[gromit: 10/13] * gromit.c: - Make activation on startup possible (gromit -a) - add configure option for the key to
- From: Simon Budig <simon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gromit: 10/13] * gromit.c: - Make activation on startup possible (gromit -a) - add configure option for the key to
- Date: Tue, 16 Mar 2010 22:24:18 +0000 (UTC)
commit 56040378e87b15dd8dffe41ced7a427aaf2d4ede
Author: Simon Budig <simon budig de>
Date: Mon Dec 13 12:08:00 2004 +0100
* gromit.c: - Make activation on startup possible (gromit -a)
- add configure option for the key to grab (gromit -k "Pause")
* README: Adjusted.
Import of gromit history
ChangeLog | 7 ++
Makefile | 6 ++
README | 4 +
gromit.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++---------------
4 files changed, 208 insertions(+), 63 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d26f26b..fcc8721 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-12-13 Simon Budig <simon gimp org>
+
+ * gromit.c: - Make activation on startup possible (gromit -a)
+ - add configure option for the key to grab (gromit -k "Pause")
+
+ * README: Adjusted.
+
2004-10-14 Simon Budig <simon gimp org>
* gromit.c: - Fix pressure sensitivity
diff --git a/Makefile b/Makefile
index 16b0bbb..05cf11d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,10 @@
all: gromit
+proptest: proptest.c
+ gcc -o proptest proptest.c `gtk-config --libs --cflags`
+
+propertywatch: propertywatch.c
+ gcc -o propertywatch propertywatch.c `gtk-config --libs --cflags`
+
gromit: gromit.c Makefile
gcc -DG_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DPANGO_DISABLE_DEPRECATED -DGDK_MULTIHEAD_SAFE -DGTK_MULTIHEAD_SAFE -o gromit gromit.c -Wall `pkg-config --libs --cflags gtk+-2.0`
diff --git a/README b/README
index 248cc66..d40af19 100644
--- a/README
+++ b/README
@@ -26,6 +26,10 @@ The available commands are:
CTRL-Pause: toggle visibility
ALT-Pause: Quit Gromit.
+You can specify the key to grab via "gromit --key <keysym>". Specifying
+an empty string or "none" for the keysym will prevent gromit from grabbing
+a key.
+
Alternatively you can invoke Gromit with various arguments to control an
already running Gromit (If you are curious: Communication between two
gromit instances is done via a special X-Selection).
diff --git a/gromit.c b/gromit.c
index 2041fab..83e4b1d 100644
--- a/gromit.c
+++ b/gromit.c
@@ -44,8 +44,6 @@
#define GROMIT_WINDOW_EVENTS ( GROMIT_PAINT_AREA_EVENTS )
-#define GROMIT_HOTKEY "Pause"
-
/* Atoms used to control Gromit */
#define GA_CONTROL gdk_atom_intern ("Gromit/control", FALSE)
#define GA_STATUS gdk_atom_intern ("Gromit/status", FALSE)
@@ -96,6 +94,7 @@ typedef struct
GdkDisplay *display;
GdkScreen *screen;
GdkWindow *root;
+ gchar *hot_keyval;
guint hot_keycode;
GdkColormap *cm;
@@ -623,7 +622,7 @@ gromit_draw_arrow (GromitData *data, gint x1, gint y1,
}
if (data->cur_context->paint_gc)
- gtk_widget_draw (data->area, &rect);
+ gtk_widget_draw (data->area, &rect);
data->painted = 1;
}
@@ -1023,13 +1022,6 @@ parse_name (GScanner *scanner)
}
void
-parse_print_help (gpointer key, gpointer value, gpointer user_data)
-{
- gromit_paint_context_print ((gchar *) key, (GromitPaintContext *) value);
-}
-
-
-void
parse_config (GromitData *data)
{
GromitPaintContext *context=NULL;
@@ -1271,10 +1263,6 @@ parse_config (GromitData *data)
g_scanner_destroy (scanner);
close (file);
g_free (filename);
-
- g_printerr ("\n-----------------------------\n");
- g_hash_table_foreach (data->tool_config, parse_print_help, NULL);
- g_printerr ("-----------------------------\n\n");
}
@@ -1342,13 +1330,10 @@ setup_client_app (GromitData *data)
void
-setup_main_app (GromitData *data)
+setup_main_app (GromitData *data, gboolean activate)
{
- GdkPixmap *cursor_src, *cursor_mask;
- GdkKeymap *keymap;
- GdkKeymapKey *keys;
- gint n_keys;
- guint keyval;
+ GdkPixmap *cursor_src, *cursor_mask;
+ gboolean have_key = FALSE;
/* COLORMAP */
data->cm = gdk_screen_get_default_colormap (data->screen);
@@ -1468,29 +1453,153 @@ setup_main_app (GromitData *data)
/* Grab the GROMIT_HOTKEY */
- keymap = gdk_keymap_get_for_display (data->display);
+ if (data->hot_keyval)
+ {
+ GdkKeymap *keymap;
+ GdkKeymapKey *keys;
+ gint n_keys;
+ guint keyval;
- keyval = gdk_keyval_from_name (GROMIT_HOTKEY);
+ if (strlen (data->hot_keyval) > 0 &&
+ strcasecmp (data->hot_keyval, "none") != 0)
+ {
+ keymap = gdk_keymap_get_for_display (data->display);
+ keyval = gdk_keyval_from_name (data->hot_keyval);
- if (!keyval || !gdk_keymap_get_entries_for_keyval (keymap, keyval,
- &keys, &n_keys))
- {
- g_printerr ("cannot find the key \"%s\"\n", GROMIT_HOTKEY);
- exit (1);
+ if (!keyval || !gdk_keymap_get_entries_for_keyval (keymap, keyval,
+ &keys, &n_keys))
+ {
+ g_printerr ("cannot find the key \"%s\"\n", data->hot_keyval);
+ exit (1);
+ }
+
+ have_key = TRUE;
+ data->hot_keycode = keys[0].keycode;
+ g_free (keys);
+ }
}
- data->hot_keycode = keys[0].keycode;
- g_free (keys);
+ if (have_key)
+ {
+ if (data->hot_keycode)
+ {
+ gdk_error_trap_push ();
+
+ XGrabKey (GDK_DISPLAY_XDISPLAY (data->display),
+ data->hot_keycode,
+ AnyModifier,
+ GDK_WINDOW_XWINDOW (data->root),
+ TRUE,
+ GrabModeAsync,
+ GrabModeAsync);
+
+ gdk_flush ();
+
+ if (gdk_error_trap_pop ())
+ {
+ g_printerr ("could not grab Hotkey. Aborting...\n");
+ exit (1);
+ }
+ }
+ else
+ {
+ g_printerr ("cannot find the key #%d\n", data->hot_keycode);
+ exit (1);
+ }
+ }
gdk_event_handler_set ((GdkEventFunc) gromit_main_do_event, data, NULL);
gtk_key_snooper_install (key_press_event, data);
- XGrabKey (GDK_DISPLAY_XDISPLAY (data->display),
- data->hot_keycode,
- AnyModifier,
- GDK_WINDOW_XWINDOW (data->root),
- TRUE,
- GrabModeAsync,
- GrabModeAsync);
+
+ if (activate)
+ gromit_acquire_grab (data);
+}
+
+
+void
+parse_print_help (gpointer key, gpointer value, gpointer user_data)
+{
+ gromit_paint_context_print ((gchar *) key, (GromitPaintContext *) value);
+}
+
+int
+app_parse_args (int argc, char **argv, GromitData *data)
+{
+ gint i;
+ gchar *arg;
+ gboolean wrong_arg = FALSE;
+ gboolean activate = FALSE;
+ gboolean dump = FALSE;
+
+ data->hot_keyval = "Pause";
+ data->hot_keycode = 0;
+
+ for (i=1; i < argc ; i++)
+ {
+ arg = argv[i];
+ if (strcmp (arg, "-a") == 0 ||
+ strcmp (arg, "--active") == 0)
+ {
+ activate = TRUE;
+ }
+ else if (strcmp (arg, "-d") == 0 ||
+ strcmp (arg, "--debug") == 0)
+ {
+ dump = TRUE;
+ }
+ else if (strcmp (arg, "-k") == 0 ||
+ strcmp (arg, "--key") == 0)
+ {
+ if (i+1 < argc)
+ {
+ data->hot_keyval = argv[i+1];
+ data->hot_keycode = 0;
+ i++;
+ }
+ else
+ {
+ g_printerr ("-k requires an Key-Name as argument\n");
+ wrong_arg = TRUE;
+ }
+ }
+ else if (strcmp (arg, "-K") == 0 ||
+ strcmp (arg, "--keycode") == 0)
+ {
+ if (i+1 < argc && atoi (argv[i+1]) > 0)
+ {
+ data->hot_keyval = NULL;
+ data->hot_keycode = atoi (argv[i+1]);
+ i++;
+ }
+ else
+ {
+ g_printerr ("-K requires an keycode > 0 as argument\n");
+ wrong_arg = TRUE;
+ }
+ }
+ else
+ {
+ g_printerr ("Unknown Option: \"%s\"\n", arg);
+ wrong_arg = TRUE;
+ }
+
+ if (!wrong_arg)
+ {
+ if (dump)
+ {
+ g_printerr ("\n-----------------------------\n");
+ g_hash_table_foreach (data->tool_config, parse_print_help, NULL);
+ g_printerr ("-----------------------------\n\n");
+ }
+ }
+ else
+ {
+ g_printerr ("Please see the Gromit README for the correct usage\n");
+ exit (1);
+ }
+ }
+
+ return activate;
}
@@ -1501,34 +1610,53 @@ setup_main_app (GromitData *data)
int
main_client (int argc, char **argv, GromitData *data)
{
- GdkAtom action = GDK_NONE;
- gint i;
- gchar *arg;
+ GdkAtom action = GDK_NONE;
+ gint i;
+ gchar *arg;
+ gboolean wrong_arg = FALSE;
for (i=1; i < argc ; i++)
- {
- arg = argv[i];
- action = GDK_NONE;
- if (strcmp (arg, "-t") == 0 ||
- strcmp (arg, "--toggle") == 0)
- action = GA_TOGGLE;
- else if (strcmp (arg, "-v") == 0 ||
- strcmp (arg, "--visibility") == 0)
- action = GA_VISIBILITY;
- else if (strcmp (arg, "-q") == 0 ||
- strcmp (arg, "--quit") == 0)
- action = GA_QUIT;
- else if (strcmp (arg, "-c") == 0 ||
- strcmp (arg, "--clear") == 0)
- action = GA_CLEAR;
-
- if (action != GDK_NONE)
- {
- gtk_selection_convert (data->win, GA_CONTROL,
- action, GDK_CURRENT_TIME);
- gtk_main (); /* Wait for the response */
- }
- }
+ {
+ arg = argv[i];
+ action = GDK_NONE;
+ if (strcmp (arg, "-t") == 0 ||
+ strcmp (arg, "--toggle") == 0)
+ {
+ action = GA_TOGGLE;
+ }
+ else if (strcmp (arg, "-v") == 0 ||
+ strcmp (arg, "--visibility") == 0)
+ {
+ action = GA_VISIBILITY;
+ }
+ else if (strcmp (arg, "-q") == 0 ||
+ strcmp (arg, "--quit") == 0)
+ {
+ action = GA_QUIT;
+ }
+ else if (strcmp (arg, "-c") == 0 ||
+ strcmp (arg, "--clear") == 0)
+ {
+ action = GA_CLEAR;
+ }
+ else
+ {
+ g_printerr ("Unknown Option: \"%s\"\n", arg);
+ wrong_arg = TRUE;
+ }
+
+ if (!wrong_arg && action != GDK_NONE)
+ {
+ gtk_selection_convert (data->win, GA_CONTROL,
+ action, GDK_CURRENT_TIME);
+ gtk_main (); /* Wait for the response */
+ }
+ else
+ {
+ g_printerr ("Please see the Gromit README for the correct usage\n");
+ return 1;
+ }
+ }
return 0;
}
@@ -1557,7 +1685,7 @@ main (int argc, char **argv)
return main_client (argc, argv, data);
/* Main application */
- setup_main_app (data);
+ setup_main_app (data, app_parse_args (argc, argv, data));
gtk_main ();
gdk_display_pointer_ungrab (data->display, GDK_CURRENT_TIME);
gdk_cursor_unref (data->paint_cursor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]