diff options
Diffstat (limited to 'src/renderers')
-rw-r--r-- | src/renderers/pieRenderer.vala | 74 | ||||
-rw-r--r-- | src/renderers/pieWindow.vala | 69 | ||||
-rw-r--r-- | src/renderers/sliceRenderer.vala | 23 |
3 files changed, 97 insertions, 69 deletions
diff --git a/src/renderers/pieRenderer.vala b/src/renderers/pieRenderer.vala index ffaf776..67a6b56 100644 --- a/src/renderers/pieRenderer.vala +++ b/src/renderers/pieRenderer.vala @@ -31,7 +31,7 @@ public class PieRenderer : GLib.Object { /// gets executed when the user clicks on the middle of the pie) ///////////////////////////////////////////////////////////////////// - public int quick_action { get; private set; } + public int quickaction { get; private set; } ///////////////////////////////////////////////////////////////////// /// The index of the currently active slice. @@ -83,13 +83,13 @@ public class PieRenderer : GLib.Object { public PieRenderer() { this.slices = new Gee.ArrayList<SliceRenderer?>(); this.center = new CenterRenderer(this); - this.quick_action = -1; + this.quickaction = -1; this.active_slice = -2; this.size = 0; } ///////////////////////////////////////////////////////////////////// - /// Loads an Pie. All members are initialized accordingly. + /// Loads a Pie. All members are initialized accordingly. ///////////////////////////////////////////////////////////////////// public void load_pie(Pie pie) { @@ -102,8 +102,8 @@ public class PieRenderer : GLib.Object { this.slices.add(renderer); renderer.load(action, slices.size-1); - if (action.is_quick_action) { - this.quick_action = count; + if (action.is_quickaction) { + this.quickaction = count; } ++count; @@ -112,7 +112,7 @@ public class PieRenderer : GLib.Object { this.turbo_mode = PieManager.get_is_turbo(pie.id); - this.set_highlighted_slice(this.quick_action); + this.set_highlighted_slice(this.quickaction); this.size = (int)fmax(2*Config.global.theme.radius + 2*Config.global.theme.slice_radius*Config.global.theme.max_zoom, 2*Config.global.theme.center_radius); @@ -227,39 +227,41 @@ public class PieRenderer : GLib.Object { ///////////////////////////////////////////////////////////////////// public void draw(double frame_time, Cairo.Context ctx, int mouse_x, int mouse_y) { - double distance = sqrt(mouse_x*mouse_x + mouse_y*mouse_y); - double angle = 0.0; + if (this.size > 0) { + double distance = sqrt(mouse_x*mouse_x + mouse_y*mouse_y); + double angle = 0.0; - if (this.key_board_control) { - angle = 2.0*PI*this.active_slice/(double)slice_count(); - } else { - - if (distance > 0) { - angle = acos(mouse_x/distance); - if (mouse_y < 0) - angle = 2*PI - angle; - } + if (this.key_board_control) { + angle = 2.0*PI*this.active_slice/(double)slice_count(); + } else { - int next_active_slice = this.active_slice; + if (distance > 0) { + angle = acos(mouse_x/distance); + if (mouse_y < 0) + angle = 2*PI - angle; + } + + int next_active_slice = this.active_slice; + + if (distance < Config.global.theme.active_radius + && this.quickaction >= 0 && this.quickaction < this.slices.size) { + + next_active_slice = this.quickaction; + angle = 2.0*PI*quickaction/(double)slice_count(); + } else if (distance > Config.global.theme.active_radius && this.slice_count() > 0) { + next_active_slice = (int)(angle*slices.size/(2*PI) + 0.5) % this.slice_count(); + } else { + next_active_slice = -1; + } - if (distance < Config.global.theme.active_radius - && this.quick_action >= 0 && this.quick_action < this.slices.size) { - - next_active_slice = this.quick_action; - angle = 2.0*PI*quick_action/(double)slice_count(); - } else if (distance > Config.global.theme.active_radius && this.slice_count() > 0) { - next_active_slice = (int)(angle*slices.size/(2*PI) + 0.5) % this.slice_count(); - } else { - next_active_slice = -1; + this.set_highlighted_slice(next_active_slice); } - - this.set_highlighted_slice(next_active_slice); - } - center.draw(frame_time, ctx, angle, distance); - - foreach (var slice in this.slices) - slice.draw(frame_time, ctx, angle, distance); + center.draw(frame_time, ctx, angle, distance); + + foreach (var slice in this.slices) + slice.draw(frame_time, ctx, angle, distance); + } } ///////////////////////////////////////////////////////////////////// @@ -278,8 +280,8 @@ public class PieRenderer : GLib.Object { if (index != this.active_slice) { if (index >= 0 && index < this.slice_count()) this.active_slice = index; - else if (this.quick_action >= 0) - this.active_slice = this.quick_action; + else if (this.quickaction >= 0) + this.active_slice = this.quickaction; else this.active_slice = -1; diff --git a/src/renderers/pieWindow.vala b/src/renderers/pieWindow.vala index 59117df..0a26110 100644 --- a/src/renderers/pieWindow.vala +++ b/src/renderers/pieWindow.vala @@ -32,6 +32,19 @@ public class PieWindow : Gtk.Window { public signal void on_closing(); ///////////////////////////////////////////////////////////////////// + /// Signal which gets emitted when the PieWindow is closed. + ///////////////////////////////////////////////////////////////////// + + public signal void on_closed(); + + ///////////////////////////////////////////////////////////////////// + /// The background image used for fake transparency if + /// has_compositing is false. + ///////////////////////////////////////////////////////////////////// + + public Image background { get; private set; default=null; } + + ///////////////////////////////////////////////////////////////////// /// The owned renderer. ///////////////////////////////////////////////////////////////////// @@ -56,13 +69,6 @@ public class PieWindow : Gtk.Window { private bool has_compositing = false; ///////////////////////////////////////////////////////////////////// - /// The background image used for fake transparency if - /// has_compositing is false. - ///////////////////////////////////////////////////////////////////// - - private Image background = null; - - ///////////////////////////////////////////////////////////////////// /// C'tor, sets up the window. ///////////////////////////////////////////////////////////////////// @@ -73,7 +79,7 @@ public class PieWindow : Gtk.Window { this.set_skip_taskbar_hint(true); this.set_skip_pager_hint(true); this.set_keep_above(true); - this.set_type_hint(Gdk.WindowTypeHint.SPLASHSCREEN); + this.set_type_hint(Gdk.WindowTypeHint.UTILITY); this.set_decorated(false); this.set_resizable(false); this.icon_name = "gnome-pie"; @@ -81,7 +87,11 @@ public class PieWindow : Gtk.Window { // check for compositing if (this.screen.is_composited()) { - this.set_colormap(this.screen.get_rgba_colormap()); + #if HAVE_GTK_3 + this.set_visual(this.screen.get_rgba_visual()); + #else + this.set_colormap(this.screen.get_rgba_colormap()); + #endif this.has_compositing = true; } @@ -128,9 +138,18 @@ public class PieWindow : Gtk.Window { this.renderer.on_mouse_move(); return true; }); + + this.show.connect_after(() => { + Gtk.grab_add(this); + FocusGrabber.grab(this.get_window(), true, true, false); + }); // draw the pie on expose - this.expose_event.connect(this.draw); + #if HAVE_GTK_3 + this.draw.connect(this.draw_window); + #else + this.expose_event.connect(this.draw_window); + #endif } ///////////////////////////////////////////////////////////////////// @@ -139,7 +158,7 @@ public class PieWindow : Gtk.Window { public void load_pie(Pie pie) { this.renderer.load_pie(pie); - this.set_window_position(); + this.set_window_position(pie); this.set_size_request(renderer.size, renderer.size); } @@ -160,7 +179,6 @@ public class PieWindow : Gtk.Window { // capture the input focus this.show(); - FocusGrabber.grab(this); // start the timer this.timer = new GLib.Timer(); @@ -178,10 +196,13 @@ public class PieWindow : Gtk.Window { /// Draw the Pie. ///////////////////////////////////////////////////////////////////// - private bool draw(Gtk.Widget da, Gdk.EventExpose event) { - // clear the window - var ctx = Gdk.cairo_create(this.window); - + #if HAVE_GTK_3 + private bool draw_window(Cairo.Context ctx) { + #else + private bool draw_window(Gtk.Widget da, Gdk.EventExpose event) { + // clear the window + var ctx = Gdk.cairo_create(this.get_window()); + #endif // paint the background image if there is no compositing if (this.has_compositing) { ctx.set_operator (Cairo.Operator.CLEAR); @@ -219,12 +240,13 @@ public class PieWindow : Gtk.Window { if (!this.closing) { this.closing = true; this.on_closing(); - FocusGrabber.ungrab(this); + Gtk.grab_remove(this); + FocusGrabber.ungrab(); this.renderer.activate(); Timeout.add((uint)(Config.global.theme.fade_out_time*1000), () => { + this.on_closed(); this.destroy(); - ThemedIcon.clear_cache(); return false; }); } @@ -238,12 +260,13 @@ public class PieWindow : Gtk.Window { if (!this.closing) { this.closing = true; this.on_closing(); - FocusGrabber.ungrab(this); + Gtk.grab_remove(this); + FocusGrabber.ungrab(); this.renderer.cancel(); Timeout.add((uint)(Config.global.theme.fade_out_time*1000), () => { + this.on_closed(); this.destroy(); - ThemedIcon.clear_cache(); return false; }); } @@ -254,9 +277,9 @@ public class PieWindow : Gtk.Window { /// the mouse. ///////////////////////////////////////////////////////////////////// - private void set_window_position() { - if(Config.global.open_at_mouse) this.set_position(Gtk.WindowPosition.MOUSE); - else this.set_position(Gtk.WindowPosition.CENTER); + private void set_window_position(Pie pie) { + if(PieManager.get_is_centered(pie.id)) this.set_position(Gtk.WindowPosition.CENTER); + else this.set_position(Gtk.WindowPosition.MOUSE); } ///////////////////////////////////////////////////////////////////// diff --git a/src/renderers/sliceRenderer.vala b/src/renderers/sliceRenderer.vala index 61c50b1..4803070 100644 --- a/src/renderers/sliceRenderer.vala +++ b/src/renderers/sliceRenderer.vala @@ -20,7 +20,7 @@ using GLib.Math; namespace GnomePie { ///////////////////////////////////////////////////////////////////////// -/// Renders a Slice of a Pie. According to the current theme. +/// Renders a Slice of a Pie. According to the current theme. ///////////////////////////////////////////////////////////////////////// public class SliceRenderer : GLib.Object { @@ -123,7 +123,9 @@ public class SliceRenderer : GLib.Object { this.caption = new RenderedText(action.name, Config.global.theme.caption_width, Config.global.theme.caption_height, - Config.global.theme.caption_font); + Config.global.theme.caption_font, + Config.global.theme.caption_color, + Config.global.global_scale); this.active_icon = new ThemedIcon(action.icon, true); this.inactive_icon = new ThemedIcon(action.icon, false); @@ -138,7 +140,8 @@ public class SliceRenderer : GLib.Object { } this.hotkey = new RenderedText(hotkey_label, (int)Config.global.theme.slice_radius*2, - (int)Config.global.theme.slice_radius*2, "sans 20"); + (int)Config.global.theme.slice_radius*2, "sans 20", + Config.global.theme.caption_color, Config.global.global_scale); } ///////////////////////////////////////////////////////////////////// @@ -185,6 +188,13 @@ public class SliceRenderer : GLib.Object { ///////////////////////////////////////////////////////////////////// public void draw(double frame_time, Cairo.Context ctx, double angle, double distance) { + + // update the AnimatedValues + this.scale.update(frame_time); + this.alpha.update(frame_time); + this.fade.update(frame_time); + this.fade_scale.update(frame_time); + this.fade_rotation.update(frame_time); double direction = 2.0 * PI * position/parent.slice_count() + this.fade_rotation.val; double max_scale = 1.0/Config.global.theme.max_zoom; @@ -205,13 +215,6 @@ public class SliceRenderer : GLib.Object { if (fabs(this.scale.end - max_scale) > Config.global.theme.max_zoom*0.005) this.scale.reset_target(max_scale, Config.global.theme.transition_time); - // update the AnimatedValues - this.scale.update(frame_time); - this.alpha.update(frame_time); - this.fade.update(frame_time); - this.fade_scale.update(frame_time); - this.fade_rotation.update(frame_time); - ctx.save(); // distance from the center |