[gromit: 2/13] Import of gromit history
- From: Simon Budig <simon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gromit: 2/13] Import of gromit history
- Date: Tue, 16 Mar 2010 22:23:37 +0000 (UTC)
commit 63e24b823597ff660aece4b68472ad44dfeaeda6
Author: Simon Budig <simon budig de>
Date: Wed Oct 25 12:00:00 2000 +0200
Import of gromit history
README | 12 +-
gromit.c | 42 ++------
gromitconf | 15 ++--
gromitconf.final | 14 +++
parser.c | 314 ++++++++++++++++++++++++++++++++++++++----------------
5 files changed, 258 insertions(+), 139 deletions(-)
---
diff --git a/README b/README
index bf5457b..fb6d991 100644
--- a/README
+++ b/README
@@ -41,12 +41,12 @@ Usage:
gromit --clear
will clear the screen (or "-c")
- If activated gromit prevents you from using other programs with the
- mouse. You can press the button and paint on the screen. Key presses
- will still reach the currently active window but it may be difficult
- to change the window-focus without mouse...
- The next "gromit --toggle" will deactivate gromit and you can use your
- programs as usual - only the painted regions will be obscured.
+If activated gromit prevents you from using other programs with the
+mouse. You can press the button and paint on the screen. Key presses
+will still reach the currently active window but it may be difficult
+to change the window-focus without mouse...
+The next "gromit --toggle" will deactivate gromit and you can use your
+programs as usual - only the painted regions will be obscured.
I included the (shell-)script "sawfish-config". If you are using the
sawfish-windowmanager you can simply start this script. The "Pause"-Key
diff --git a/gromit.c b/gromit.c
index 07c2112..9c177ea 100644
--- a/gromit.c
+++ b/gromit.c
@@ -186,6 +186,10 @@ gromit_toggle_grab (GromitData *data)
default:
g_printerr ("Huh?\n");
}
+
+ /* Hier sollte noch das Fenster wieder in den Vordergrund
+ * geschaltet werden...
+ */
}
}
@@ -196,8 +200,7 @@ gromit_clear_screen (GromitData *data)
gdk_gc_set_foreground (data->shape_gc, data->transparent);
gdk_draw_rectangle (data->shape, data->shape_gc, 1,
0, 0, data->width, data->height);
- gtk_widget_shape_combine_mask (data->win, data->shape, 0,0);
-}
+ gtk_widget_shape_combine_mask (data->win, data->shape, 0,0);}
gint
@@ -233,14 +236,12 @@ gromit_draw_line (GromitData *data, gint x1, gint y1,
if (data->cur_context->paint_gc)
gdk_gc_set_line_attributes (data->cur_context->paint_gc,
- data->maxwidth,
- GDK_LINE_SOLID, GDK_CAP_ROUND,
- GDK_JOIN_ROUND);
+ data->maxwidth, GDK_LINE_SOLID,
+ GDK_CAP_ROUND, GDK_JOIN_ROUND);
if (data->cur_context->shape_gc)
gdk_gc_set_line_attributes (data->cur_context->shape_gc,
- data->maxwidth,
- GDK_LINE_SOLID, GDK_CAP_ROUND,
- GDK_JOIN_ROUND);
+ data->maxwidth, GDK_LINE_SOLID,
+ GDK_CAP_ROUND, GDK_JOIN_ROUND);
if (data->cur_context->paint_gc)
gdk_draw_line (data->pixmap, data->cur_context->paint_gc,
@@ -267,29 +268,6 @@ paint (GtkWidget *win, GdkEventButton *ev, gpointer user_data)
{
GromitData *data = (GromitData *) user_data;
-#if 0
- if (ev->button == 1) {
- if (ev->state & GDK_SHIFT_MASK)
- data->cur_context = data->contexts[1];
- else
- data->cur_context = data->contexts[0];
- } else if (ev->button == 2) {
- if (ev->state & GDK_SHIFT_MASK)
- data->cur_context = data->contexts[3];
- else
- data->cur_context = data->contexts[2];
- } else if (ev->button == 3) {
- if (ev->state & GDK_SHIFT_MASK)
- data->cur_context = data->contexts[5];
- else
- data->cur_context = data->contexts[4];
- } else if (ev->button == 4) {
- gromit_clear_screen (data);
- } else if (ev->button == 5) {
- gtk_main_quit ();
- }
-#endif
-
g_printerr ("Source: %d\n", ev->source);
switch (ev->source) {
case GDK_SOURCE_MOUSE:
@@ -297,11 +275,9 @@ paint (GtkWidget *win, GdkEventButton *ev, gpointer user_data)
data->cur_context = data->contexts[1];
break;
case GDK_SOURCE_PEN:
- gdk_window_set_cursor (data->win->window, data->paint_cursor);
data->cur_context = data->contexts[0];
break;
case GDK_SOURCE_ERASER:
- gdk_window_set_cursor (data->win->window, data->erase_cursor);
data->cur_context = data->contexts[4];
break;
default:
diff --git a/gromitconf b/gromitconf
index fd514c8..d1b4cc8 100644
--- a/gromitconf
+++ b/gromitconf
@@ -2,13 +2,14 @@
# Tools
-"roter Stift" = PEN ( size = 12, color = "red" )
-"Radierer" = Eraser ( size = 50 )
+"roter Stift" = PEN ( size = 12, color = "red" ) ;
+"Radierer" = Eraser ( size = 50 ) ;
-"Pen1" = "roter Stift"
+"Pen1" = "roter Stift";
-"Pen1"[SHIFT,CTRL] = "Radierer"
-"Pen1"[SHIFT+CTRL] = PEN ( SIZE=30, color="red" )
-"Eraser" = ERASER ( color="#0000ff", siZE=50 )
-"Mouse" = NULL
+"Pen1"[SHIFT,CONTROL] = "Radierer";
+"Pen1"[BUTTON1 3 SHIFT CONTROL] = PEN ( SIZE=30, color="red" );
+"Eraser" = ERASER ( color="#0000ff", siZE=50 );
+"Recolor" = REcolor ( coLOr="#0000ff", SIZE=50 );
+# "Mouse" = NULL
diff --git a/gromitconf.final b/gromitconf.final
new file mode 100644
index 0000000..fd514c8
--- /dev/null
+++ b/gromitconf.final
@@ -0,0 +1,14 @@
+# Configuration file for gromit
+
+# Tools
+
+"roter Stift" = PEN ( size = 12, color = "red" )
+"Radierer" = Eraser ( size = 50 )
+
+"Pen1" = "roter Stift"
+
+"Pen1"[SHIFT,CTRL] = "Radierer"
+"Pen1"[SHIFT+CTRL] = PEN ( SIZE=30, color="red" )
+"Eraser" = ERASER ( color="#0000ff", siZE=50 )
+"Mouse" = NULL
+
diff --git a/parser.c b/parser.c
index d50370a..6fd3596 100644
--- a/parser.c
+++ b/parser.c
@@ -4,104 +4,232 @@
#include <sys/stat.h>
#include <fcntl.h>
+typedef enum
+{
+ GROMIT_PEN,
+ GROMIT_ERASER,
+ GROMIT_RECOLOR
+} GromitPaintType;
+
#undef DEBUG
-gint main (void) {
- GScanner *scanner;
- GTokenType token;
- int file;
-
- scanner = g_scanner_new (NULL);
- scanner->config->case_sensitive = 0;
- scanner->config->scan_octal = 0;
- scanner->config->identifier_2_string = 1;
- scanner->config->char_2_token = 1;
- scanner->config->numbers_2_int = 1;
- scanner->config->int_2_float = 1;
-
- g_scanner_scope_add_symbol (scanner, 1, "size", NULL);
- g_scanner_scope_add_symbol (scanner, 1, "color", NULL);
- g_scanner_scope_add_symbol (scanner, 0, "PEN", NULL);
- g_scanner_scope_add_symbol (scanner, 0, "RECOLOR", NULL);
- g_scanner_scope_add_symbol (scanner, 0, "ERASER", NULL);
-
- g_scanner_set_scope (scanner, 1);
- scanner->config->scope_0_fallback = 1;
-
- file = open ("./gromitconf", O_RDONLY);
- g_scanner_input_file (scanner, file);
-
- while ((token = g_scanner_get_next_token (scanner)) != G_TOKEN_EOF) {
- switch (token) {
- case G_TOKEN_LEFT_PAREN:
- printf (" (\n"); break;
- case G_TOKEN_RIGHT_PAREN:
- printf (" )\n"); break;
- case G_TOKEN_LEFT_BRACE:
- printf (" [\n"); break;
- case G_TOKEN_RIGHT_BRACE:
- printf (" ]\n"); break;
- case G_TOKEN_EQUAL_SIGN:
- printf (" =\n"); break;
- case G_TOKEN_COMMA:
- printf (" ,\n"); break;
-
- case G_TOKEN_INT:
- printf ("Integer: %d\n", scanner->value.v_int); break;
- case G_TOKEN_FLOAT:
- printf ("Float : %f\n", scanner->value.v_float); break;
+gchar *parse_name (GScanner *scanner) {
+ GTokenType token;
+
+ guint buttons = 0;
+ guint modifier = 0;
+ guint len = 0;
+ gchar *name;
+
+ token = g_scanner_cur_token(scanner);
+
+ if (token != G_TOKEN_STRING) {
+ g_scanner_unexp_token (scanner, G_TOKEN_STRING, NULL,
+ NULL, NULL, "aborting", TRUE);
+ exit (1);
+ }
+
+ len = strlen (scanner->value.v_string);
+ name = g_strndup (scanner->value.v_string, len + 3);
+
+ token = g_scanner_get_next_token (scanner);
+
+ /*
+ * Are there any options to limit the scope of the definition?
+ */
+
+ if (token == G_TOKEN_LEFT_BRACE) {
+ g_scanner_set_scope (scanner, 1);
+ scanner->config->int_2_float = 0;
+ modifier = buttons = 0;
+ while ((token = g_scanner_get_next_token (scanner))
+ != G_TOKEN_RIGHT_BRACE) {
+ if (token == G_TOKEN_SYMBOL) {
+ /* printf ("symbol: %d\n", scanner->value.v_symbol);
+ */
+ if ((guint) scanner->value.v_symbol < 11)
+ buttons |= 1 << ((guint) scanner->value.v_symbol - 1);
+ else
+ modifier |= 1 << ((guint) scanner->value.v_symbol - 11);
+ } else if (token == G_TOKEN_INT) {
+ if (scanner->value.v_int <= 5 && scanner->value.v_int > 0) {
+ printf ("int: %d\n", scanner->value.v_int);
+ buttons |= 1 << (scanner->value.v_int - 1);
+ } else {
+ printf ("Only Buttons 1-5 are supported!\n");
+ }
+ } else {
+ printf ("skipped token\n");
+ }
+ }
+ printf ("Limiting: Buttons: %d, Modifier: %d\n", buttons, modifier);
+ g_scanner_set_scope (scanner, 0);
+ scanner->config->int_2_float = 1;
+ token = g_scanner_get_next_token (scanner);
+ }
- case G_TOKEN_STRING:
- printf ("String : %s\n", scanner->value.v_string); break;
+ name [len] = 124;
+ name [len+1] = buttons + 64;
+ name [len+2] = modifier + 48;
+
+ printf ("Name: %s\n", name);
+ return name;
+}
- case G_TOKEN_IDENTIFIER:
- case G_TOKEN_IDENTIFIER_NULL:
- printf ("Ident : %s\n", scanner->value.v_identifier); break;
+
+
+gint parse (void) {
+ GScanner *scanner;
+ GTokenType token;
+ int file;
+
+ gchar *name, *copy;
+ gchar *color=NULL;
+ gdouble size;
+ guint buttons, modifier;
+
+ scanner = g_scanner_new (NULL);
+ scanner->config->case_sensitive = 0;
+ scanner->config->scan_octal = 0;
+ scanner->config->identifier_2_string = 0;
+ scanner->config->char_2_token = 1;
+ scanner->config->numbers_2_int = 1;
+ scanner->config->int_2_float = 1;
+
+ g_scanner_scope_add_symbol (scanner, 0, "PEN", (gpointer) GROMIT_PEN);
+ g_scanner_scope_add_symbol (scanner, 0, "ERASER", (gpointer) GROMIT_ERASER);
+ g_scanner_scope_add_symbol (scanner, 0, "RECOLOR",(gpointer) GROMIT_RECOLOR);
+
+ g_scanner_scope_add_symbol (scanner, 1, "BUTTON1",(gpointer) 1);
+ g_scanner_scope_add_symbol (scanner, 1, "BUTTON2",(gpointer) 2);
+ g_scanner_scope_add_symbol (scanner, 1, "BUTTON3",(gpointer) 3);
+ g_scanner_scope_add_symbol (scanner, 1, "BUTTON4",(gpointer) 4);
+ g_scanner_scope_add_symbol (scanner, 1, "BUTTON5",(gpointer) 5);
+ g_scanner_scope_add_symbol (scanner, 1, "SHIFT", (gpointer) 11);
+ g_scanner_scope_add_symbol (scanner, 1, "CONTROL",(gpointer) 12);
+ g_scanner_scope_add_symbol (scanner, 1, "META", (gpointer) 13);
+
+ g_scanner_scope_add_symbol (scanner, 2, "size", (gpointer) 1);
+ g_scanner_scope_add_symbol (scanner, 2, "color", (gpointer) 2);
+
+ g_scanner_set_scope (scanner, 0);
+ scanner->config->scope_0_fallback = 0;
+
+ file = open ("./gromitconf", O_RDONLY);
+ g_scanner_input_file (scanner, file);
+
+ token = g_scanner_get_next_token (scanner);
+ while (token != G_TOKEN_EOF) {
- case G_TOKEN_SYMBOL:
- printf (" SYMBOL!\n"); break;
-
- case G_TOKEN_CHAR:
- printf ("Char : %c\n", scanner->value.v_char); break;
-
- case G_TOKEN_ERROR:
- printf ("*** Error!\n"); break;
-
-#ifdef DEBUG
- case G_TOKEN_LAST:
- printf ("G_TOKEN_LAST\n"); break;
-
- case G_TOKEN_LEFT_CURLY:
- printf ("G_TOKEN_LEFT_CURLY\n"); break;
- case G_TOKEN_RIGHT_CURLY:
- printf ("G_TOKEN_RIGHT_CURLY\n"); break;
- case G_TOKEN_LEFT_BRACE:
- printf ("G_TOKEN_LEFT_BRACE\n"); break;
- case G_TOKEN_RIGHT_BRACE:
- printf ("G_TOKEN_RIGHT_BRACE\n"); break;
- case G_TOKEN_NONE:
- printf ("G_TOKEN_NONE\n"); break;
- case G_TOKEN_BINARY:
- printf ("G_TOKEN_BINARY\n"); break;
- case G_TOKEN_OCTAL:
- printf ("G_TOKEN_OCTAL\n"); break;
- case G_TOKEN_HEX:
- printf ("G_TOKEN_HEX\n"); break;
- case G_TOKEN_COMMENT_SINGLE:
- printf ("G_TOKEN_COMMENT_SINGLE\n"); break;
- case G_TOKEN_COMMENT_MULTI:
- printf ("G_TOKEN_COMMENT_MULTI\n"); break;
- case G_TOKEN_EOF:
- printf ("G_TOKEN_EOF\n"); break;
-
-#endif
- default:
- printf ("Unknown Token: %d, '%s'!\n", scanner->token, scanner->value);
-
- }
- }
- close (file);
- g_scanner_destroy (scanner);
+ /*
+ * New tool definition
+ */
+
+ if (token == G_TOKEN_STRING) {
+ name = parse_name (scanner);
+ token = g_scanner_cur_token(scanner);
+
+ if (token != G_TOKEN_EQUAL_SIGN) {
+ g_scanner_unexp_token (scanner, G_TOKEN_EQUAL_SIGN, NULL,
+ NULL, NULL, "aborting", TRUE);
+ exit (1);
+ }
+
+ token = g_scanner_get_next_token (scanner);
+ if (token == G_TOKEN_SYMBOL) {
+ printf ("Tool Type: %d\n", scanner->value.v_symbol);
+
+ token = g_scanner_get_next_token (scanner);
+
+ /* Are there any tool-options?
+ */
+
+ if (token == G_TOKEN_LEFT_PAREN) {
+ /* printf ("Extra tool options\n");
+ */
+ if (color)
+ g_free (color);
+ color = NULL;
+ size = 0;
+ g_scanner_set_scope (scanner, 2);
+ scanner->config->int_2_float = 1;
+ token = g_scanner_get_next_token (scanner);
+ while (token != G_TOKEN_RIGHT_PAREN) {
+ if (token == G_TOKEN_SYMBOL) {
+ if ((guint) scanner->value.v_symbol == 1) {
+ token = g_scanner_get_next_token (scanner);
+ if (token != G_TOKEN_EQUAL_SIGN) {
+ printf ("Missing \"=\"... aborting\n");
+ exit (1);
+ }
+ token = g_scanner_get_next_token (scanner);
+ if (token != G_TOKEN_FLOAT) {
+ printf ("Missing Size (float)... aborting\n");
+ exit (1);
+ }
+ size = scanner->value.v_float;
+ } else if ((guint) scanner->value.v_symbol == 2) {
+ token = g_scanner_get_next_token (scanner);
+ if (token != G_TOKEN_EQUAL_SIGN) {
+ printf ("Missing \"=\"... aborting\n");
+ exit (1);
+ }
+ token = g_scanner_get_next_token (scanner);
+ if (token != G_TOKEN_STRING) {
+ printf ("Missing Color (string)... aborting\n");
+ exit (1);
+ }
+ if (color != NULL)
+ g_free (color);
+ color = g_strdup (scanner->value.v_string);
+ } else {
+ printf ("Unknown tool type?????\n");
+ }
+ } else {
+ printf ("skipped token!!!\n");
+ }
+ token = g_scanner_get_next_token (scanner);
+ }
+ g_scanner_set_scope (scanner, 0);
+ token = g_scanner_get_next_token (scanner);
+ }
+ printf ("Size: %.2f ; Color \"%s\"\n", size, color);
+ } else if (token == G_TOKEN_STRING) {
+ copy = parse_name (scanner);
+ token = g_scanner_cur_token(scanner);
+ printf ("\"%s\" gets config from \"%s\"\n", name, copy);
+ } else {
+ printf ("Expected either Tool-definition or name of template tool\n");
+ exit (1);
+ }
+
+
+ /*
+ * Finally we expect a semicolon
+ */
+
+ if (token != ';') {
+ printf ("Expected \";\"\n");
+ exit (1);
+ }
+
+ } else {
+ printf ("Expected name of Tool to define\n");
+ exit(1);
+ }
+
+ token = g_scanner_get_next_token (scanner);
+
+ }
+ close (file);
+ g_scanner_destroy (scanner);
}
+int main (int argc, char *argv[]) {
+ parse ();
+}
+
+
+
+/* vim: sw=3 ts=8 cindent noai bs=2 cinoptions=(0 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]