[mousetweaks] Rework pointer-capture applet
- From: Gerd Kohlberger <gerdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetweaks] Rework pointer-capture applet
- Date: Sun, 27 Jun 2010 16:33:46 +0000 (UTC)
commit 0060ea003e16fd351afde99076f1bf571ea8f62c
Author: Gerd Kohlberger <gerdk src gnome org>
Date: Sun Jun 27 18:30:08 2010 +0200
Rework pointer-capture applet
data/pointer-capture-applet.schemas.in | 2 +-
data/pointer-capture-applet.ui | 31 +-
src/pointer-capture-applet.c | 682 +++++++++++++++-----------------
3 files changed, 338 insertions(+), 377 deletions(-)
---
diff --git a/data/pointer-capture-applet.schemas.in b/data/pointer-capture-applet.schemas.in
index 88d8ca6..6965522 100644
--- a/data/pointer-capture-applet.schemas.in
+++ b/data/pointer-capture-applet.schemas.in
@@ -5,7 +5,7 @@
<key>/schemas/apps/pointer-capture/size</key>
<owner>pointer-capture</owner>
<type>int</type>
- <default>100</default>
+ <default>70</default>
<locale name="C">
<short>Size of capture area</short>
<long>Width of the capture area in pixels.</long>
diff --git a/data/pointer-capture-applet.ui b/data/pointer-capture-applet.ui
index db016dd..0f25f58 100644
--- a/data/pointer-capture-applet.ui
+++ b/data/pointer-capture-applet.ui
@@ -31,10 +31,10 @@
<property name="icon_name">input-mouse</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
- <property name="copyright">Copyright 2007-2008 © Gerd Kohlberger</property>
- <property name="comments" translatable="yes">Area to freeze the mouse pointer on the panel.
+ <property name="copyright">Copyright 2007-2010 © Gerd Kohlberger</property>
+ <property name="comments" translatable="yes">Area to lock the pointer on the panel.
Part of Mousetweaks</property>
- <property name="authors">Gerd Kohlberger <lowfi chello at></property>
+ <property name="authors">Gerd Kohlberger <gerdko gmail com></property>
<property name="documenters">Francesco Fumanti <francesco fumanti gmx net></property>
<property name="translator_credits">GNOME Translation Team</property>
<property name="logo_icon_name">input-mouse</property>
@@ -61,12 +61,12 @@ Part of Mousetweaks</property>
</object>
</child>
</object>
- <object class="GtkWindow" id="capture_preferences">
+ <object class="GtkWindow" id="preferences">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">12</property>
<property name="title" translatable="yes">Pointer Capture Preferences</property>
<property name="resizable">False</property>
- <property name="icon_name">gnome-dev-mouse-optical</property>
+ <property name="icon_name">input-mouse</property>
<property name="type_hint">dialog</property>
<child>
<object class="GtkVBox" id="vbox2">
@@ -228,7 +228,7 @@ Part of Mousetweaks</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Capture Pointer</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
@@ -387,7 +387,7 @@ Part of Mousetweaks</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Release Pointer</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
@@ -413,7 +413,7 @@ Part of Mousetweaks</property>
<object class="GtkHBox" id="hbox5">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="spacing">24</property>
+ <property name="spacing">12</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
@@ -473,9 +473,9 @@ Part of Mousetweaks</property>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">Size of Capture Area</property>
+ <property name="label" translatable="yes">Size of the Capture Area</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
@@ -506,6 +506,8 @@ Part of Mousetweaks</property>
<property name="use_stock">True</property>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
@@ -514,11 +516,14 @@ Part of Mousetweaks</property>
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="has_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="use_stock">True</property>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -531,4 +536,10 @@ Part of Mousetweaks</property>
</object>
</child>
</object>
+ <object class="GtkSizeGroup" id="sizegroup">
+ <widgets>
+ <widget name="label10"/>
+ <widget name="label3"/>
+ </widgets>
+ </object>
</interface>
diff --git a/src/pointer-capture-applet.c b/src/pointer-capture-applet.c
index db0c383..061b18f 100644
--- a/src/pointer-capture-applet.c
+++ b/src/pointer-capture-applet.c
@@ -22,62 +22,149 @@
#include "mt-common.h"
-#define WID(n) (GTK_WIDGET (gtk_builder_get_object (cd->ui, n)))
+#define PC_TYPE_APPLET (pc_applet_get_type ())
+#define PC_APPLET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PC_TYPE_APPLET, PcApplet))
+#define PC_IS_APPLET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PC_TYPE_APPLET))
-#define TANGO_CHAMELEON_DARK 0.305f, 0.603f, 0.023f
-#define TANGO_SCARLETRED_DARK 0.643f, 0.000f, 0.000f
-#define TANGO_ALUMINIUM2_DARK 0.180f, 0.203f, 0.211f
+#define WID(n) (GTK_WIDGET (gtk_builder_get_object (pc->ui, (n))))
-typedef struct _CaptureData CaptureData;
-struct _CaptureData
+typedef PanelAppletClass PcAppletClass;
+typedef struct _PcApplet
{
- PanelApplet *applet;
+ PanelApplet parent;
+
GtkBuilder *ui;
GtkWidget *area;
-
+ GtkWidget *box;
+ GtkWidget *label;
+ GtkWidget *icon;
GdkCursor *blank;
- GdkCursor *root;
+
gboolean pointer_locked;
gint pointer_x;
gint pointer_y;
gint center_x;
gint center_y;
- gboolean vertical;
- /* options */
gint size;
gint cap_button;
guint cap_mask;
gint rel_button;
guint rel_mask;
-};
+} PcApplet;
-static void capture_data_free (CaptureData *cd);
+GType pc_applet_get_type (void) G_GNUC_CONST;
+
+G_DEFINE_TYPE (PcApplet, pc_applet, PANEL_TYPE_APPLET)
static void
-capture_preferences (BonoboUIComponent *component,
- gpointer data,
- const char *cname)
+pc_applet_init (PcApplet *pc)
{
- CaptureData *cd = data;
+ AtkObject *atk;
+
+ atk = gtk_widget_get_accessible (GTK_WIDGET (pc));
+ if (GTK_IS_ACCESSIBLE (atk))
+ {
+ atk_object_set_name (atk, _("Capture area"));
+ atk_object_set_description (atk, _("Temporarily lock the mouse pointer"));
+ }
- gtk_window_present (GTK_WINDOW (WID ("capture_preferences")));
+ pc->ui = NULL;
+ pc->area = NULL;
+ pc->box = NULL;
+ pc->label = NULL;
+ pc->icon = NULL;
+ pc->blank = gdk_cursor_new (GDK_BLANK_CURSOR);
+ pc->pointer_locked = FALSE;
+ pc->pointer_x = 0;
+ pc->pointer_y = 0;
+ pc->center_x = 0;
+ pc->center_y = 0;
+
+ pc->size = 70;
+ pc->cap_button = 1;
+ pc->cap_mask = 0;
+ pc->rel_button = 1;
+ pc->rel_mask = 0;
}
static void
-capture_help (BonoboUIComponent *component, gpointer data, const char *cname)
+pc_applet_change_orient (PanelApplet *applet,
+ PanelAppletOrient orient)
{
- CaptureData *cd = data;
+ PcApplet *pc = PC_APPLET (applet);
- mt_common_show_help (gtk_widget_get_screen (cd->area),
- gtk_get_current_event_time ());
+ if (pc->area || pc->label)
+ {
+ if (orient == PANEL_APPLET_ORIENT_UP ||
+ orient == PANEL_APPLET_ORIENT_DOWN)
+ {
+ gtk_widget_set_size_request (pc->area, pc->size, -1);
+ gtk_label_set_angle (GTK_LABEL (pc->label), 0);
+ }
+ else
+ {
+ gtk_widget_set_size_request (pc->area, -1, pc->size);
+ gtk_label_set_angle (GTK_LABEL (pc->label), 90);
+ }
+ }
}
static void
-capture_about (BonoboUIComponent *component, gpointer data, const char *cname)
+pc_applet_destroy (GtkObject *object)
{
- CaptureData *cd = data;
+ PcApplet *pc = PC_APPLET (object);
+ if (pc->blank)
+ {
+ gdk_cursor_unref (pc->blank);
+ pc->blank = NULL;
+ }
+
+ if (pc->ui)
+ {
+ gtk_widget_destroy (WID ("about"));
+ gtk_widget_destroy (WID ("preferences"));
+ g_object_unref (pc->ui);
+ pc->ui = NULL;
+ }
+}
+
+static void
+pc_applet_class_init (PcAppletClass *klass)
+{
+ GtkObjectClass *object_class;
+ PanelAppletClass *applet_class;
+
+ object_class = GTK_OBJECT_CLASS (klass);
+ object_class->destroy = pc_applet_destroy;
+
+ applet_class = PANEL_APPLET_CLASS (klass);
+ applet_class->change_orient = pc_applet_change_orient;
+}
+
+static void
+capture_preferences (BonoboUIComponent *component,
+ PcApplet *pc,
+ const gchar *cname)
+{
+ gtk_window_present (GTK_WINDOW (WID ("preferences")));
+}
+
+static void
+capture_help (BonoboUIComponent *component,
+ PcApplet *pc,
+ const gchar *cname)
+{
+ mt_common_show_help (gtk_widget_get_screen (pc->area),
+ gtk_get_current_event_time ());
+}
+
+static void
+capture_about (BonoboUIComponent *component,
+ PcApplet *pc,
+ const gchar *cname)
+{
gtk_window_present (GTK_WINDOW (WID ("about")));
}
@@ -90,265 +177,183 @@ static const BonoboUIVerb menu_verb[] =
};
static void
-lock_pointer (CaptureData *cd)
+lock_pointer (PcApplet *pc)
{
GdkWindow *win;
gint x, y, w, h;
/* set invisible cursor */
- win = gdk_screen_get_root_window (gtk_widget_get_screen (cd->area));
- cd->root = gdk_window_get_cursor (win);
- gdk_window_set_cursor (win, cd->blank);
+ win = gdk_screen_get_root_window (gtk_widget_get_screen (pc->area));
+ gdk_window_set_cursor (win, pc->blank);
/* calculate center position */
- win = gtk_widget_get_window (cd->area);
+ win = gtk_widget_get_window (pc->area);
gdk_drawable_get_size (win, &w, &h);
gdk_window_get_origin (win, &x, &y);
- cd->center_x = x + (w >> 1);
- cd->center_y = y + (h >> 1);
+ pc->center_x = x + (w >> 1);
+ pc->center_y = y + (h >> 1);
/* update state */
- cd->pointer_locked = TRUE;
- gtk_widget_queue_draw (cd->area);
+ pc->pointer_locked = TRUE;
+ gtk_widget_show (pc->label);
+ gtk_widget_hide (pc->icon);
}
static void
-unlock_pointer (CaptureData *cd)
+unlock_pointer (PcApplet *pc)
{
GdkWindow *root;
GdkCursor *cursor;
/* move pointer to the position where it was locked */
gdk_display_warp_pointer (gdk_display_get_default (),
- gtk_widget_get_screen (cd->area),
- cd->pointer_x,
- cd->pointer_y);
+ gtk_widget_get_screen (pc->area),
+ pc->pointer_x,
+ pc->pointer_y);
/* restore cursor */
- root = gdk_screen_get_root_window (gtk_widget_get_screen (cd->area));
- if (cd->root)
- {
- gdk_window_set_cursor (root, cd->root);
- }
- else
- {
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (root, cursor);
- gdk_cursor_unref (cursor);
- }
+ root = gdk_screen_get_root_window (gtk_widget_get_screen (pc->area));
+ cursor = gdk_cursor_new (GDK_LEFT_PTR);
+ gdk_window_set_cursor (root, cursor);
+ gdk_cursor_unref (cursor);
/* update state */
- cd->pointer_locked = FALSE;
- gtk_widget_queue_draw (cd->area);
+ pc->pointer_locked = FALSE;
+ gtk_widget_hide (pc->label);
+ gtk_widget_show (pc->icon);
}
-/* lock pointer immediately if we have no button*/
static gboolean
-area_entered (GtkWidget *widget, GdkEventCrossing *cev, gpointer data)
+pc_applet_enter_notify (GtkWidget *widget,
+ GdkEventCrossing *event,
+ PcApplet *pc)
{
- CaptureData *cd = data;
-
- if (cev->mode != GDK_CROSSING_NORMAL)
- return FALSE;
-
- if (cd->cap_button)
- return FALSE;
-
- cd->pointer_x = cev->x_root;
- cd->pointer_y = cev->y_root;
- lock_pointer (cd);
-
+ /* lock the pointer immediately if we have no button */
+ if (!pc->cap_button && event->mode == GDK_CROSSING_NORMAL)
+ {
+ pc->pointer_x = event->x_root;
+ pc->pointer_y = event->y_root;
+ lock_pointer (pc);
+ }
return FALSE;
}
static gboolean
-area_left (GtkWidget *widget, GdkEventCrossing *cev, gpointer data)
+pc_applet_leave_notify (GtkWidget *widget,
+ GdkEventCrossing *event,
+ PcApplet *pc)
{
- CaptureData *cd = data;
-
- if (cd->pointer_locked)
+ if (pc->pointer_locked)
{
/* move pointer back to center */
gdk_display_warp_pointer (gdk_display_get_default (),
gtk_widget_get_screen (widget),
- cd->center_x,
- cd->center_y);
+ pc->center_x,
+ pc->center_y);
}
return FALSE;
}
/* change lock states */
static gboolean
-area_button_press (GtkWidget *widget, GdkEventButton *bev, gpointer data)
+pc_applet_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ PcApplet *pc)
{
- CaptureData *cd = data;
-
- if (bev->button == cd->cap_button &&
- (bev->state & cd->cap_mask) == cd->cap_mask &&
- !cd->pointer_locked)
- {
- cd->pointer_x = bev->x_root;
- cd->pointer_y = bev->y_root;
- lock_pointer (cd);
- }
- else if (bev->button == cd->rel_button &&
- (bev->state & cd->rel_mask) == cd->rel_mask &&
- cd->pointer_locked)
+ if (event->button == pc->cap_button &&
+ (event->state & pc->cap_mask) == pc->cap_mask &&
+ !pc->pointer_locked)
{
- unlock_pointer (cd);
+ pc->pointer_x = event->x_root;
+ pc->pointer_y = event->y_root;
+ lock_pointer (pc);
+ return TRUE;
}
- else if (!cd->pointer_locked && bev->button != 1)
+ else if (event->button == pc->rel_button &&
+ (event->state & pc->rel_mask) == pc->rel_mask &&
+ pc->pointer_locked)
{
- g_signal_stop_emission_by_name (widget, "button_press_event");
- return FALSE;
+ unlock_pointer (pc);
+ return TRUE;
}
- return TRUE;
+ return FALSE;
}
-static void
-render_text (cairo_t *cr, CaptureData *cd)
+static gboolean
+pc_applet_visibility_notify (GtkWidget *widget,
+ GdkEventVisibility *event,
+ PcApplet *pc)
{
- PangoLayout *layout;
- PangoFontDescription *desc;
- PangoRectangle rect;
- guint size;
-
- layout = pango_cairo_create_layout (cr);
-
- if (cd->size >= 60)
- pango_layout_set_text (layout, _("Locked"), -1);
- else
- /* l10n: the first letter of 'Locked' */
- pango_layout_set_text (layout, _("L"), -1);
-
- desc = pango_font_description_new ();
- pango_font_description_set_family (desc, "Bitstream Vera Sans");
-
- if (cd->vertical)
- pango_font_description_set_gravity (desc, PANGO_GRAVITY_EAST);
-
- size = panel_applet_get_size (cd->applet) / 3;
- pango_font_description_set_size (desc, size * PANGO_SCALE);
-
- pango_layout_set_font_description (layout, desc);
- pango_layout_get_pixel_extents (layout, &rect, NULL);
-
- /* check font size */
- while ((rect.width - 8) > cd->size)
+ if (event->state != GDK_VISIBILITY_UNOBSCURED && pc->pointer_locked)
{
- pango_font_description_set_size (desc, (--size) * PANGO_SCALE);
- pango_layout_set_font_description (layout, desc);
- pango_layout_get_pixel_extents (layout, &rect, NULL);
+ unlock_pointer (pc);
}
-
- if (cd->vertical)
- cairo_rotate (cr, -pango_gravity_to_rotation (PANGO_GRAVITY_EAST));
-
- cairo_rel_move_to (cr,
- -rect.x - rect.width / 2,
- -rect.y - rect.height / 2);
- pango_cairo_layout_path (cr, layout);
-
- pango_font_description_free (desc);
- g_object_unref (layout);
+ return FALSE;
}
-/* draw background */
static gboolean
-area_exposed (GtkWidget *widget, GdkEventExpose *eev, gpointer data)
-{
- CaptureData *cd = data;
- GtkAllocation allocation;
- cairo_t *cr;
- gdouble w, h;
-
- gtk_widget_get_allocation (widget, &allocation);
- w = allocation.width;
- h = allocation.height;
-
- cr = gdk_cairo_create (gtk_widget_get_window (widget));
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_rectangle (cr, 0.0, 0.0, w, h);
-
- if (cd->pointer_locked)
- cairo_set_source_rgb (cr, TANGO_SCARLETRED_DARK);
- else
- cairo_set_source_rgb (cr, TANGO_CHAMELEON_DARK);
-
- cairo_paint (cr);
- cairo_set_source_rgb (cr, TANGO_ALUMINIUM2_DARK);
- cairo_stroke (cr);
-
- if (cd->pointer_locked)
- {
- cairo_move_to (cr, w / 2, h / 2);
- render_text (cr, cd);
- cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
- cairo_fill (cr);
- }
- cairo_destroy (cr);
-
- return TRUE;
+area_exposed (GtkWidget *widget,
+ GdkEventExpose *event,
+ PcApplet *pc)
+{
+ GtkAllocation alloc;
+
+ gtk_widget_get_allocation (widget, &alloc);
+
+ if (pc->pointer_locked)
+ gtk_paint_flat_box (gtk_widget_get_style (widget),
+ gtk_widget_get_window (widget),
+ GTK_STATE_SELECTED,
+ GTK_SHADOW_NONE,
+ &event->area, widget, NULL,
+ alloc.x, alloc.y, alloc.width, alloc.height);
+
+ gtk_paint_shadow (gtk_widget_get_style (widget),
+ gtk_widget_get_window (widget),
+ GTK_STATE_NORMAL,
+ GTK_SHADOW_ETCHED_IN,
+ &event->area, widget, NULL,
+ alloc.x, alloc.y, alloc.width, alloc.height);
+ return FALSE;
}
static void
-update_orientation (CaptureData *cd, PanelAppletOrient orient)
+icon_theme_changed (GtkIconTheme *theme, PcApplet *pc)
{
- switch (orient)
- {
- case PANEL_APPLET_ORIENT_UP:
- case PANEL_APPLET_ORIENT_DOWN:
- gtk_widget_set_size_request (cd->area, cd->size, 0);
- cd->vertical = FALSE;
- break;
- case PANEL_APPLET_ORIENT_LEFT:
- case PANEL_APPLET_ORIENT_RIGHT:
- gtk_widget_set_size_request (cd->area, 0, cd->size);
- cd->vertical = TRUE;
- default:
- break;
- }
-}
+ gboolean visible;
-/* applet callback */
-static void
-applet_unrealize (GtkWidget *widget, gpointer data)
-{
- capture_data_free (data);
-}
+ visible = gtk_widget_get_visible (pc->icon);
+ gtk_container_remove (GTK_CONTAINER (pc->box), pc->icon);
+ pc->icon = gtk_image_new_from_icon_name ("input-mouse", GTK_ICON_SIZE_BUTTON);
+ gtk_container_add (GTK_CONTAINER (pc->box), pc->icon);
-static void
-applet_orient_changed (PanelApplet *applet, guint orient, gpointer data)
-{
- update_orientation (data, orient);
+ if (visible)
+ gtk_widget_show (pc->icon);
}
+/* about dialog callbacks */
static void
-about_response (GtkButton *button, gint response, gpointer data)
+about_response (GtkButton *button, gint response, PcApplet *pc)
{
- CaptureData *cd = data;
-
gtk_widget_hide (WID ("about"));
}
/* preferences dialog callbacks */
static void
-prefs_size_changed (GtkSpinButton *spin, gpointer data)
+prefs_size_changed (GtkSpinButton *spin, PcApplet *pc)
{
- CaptureData *cd = data;
+ PanelApplet *applet = PANEL_APPLET (pc);
- cd->size = gtk_spin_button_get_value_as_int (spin);
- panel_applet_gconf_set_int (cd->applet, "size", cd->size, NULL);
+ pc->size = gtk_spin_button_get_value_as_int (spin);
+ panel_applet_gconf_set_int (applet, "size", pc->size, NULL);
- update_orientation (cd, panel_applet_get_orient (cd->applet));
+ pc_applet_change_orient (applet, panel_applet_get_orient (applet));
}
static void
-prefs_closed (GtkButton *button, gpointer data)
+prefs_closed (GtkButton *button, PcApplet *pc)
{
- CaptureData *cd = data;
-
- gtk_widget_hide (WID ("capture_preferences"));
+ gtk_widget_hide (WID ("preferences"));
}
static void
@@ -359,109 +364,93 @@ prefs_help (GtkButton *button, gpointer data)
}
static void
-prefs_cap_button (GtkSpinButton *spin, gpointer data)
+prefs_cap_button (GtkSpinButton *spin, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->cap_button = gtk_spin_button_get_value_as_int (spin);
- panel_applet_gconf_set_int (cd->applet,
+ pc->cap_button = gtk_spin_button_get_value_as_int (spin);
+ panel_applet_gconf_set_int (PANEL_APPLET (pc),
"capture_button",
- cd->cap_button,
+ pc->cap_button,
NULL);
}
static void
-prefs_cap_alt (GtkToggleButton *toggle, gpointer data)
+prefs_cap_alt (GtkToggleButton *toggle, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->cap_mask ^= GDK_MOD1_MASK;
- panel_applet_gconf_set_bool (cd->applet,
+ pc->cap_mask ^= GDK_MOD1_MASK;
+ panel_applet_gconf_set_bool (PANEL_APPLET (pc),
"capture_mod_alt",
gtk_toggle_button_get_active (toggle),
NULL);
}
static void
-prefs_cap_shift (GtkToggleButton *toggle, gpointer data)
+prefs_cap_shift (GtkToggleButton *toggle, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->cap_mask ^= GDK_SHIFT_MASK;
- panel_applet_gconf_set_bool (cd->applet,
+ pc->cap_mask ^= GDK_SHIFT_MASK;
+ panel_applet_gconf_set_bool (PANEL_APPLET (pc),
"capture_mod_shift",
gtk_toggle_button_get_active (toggle),
NULL);
}
static void
-prefs_cap_ctrl (GtkToggleButton *toggle, gpointer data)
+prefs_cap_ctrl (GtkToggleButton *toggle, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->cap_mask ^= GDK_CONTROL_MASK;
- panel_applet_gconf_set_bool (cd->applet,
+ pc->cap_mask ^= GDK_CONTROL_MASK;
+ panel_applet_gconf_set_bool (PANEL_APPLET (pc),
"capture_mod_ctrl",
gtk_toggle_button_get_active (toggle),
NULL);
}
static void
-prefs_rel_button (GtkSpinButton *spin, gpointer data)
+prefs_rel_button (GtkSpinButton *spin, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->rel_button = gtk_spin_button_get_value_as_int (spin);
- panel_applet_gconf_set_int (cd->applet,
+ pc->rel_button = gtk_spin_button_get_value_as_int (spin);
+ panel_applet_gconf_set_int (PANEL_APPLET (pc),
"release_button",
- cd->rel_button,
+ pc->rel_button,
NULL);
}
static void
-prefs_rel_alt (GtkToggleButton *toggle, gpointer data)
+prefs_rel_alt (GtkToggleButton *toggle, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->rel_mask ^= GDK_MOD1_MASK;
- panel_applet_gconf_set_bool (cd->applet,
+ pc->rel_mask ^= GDK_MOD1_MASK;
+ panel_applet_gconf_set_bool (PANEL_APPLET (pc),
"release_mod_alt",
gtk_toggle_button_get_active (toggle),
NULL);
}
static void
-prefs_rel_shift (GtkToggleButton *toggle, gpointer data)
+prefs_rel_shift (GtkToggleButton *toggle, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->rel_mask ^= GDK_SHIFT_MASK;
- panel_applet_gconf_set_bool (cd->applet,
+ pc->rel_mask ^= GDK_SHIFT_MASK;
+ panel_applet_gconf_set_bool (PANEL_APPLET (pc),
"release_mod_shift",
gtk_toggle_button_get_active (toggle),
NULL);
}
static void
-prefs_rel_ctrl (GtkToggleButton *toggle, gpointer data)
+prefs_rel_ctrl (GtkToggleButton *toggle, PcApplet *pc)
{
- CaptureData *cd = data;
-
- cd->rel_mask ^= GDK_CONTROL_MASK;
- panel_applet_gconf_set_bool (cd->applet,
+ pc->rel_mask ^= GDK_CONTROL_MASK;
+ panel_applet_gconf_set_bool (PANEL_APPLET (pc),
"release_mod_ctrl",
gtk_toggle_button_get_active (toggle),
NULL);
}
static gboolean
-init_preferences (CaptureData *cd)
+init_preferences (PcApplet *pc)
{
GtkWidget *w;
GError *error = NULL;
- cd->ui = gtk_builder_new ();
- gtk_builder_add_from_file (cd->ui,
+ pc->ui = gtk_builder_new ();
+ gtk_builder_add_from_file (pc->ui,
DATADIR "/pointer-capture-applet.ui",
&error);
if (error)
@@ -471,101 +460,68 @@ init_preferences (CaptureData *cd)
return FALSE;
}
- g_signal_connect (WID ("capture_preferences"), "delete-event",
+ g_signal_connect (WID ("preferences"), "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
g_signal_connect (WID ("close"), "clicked",
- G_CALLBACK (prefs_closed), cd);
+ G_CALLBACK (prefs_closed), pc);
g_signal_connect (WID ("help"), "clicked",
G_CALLBACK (prefs_help), NULL);
+ /* size */
w = WID ("size");
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), cd->size);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), pc->size);
g_signal_connect (w, "value_changed",
- G_CALLBACK (prefs_size_changed), cd);
+ G_CALLBACK (prefs_size_changed), pc);
- /* capture modifier signals */
+ /* capture modifier */
w = WID ("cap_button");
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), cd->cap_button);
- g_signal_connect (w, "value_changed",
- G_CALLBACK (prefs_cap_button), cd);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), pc->cap_button);
+ g_signal_connect (w, "value_changed", G_CALLBACK (prefs_cap_button), pc);
w = WID ("cap_alt");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
- (cd->cap_mask & GDK_MOD1_MASK));
- g_signal_connect (w, "toggled",
- G_CALLBACK (prefs_cap_alt), cd);
+ pc->cap_mask & GDK_MOD1_MASK);
+ g_signal_connect (w, "toggled", G_CALLBACK (prefs_cap_alt), pc);
w = WID ("cap_shift");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
- (cd->cap_mask & GDK_SHIFT_MASK));
- g_signal_connect (w, "toggled",
- G_CALLBACK (prefs_cap_shift), cd);
+ pc->cap_mask & GDK_SHIFT_MASK);
+ g_signal_connect (w, "toggled", G_CALLBACK (prefs_cap_shift), pc);
w = WID ("cap_ctrl");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
- (cd->cap_mask & GDK_CONTROL_MASK));
- g_signal_connect (w, "toggled",
- G_CALLBACK (prefs_cap_ctrl), cd);
+ pc->cap_mask & GDK_CONTROL_MASK);
+ g_signal_connect (w, "toggled", G_CALLBACK (prefs_cap_ctrl), pc);
- /* release modifier signals */
+ /* release modifier */
w = WID ("rel_button");
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), cd->rel_button);
- g_signal_connect (w, "value_changed",
- G_CALLBACK (prefs_rel_button), cd);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), pc->rel_button);
+ g_signal_connect (w, "value_changed", G_CALLBACK (prefs_rel_button), pc);
w = WID ("rel_alt");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
- (cd->rel_mask & GDK_MOD1_MASK));
- g_signal_connect (w, "toggled",
- G_CALLBACK (prefs_rel_alt), cd);
+ pc->rel_mask & GDK_MOD1_MASK);
+ g_signal_connect (w, "toggled", G_CALLBACK (prefs_rel_alt), pc);
w = WID ("rel_shift");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
- (cd->rel_mask & GDK_SHIFT_MASK));
- g_signal_connect (w, "toggled",
- G_CALLBACK (prefs_rel_shift), cd);
+ pc->rel_mask & GDK_SHIFT_MASK);
+ g_signal_connect (w, "toggled", G_CALLBACK (prefs_rel_shift), pc);
w = WID ("rel_ctrl");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),
- (cd->rel_mask & GDK_CONTROL_MASK));
- g_signal_connect (w, "toggled",
- G_CALLBACK (prefs_rel_ctrl), cd);
+ pc->rel_mask & GDK_CONTROL_MASK);
+ g_signal_connect (w, "toggled", G_CALLBACK (prefs_rel_ctrl), pc);
return TRUE;
}
-static CaptureData *
-capture_data_init (PanelApplet *applet)
-{
- CaptureData *cd;
-
- cd = g_slice_new0 (CaptureData);
- cd->applet = applet;
- cd->size = 100;
- cd->rel_button = 1;
- cd->blank = gdk_cursor_new (GDK_BLANK_CURSOR);
-
- return cd;
-}
-
-static void
-capture_data_free (CaptureData *cd)
-{
- if (cd->blank)
- gdk_cursor_unref (cd->blank);
-
- if (cd->ui)
- g_object_unref (cd->ui);
-
- g_slice_free (CaptureData, cd);
-}
-
static gboolean
fill_applet (PanelApplet *applet)
{
- CaptureData *cd;
+ PcApplet *pc = PC_APPLET (applet);
+ GtkIconTheme *theme;
GtkWidget *about;
- AtkObject *obj;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -574,84 +530,78 @@ fill_applet (PanelApplet *applet)
g_set_application_name (_("Pointer Capture"));
gtk_window_set_default_icon_name (MT_ICON_NAME);
- cd = capture_data_init (applet);
-
/* gconf settings */
- panel_applet_add_preferences (applet,
- "/schemas/apps/pointer-capture",
- NULL);
-
- cd->size = panel_applet_gconf_get_int (applet, "size", NULL);
- cd->cap_button = panel_applet_gconf_get_int (applet,
- "capture_button", NULL);
- cd->rel_button = panel_applet_gconf_get_int (applet,
- "release_button", NULL);
+ panel_applet_add_preferences (applet, "/schemas/apps/pointer-capture", NULL);
+
+ pc->size = panel_applet_gconf_get_int (applet, "size", NULL);
+ pc->cap_button = panel_applet_gconf_get_int (applet, "capture_button", NULL);
+ pc->rel_button = panel_applet_gconf_get_int (applet, "release_button", NULL);
+
if (panel_applet_gconf_get_bool (applet, "capture_mod_shift", NULL))
- cd->cap_mask |= GDK_SHIFT_MASK;
+ pc->cap_mask |= GDK_SHIFT_MASK;
if (panel_applet_gconf_get_bool (applet, "capture_mod_ctrl", NULL))
- cd->cap_mask |= GDK_CONTROL_MASK;
+ pc->cap_mask |= GDK_CONTROL_MASK;
if (panel_applet_gconf_get_bool (applet, "capture_mod_alt", NULL))
- cd->cap_mask |= GDK_MOD1_MASK;
+ pc->cap_mask |= GDK_MOD1_MASK;
if (panel_applet_gconf_get_bool (applet, "release_mod_shift", NULL))
- cd->rel_mask |= GDK_SHIFT_MASK;
+ pc->rel_mask |= GDK_SHIFT_MASK;
if (panel_applet_gconf_get_bool (applet, "release_mod_ctrl", NULL))
- cd->rel_mask |= GDK_CONTROL_MASK;
+ pc->rel_mask |= GDK_CONTROL_MASK;
if (panel_applet_gconf_get_bool (applet, "release_mod_alt", NULL))
- cd->rel_mask |= GDK_MOD1_MASK;
+ pc->rel_mask |= GDK_MOD1_MASK;
/* preferences dialog */
- if (!init_preferences (cd)) {
- capture_data_free (cd);
+ if (!init_preferences (pc))
return FALSE;
- }
-
- /* capture area */
- cd->area = gtk_drawing_area_new ();
- gtk_widget_add_events (cd->area,
- GDK_ENTER_NOTIFY_MASK |
- GDK_LEAVE_NOTIFY_MASK |
- GDK_BUTTON_PRESS_MASK);
-
- g_signal_connect (cd->area, "enter-notify-event",
- G_CALLBACK (area_entered), cd);
- g_signal_connect (cd->area, "leave-notify-event",
- G_CALLBACK (area_left), cd);
- g_signal_connect (cd->area, "expose-event",
- G_CALLBACK (area_exposed), cd);
- g_signal_connect (cd->area, "button-press-event",
- G_CALLBACK (area_button_press), cd);
-
- update_orientation (cd, panel_applet_get_orient (applet));
- gtk_widget_show (cd->area);
/* about dialog */
about = WID ("about");
g_object_set (about, "version", VERSION, NULL);
-
+ g_signal_connect (about, "response", G_CALLBACK (about_response), pc);
g_signal_connect (about, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
- g_signal_connect (about, "response",
- G_CALLBACK (about_response), cd);
- /* applet initialisation */
- panel_applet_set_flags (applet,
- PANEL_APPLET_EXPAND_MINOR |
- PANEL_APPLET_HAS_HANDLE);
+ /* applet setup */
panel_applet_set_background_widget (applet, GTK_WIDGET (applet));
- panel_applet_setup_menu_from_file (applet,
- DATADIR, "PointerCapture.xml",
- NULL, menu_verb, cd);
+ panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR |
+ PANEL_APPLET_HAS_HANDLE);
+ panel_applet_setup_menu_from_file (applet, DATADIR, "PointerCapture.xml",
+ NULL, menu_verb, pc);
+
+ g_signal_connect (pc, "enter-notify-event",
+ G_CALLBACK (pc_applet_enter_notify), pc);
+ g_signal_connect (pc, "leave-notify-event",
+ G_CALLBACK (pc_applet_leave_notify), pc);
+ g_signal_connect (pc, "button-press-event",
+ G_CALLBACK (pc_applet_button_press), pc);
+ g_signal_connect (pc, "visibility_notify_event",
+ G_CALLBACK (pc_applet_visibility_notify), pc);
+
+ /* icon theme */
+ theme = gtk_icon_theme_get_default ();
+ g_signal_connect (theme, "changed", G_CALLBACK (icon_theme_changed), pc);
+
+ /* capture area */
+ pc->area = gtk_event_box_new ();
+ gtk_event_box_set_visible_window (GTK_EVENT_BOX (pc->area), FALSE);
+ gtk_container_add (GTK_CONTAINER (applet), pc->area);
+ gtk_widget_show (pc->area);
+
+ g_signal_connect (pc->area, "expose-event", G_CALLBACK (area_exposed), pc);
+
+ pc->box = gtk_hbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (pc->area), pc->box);
+ gtk_widget_show (pc->box);
- g_signal_connect (applet, "change-orient",
- G_CALLBACK (applet_orient_changed), cd);
- g_signal_connect (applet, "unrealize",
- G_CALLBACK (applet_unrealize), cd);
+ pc->label = gtk_label_new (_("Locked"));
+ gtk_widget_set_state (pc->label, GTK_STATE_SELECTED);
+ gtk_container_add (GTK_CONTAINER (pc->box), pc->label);
- obj = gtk_widget_get_accessible (GTK_WIDGET (applet));
- atk_object_set_name (obj, _("Capture area"));
- atk_object_set_description (obj, _("Temporarily lock the mouse pointer"));
+ pc->icon = gtk_image_new_from_icon_name ("input-mouse", GTK_ICON_SIZE_BUTTON);
+ gtk_container_add (GTK_CONTAINER (pc->box), pc->icon);
+ gtk_widget_show (pc->icon);
- gtk_container_add (GTK_CONTAINER (applet), cd->area);
+ pc_applet_change_orient (applet, panel_applet_get_orient (applet));
gtk_widget_show (GTK_WIDGET (applet));
return TRUE;
@@ -667,7 +617,7 @@ applet_factory (PanelApplet *applet, const gchar *iid, gpointer data)
}
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:PointerCaptureApplet_Factory",
- PANEL_TYPE_APPLET,
+ PC_TYPE_APPLET,
"Pointer Capture Factory",
VERSION,
applet_factory,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]