diff --git a/CMakeLists.txt b/CMakeLists.txt index f5e09c0..d64d92e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,8 +55,6 @@ set(sources src/callbacks.h src/config.c src/config.h - src/parser.c - src/parser.h src/drawing.c src/drawing.h src/coordlist_ops.c diff --git a/README.md b/README.md index a7e7fcd..24d6957 100644 --- a/README.md +++ b/README.md @@ -97,9 +97,17 @@ Usage: will undo the last drawing stroke (or "-z") gromit-mpx --redo will redo the last undone drawing stroke (or "-y") + gromit-mpx --change-tool + will redefine a tool, using the same syntax as in the .cfg file + e.g. gromit-mpx --change-tool '"default"=RECT(color="yellow" size=2)' + gromit-mpx --change-attribute + will change one or several attributes of a tool, keeping the others + as they were. This can be used to change e.g. to color or type of a tool + e.g. gromit-mpx --change-attribute '"default"=(color="cyan")' + gromit-mpx --change-attribute '"default"=LINE' gromit-mpx --line will draw a straight line with characteristics specified by the arguments (or "-l") - eg: gromit-mpx -l 200 200 400 400 '#C4A7E7' 6 + e.g.: gromit-mpx -l 200 200 400 400 '#C4A7E7' 6 If activated Gromit-MPX prevents you from using other programs with the mouse. You can press the button and paint on the screen. Key presses diff --git a/gromit-mpx.1 b/gromit-mpx.1 index c0462b5..28476ff 100644 --- a/gromit-mpx.1 +++ b/gromit-mpx.1 @@ -1,5 +1,5 @@ .\" Hey, vim: ft=nroff -.TH GROMIT-MPX 1 "November 3, 2018" +.TH GROMIT-MPX 1 "March 31, 2024" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -95,9 +95,6 @@ running Gromit-MPX process, see above for the options available to start Gromit- .B \-c, \-\-clear will clear the screen. .TP -.B \-l , \-\-line -will draw a line from (x1,y1) to (x2,y2) with color and width . -.TP .B \-q, \-\-quit will cause the main Gromit-MPX process to quit. .TP @@ -107,6 +104,12 @@ will toggle the grabbing of the cursor. .B \-T , \-\-change-tool will change the definition of a tool. The syntax is as in the .cfg file read at startup, except for the trailing semicolon. +(example: gromit-mpx -T '"default"=RECT(color="yellow" size=2)' +.TP +.B \-A , \-\-change-attribute +will change one or several attributes of a tool, keeping the other settings. +(example 1: change just the color: gromit-mpx -A '"default"=(color="yellow")'; +example 2: change tool type, keeping color, size etc: gromit-mpx -A '"default"=LINE') .TP .B \-v, \-\-visibility will toggle the visibility of the window. diff --git a/src/callbacks.c b/src/callbacks.c index 73d3da1..cf792f4 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -25,7 +25,6 @@ #include #include #include -#include "cairo.h" #include "main.h" #include "input.h" #include "callbacks.h" @@ -142,18 +141,10 @@ void on_monitors_changed ( GdkScreen *screen, parse_config(data); // also calls paint_context_new() :-( - -<<<<<<< HEAD - data->default_pen = paint_context_new (data, GROMIT_PEN, data->red, 7, 0, GROMIT_ARROW_END, + data->default_pen = paint_context_new (data, GROMIT_PEN, gdk_rgba_copy(data->red), 7, 0, GROMIT_ARROW_END, 5, 10, 15, 25, 1, 0, G_MAXUINT); - data->default_eraser = paint_context_new (data, GROMIT_ERASER, data->red, 75, 0, GROMIT_ARROW_END, + data->default_eraser = paint_context_new (data, GROMIT_ERASER, gdk_rgba_copy(data->red), 75, 0, GROMIT_ARROW_END, 5, 10, 15, 25, 1, 0, G_MAXUINT); -======= - data->default_pen = paint_context_new (data, GROMIT_PEN, gdk_rgba_copy(data->red), 7, - 0, GROMIT_ARROW_END, 1, G_MAXUINT); - data->default_eraser = paint_context_new (data, GROMIT_ERASER, gdk_rgba_copy(data->red), 75, - 0, GROMIT_ARROW_END, 1, G_MAXUINT); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) if(!data->composited) // set shape { @@ -221,7 +212,7 @@ void on_clientapp_selection_get (GtkWidget *widget, if (gtk_selection_data_get_target(selection_data) == GA_TOGGLEDATA || gtk_selection_data_get_target(selection_data) == GA_LINEDATA || - gtk_selection_data_get_target(selection_data) == GA_DEFTOOLDATA || + gtk_selection_data_get_target(selection_data) == GA_CHGTOOLDATA || gtk_selection_data_get_target(selection_data) == GA_CHGATTRDATA) { ans = data->clientdata; @@ -292,11 +283,7 @@ gboolean on_buttonpress (GtkWidget *win, GromitPaintType type = devdata->cur_context->type; // store original state to have dynamic update of line and rect -<<<<<<< HEAD if (type == GROMIT_LINE || type == GROMIT_RECT || type == GROMIT_SMOOTH || type == GROMIT_ORTHOGONAL) -======= - if (type == GROMIT_LINE || type == GROMIT_RECT) ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) { copy_surface(data->aux_backbuffer, data->backbuffer); } @@ -413,12 +400,8 @@ gboolean on_motion (GtkWidget *win, } if (type == GROMIT_LINE) { -<<<<<<< HEAD - GromitArrowType atype = devdata->cur_context->arrow_type; -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) draw_line (data, ev->device, devdata->lastx, devdata->lasty, ev->x, ev->y); - if (devdata->cur_context->arrowsize > 0) + if (devdata->cur_context->arrowsize > 0.0) { GromitArrowType atype = devdata->cur_context->arrow_type; gint width = devdata->cur_context->arrowsize * devdata->cur_context->width / 2; @@ -467,14 +450,8 @@ gboolean on_buttonrelease (GtkWidget *win, gfloat direction = 0; gint width = 0; -<<<<<<< HEAD if(ctx) width = ctx->arrowsize * ctx->width / 2; -======= - if(devdata->cur_context) - width = devdata->cur_context->arrowsize * devdata->cur_context->width / 2; - ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) if ((ev->x != devdata->lastx) || (ev->y != devdata->lasty)) @@ -483,7 +460,6 @@ gboolean on_buttonrelease (GtkWidget *win, if (!devdata->is_grabbed) return FALSE; -<<<<<<< HEAD GromitPaintType type = ctx->type; if (type == GROMIT_SMOOTH || type == GROMIT_ORTHOGONAL) @@ -517,13 +493,6 @@ gboolean on_buttonrelease (GtkWidget *win, if (ctx->arrowsize != 0) { GromitArrowType atype = ctx->arrow_type; -======= - GromitPaintType type = devdata->cur_context->type; - - if (devdata->cur_context->arrowsize != 0) - { - GromitArrowType atype = devdata->cur_context->arrow_type; ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) if (type == GROMIT_LINE) { direction = atan2 (ev->y - devdata->lasty, ev->x - devdata->lastx); @@ -590,9 +559,9 @@ void on_mainapp_selection_get (GtkWidget *widget, undo_drawing (data); else if (action == GA_REDO) redo_drawing (data); - else if (action == GA_DEFTOOL) + else if (action == GA_CHGTOOL) { - gtk_selection_convert(data->win, GA_DATA, GA_DEFTOOLDATA, time); + gtk_selection_convert(data->win, GA_DATA, GA_CHGTOOLDATA, time); gtk_main(); } else if (action == GA_CHGATTR) @@ -687,13 +656,8 @@ void on_mainapp_selection_received (GtkWidget *widget, "Keeping default.\n"); } GromitPaintContext* line_ctx = -<<<<<<< HEAD paint_context_new(data, GROMIT_PEN, fg_color, thickness, 0, GROMIT_ARROW_END, 5, 10, 15, 25, 0, thickness, thickness); -======= - paint_context_new(data, GROMIT_PEN, fg_color, thickness, - 0, GROMIT_ARROW_END, thickness, thickness); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) GdkRectangle rect; rect.x = MIN (startX,endX) - thickness / 2; @@ -719,7 +683,7 @@ void on_mainapp_selection_received (GtkWidget *widget, else { GdkAtom atom = gtk_selection_data_get_target(selection_data); - if (atom == GA_DEFTOOLDATA || atom == GA_CHGATTRDATA) + if (atom == GA_CHGTOOLDATA || atom == GA_CHGATTRDATA) { gchar *a = (gchar *)gtk_selection_data_get_data(selection_data); if(data->debug) g_printerr("DEBUG: define tool: %s\n", a); @@ -1100,7 +1064,6 @@ void on_intro(GtkMenuItem *menuitem, gtk_widget_show_all (assistant); } -<<<<<<< HEAD void on_edit_config(GtkMenuItem *menuitem, gpointer user_data) { @@ -1155,8 +1118,6 @@ void on_edit_config(GtkMenuItem *menuitem, } -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) void on_issues(GtkMenuItem *menuitem, gpointer user_data) { diff --git a/src/callbacks.h b/src/callbacks.h index ce7e88b..7bcbdd8 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -128,12 +128,9 @@ void on_about(GtkMenuItem *menuitem, void on_intro(GtkMenuItem *menuitem, gpointer user_data); -<<<<<<< HEAD void on_edit_config(GtkMenuItem *menuitem, gpointer user_data); -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) void on_issues(GtkMenuItem *menuitem, gpointer user_data); diff --git a/src/config.c b/src/config.c index 3693a04..9bf183b 100644 --- a/src/config.c +++ b/src/config.c @@ -29,7 +29,6 @@ #include #include "config.h" -#include "math.h" #include "main.h" #include "math.h" #include "build-config.h" @@ -50,10 +49,6 @@ static gpointer UNDOKEY_SYMBOL_VALUE = (gpointer) 4; /* * initialize GScanner for the parsing of tool definitions */ -<<<<<<< HEAD -======= - ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) void scanner_init(GScanner *scanner) { scanner->config->case_sensitive = 0; @@ -63,7 +58,6 @@ void scanner_init(GScanner *scanner) scanner->config->numbers_2_int = 1; scanner->config->int_2_float = 1; -<<<<<<< HEAD g_scanner_scope_add_symbol (scanner, 0, "PEN", (gpointer) GROMIT_PEN); g_scanner_scope_add_symbol (scanner, 0, "LINE", (gpointer) GROMIT_LINE); g_scanner_scope_add_symbol (scanner, 0, "RECT", (gpointer) GROMIT_RECT); @@ -73,15 +67,6 @@ void scanner_init(GScanner *scanner) g_scanner_scope_add_symbol (scanner, 0, "RECOLOR", (gpointer) GROMIT_RECOLOR); g_scanner_scope_add_symbol (scanner, 0, "HOTKEY", HOTKEY_SYMBOL_VALUE); g_scanner_scope_add_symbol (scanner, 0, "UNDOKEY", UNDOKEY_SYMBOL_VALUE); -======= - g_scanner_scope_add_symbol (scanner, 0, "PEN", (gpointer) GROMIT_PEN); - g_scanner_scope_add_symbol (scanner, 0, "LINE", (gpointer) GROMIT_LINE); - g_scanner_scope_add_symbol (scanner, 0, "RECT", (gpointer) GROMIT_RECT); - 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, 0, "HOTKEY", HOTKEY_SYMBOL_VALUE); - g_scanner_scope_add_symbol (scanner, 0, "UNDOKEY", UNDOKEY_SYMBOL_VALUE); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) g_scanner_scope_add_symbol (scanner, 1, "BUTTON1", (gpointer) 1); g_scanner_scope_add_symbol (scanner, 1, "BUTTON2", (gpointer) 2); @@ -99,14 +84,11 @@ void scanner_init(GScanner *scanner) g_scanner_scope_add_symbol (scanner, 2, "arrowtype", (gpointer) SYM_ARROWTYPE); g_scanner_scope_add_symbol (scanner, 2, "minsize", (gpointer) SYM_MINSIZE); g_scanner_scope_add_symbol (scanner, 2, "maxsize", (gpointer) SYM_MAXSIZE); -<<<<<<< HEAD g_scanner_scope_add_symbol (scanner, 2, "radius", (gpointer) SYM_RADIUS); g_scanner_scope_add_symbol (scanner, 2, "maxangle", (gpointer) SYM_MAXANGLE); g_scanner_scope_add_symbol (scanner, 2, "minlen", (gpointer) SYM_MINLEN); g_scanner_scope_add_symbol (scanner, 2, "simplify", (gpointer) SYM_SIMPLIFY); g_scanner_scope_add_symbol (scanner, 2, "snap", (gpointer) SYM_SNAP); -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) g_scanner_set_scope (scanner, 0); scanner->config->scope_0_fallback = 0; @@ -138,13 +120,6 @@ gchar* parse_name (GScanner *scanner) name = g_strndup (scanner->value.v_string, len + 3); token = g_scanner_get_next_token (scanner); -<<<<<<< HEAD - /* - * Are there any options to limit the scope of the definition? - */ - -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) if (token == G_TOKEN_LEFT_BRACE) { g_scanner_set_scope (scanner, 1); @@ -213,14 +188,11 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty style->width = 7; style->arrowsize = 0; style->arrow_type = GROMIT_ARROW_END; -<<<<<<< HEAD style->radius = 10; style->minlen = style->radius * 5 / 2; style->maxangle = 15; style->simplify = 10; style->snapdist = 0; -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) style->minwidth = 1; style->maxwidth = G_MAXUINT; @@ -249,14 +221,11 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty style->width = context->width; style->arrowsize = context->arrowsize; style->arrow_type = context->arrow_type; -<<<<<<< HEAD style->radius = context->radius; style->minlen = context->minlen; style->maxangle = context->maxangle; style->simplify = context->simplify; style->snapdist = context->snapdist; -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) style->minwidth = context->minwidth; style->maxwidth = context->maxwidth; *style->paint_color = *context->paint_color; @@ -273,11 +242,7 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty } else { -<<<<<<< HEAD g_printerr ("Expected tool definition or name of template tool\n"); -======= - g_printerr ("Expected Tool-definition or name of template tool\n"); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) goto cleanup; } return TRUE; @@ -286,10 +251,6 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty if (color_allocated) { g_free(style->paint_color); -<<<<<<< HEAD -======= - g_printerr("parse_tool: free color @ %p\n", style->paint_color); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) style->paint_color = NULL; } return FALSE; @@ -306,7 +267,7 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style) GTokenType token; if (id == SYM_SIZE) { - gfloat v = parse_float(scanner, "Missing size"); + gfloat v = parse_get_float(scanner, "Missing size"); if (isnan(v)) return SYM_ERROR; style->width = v + 0.5; } @@ -331,13 +292,9 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style) } else if (id == SYM_ARROWSIZE) { - gfloat v = parse_float(scanner, "Missing arrowsize"); + gfloat v = parse_get_float(scanner, "Missing arrowsize"); if (isnan(v)) return SYM_ERROR; -<<<<<<< HEAD style->arrowsize = v; -======= - style->arrowsize = v + 0.5; ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) } else if (id == SYM_ARROWTYPE) { @@ -372,61 +329,47 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style) return SYM_ERROR; } } -<<<<<<< HEAD else if ((intptr_t) scanner->value.v_symbol == SYM_RADIUS) { gfloat v = parse_get_float(scanner, "Missing radius (float)"); - if (isnan(v)) goto cleanup; + if (isnan(v)) return SYM_ERROR; style->radius = v; } else if ((intptr_t) scanner->value.v_symbol == SYM_MAXANGLE) { gfloat v = parse_get_float(scanner, "Missing angle (float)"); - if (isnan(v)) goto cleanup; + if (isnan(v)) return SYM_ERROR; style->maxangle = v; } else if ((intptr_t) scanner->value.v_symbol == SYM_SIMPLIFY) { gfloat v = parse_get_float(scanner, "Missing simplify value (float)"); - if (isnan(v)) goto cleanup; + if (isnan(v)) return SYM_ERROR; style->simplify = v; } else if ((intptr_t) scanner->value.v_symbol == SYM_MINLEN) { gfloat v = parse_get_float(scanner, "Missing minlen value (float)"); - if (isnan(v)) goto cleanup; + if (isnan(v)) return SYM_ERROR; style->minlen = v; } else if ((intptr_t) scanner->value.v_symbol == SYM_SNAP) { gfloat v = parse_get_float(scanner, "Missing snap distance (float)"); - if (isnan(v)) goto cleanup; + if (isnan(v)) return SYM_ERROR; style->snapdist = v; } else if (id == SYM_MINSIZE) { - gfloat v = parse_float(scanner, "Missing minsize"); + gfloat v = parse_get_float(scanner, "Missing minsize"); if (isnan(v)) return SYM_ERROR; style->minwidth = v + 0.5; } else if (id == SYM_MAXSIZE) { - gfloat v = parse_float(scanner, "Missing maxsize"); + gfloat v = parse_get_float(scanner, "Missing maxsize"); if (isnan(v)) return SYM_ERROR; style->maxwidth = v + 0.5; -======= - else if (id == SYM_MINSIZE) - { - gfloat v = parse_float(scanner, "Missing minsize"); - if (isnan(v)) return SYM_ERROR; - style->minwidth = v + 0.5; - } - else if (id == SYM_MAXSIZE) - { - gfloat v = parse_float(scanner, "Missing maxsize"); - if (isnan(v)) return SYM_ERROR; - style->maxwidth = v + 0.5; ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) } else { @@ -437,7 +380,6 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style) } /* -<<<<<<< HEAD * get "=VALUE", where VALUE is a float * returns NAN is an error occurs */ @@ -457,26 +399,7 @@ gfloat parse_get_float(GScanner *scanner, const gchar *msg) return NAN; } return scanner->value.v_float; -======= - * parse "=", with value being a float - * return as gfloat, or NAN on error - */ -gfloat parse_float(GScanner *scanner, const gchar *msg) { - GTokenType token = g_scanner_get_next_token(scanner); - if (token != G_TOKEN_EQUAL_SIGN) { - g_printerr("Missing \"=\"... aborting\n"); - return NAN; - } - token = g_scanner_get_next_token(scanner); - if (token != G_TOKEN_FLOAT) { - g_printerr("%s", msg); - g_printerr("... aborting\n"); - return NAN; - } - return scanner->value.v_float; ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) } - /* * parses a pen style definition (e.g. (color="red" size=3) ) * and stores fields found in GromitStyleDef. @@ -509,14 +432,14 @@ gboolean parse_style(GScanner *scanner, GromitPaintContext *style) gboolean parse_config (GromitData *data) { gboolean status = FALSE; - GromitPaintContext *context = NULL; + GromitPaintContext *context=NULL; GScanner *scanner; GTokenType token; gchar *filename; int file; gchar *name; - // try user config location + /* try user config location */ filename = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_config_dir(), "gromit-mpx.cfg", NULL); if ((file = open(filename, O_RDONLY)) < 0) @@ -525,7 +448,7 @@ gboolean parse_config (GromitData *data) g_print("Using user config %s\n", filename); - // try global config file + /* try global config file */ if (file < 0) { g_free(filename); filename = g_strdup (SYSCONFDIR "/gromit-mpx/gromit-mpx.cfg"); @@ -535,15 +458,14 @@ gboolean parse_config (GromitData *data) g_print("Using system config %s\n", filename); } - // was the last possibility, no use to go on + /* was the last possibility, no use to go on */ if (file < 0) { g_free(filename); - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(data->win), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, - _("No usable config file found, falling back to default tools.")); + GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(data->win), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_CLOSE, + _("No usable config file found, falling back to default tools.")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return FALSE; @@ -572,7 +494,6 @@ gboolean parse_config (GromitData *data) goto cleanup; } - // are there any tool-options? token = g_scanner_cur_token(scanner); if (token == G_TOKEN_LEFT_PAREN) @@ -589,29 +510,20 @@ gboolean parse_config (GromitData *data) goto cleanup; } -<<<<<<< HEAD context = paint_context_new(data, style.type, style.paint_color, style.width, style.arrowsize, style.arrow_type, style.simplify, style.radius, style.maxangle, style.minlen, style.snapdist, style.minwidth, style.maxwidth); g_hash_table_insert (data->tool_config, name, context); -======= - context = paint_context_new(data, - style.type, - style.paint_color, - style.width, - style.arrowsize, - style.arrow_type, - style.minwidth, - style.maxwidth); - g_hash_table_insert(data->tool_config, name, context); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) } else if (token == G_TOKEN_SYMBOL && (scanner->value.v_symbol == HOTKEY_SYMBOL_VALUE || scanner->value.v_symbol == UNDOKEY_SYMBOL_VALUE)) { - // hot key definition + /* + * Hot key definition + */ + gpointer key_type = scanner->value.v_symbol; token = g_scanner_get_next_token(scanner); @@ -650,7 +562,7 @@ gboolean parse_config (GromitData *data) } else { - g_printerr ("Expected name of tool to define or hot key definition\n"); + g_printerr ("Expected name of Tool to define or Hot key definition\n"); goto cleanup; } @@ -671,13 +583,12 @@ gboolean parse_config (GromitData *data) g_hash_table_remove_all(data->tool_config); /* alert user */ - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(data->win), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, - _("Failed parsing config file %s, falling back to default tools."), - filename); + GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(data->win), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_CLOSE, + _("Failed parsing config file %s, falling back to default tools."), + filename); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } diff --git a/src/config.h b/src/config.h index 340186e..306ec98 100644 --- a/src/config.h +++ b/src/config.h @@ -33,27 +33,14 @@ Select and parse system or user .cfg file. Returns TRUE if something got parsed successfully, FALSE otherwise. */ -gboolean parse_config (GromitData *data); -<<<<<<< HEAD -int parse_args (int argc, char **argv, GromitData *data); -gchar* parse_name (GScanner *scanner); typedef enum { SYM_ERROR = 0, SYM_SIZE = 1, -======= -int parse_args(int argc, char **argv, GromitData *data); -gchar* parse_name (GScanner *scanner); - -typedef enum { - SYM_ERROR=0, - SYM_SIZE=1, ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) SYM_COLOR, SYM_ARROWSIZE, SYM_ARROWTYPE, SYM_MINSIZE, -<<<<<<< HEAD SYM_MAXSIZE, SYM_MINLEN, SYM_MAXANGLE, @@ -62,22 +49,17 @@ typedef enum { SYM_SNAP } ToolAttribute; -void scanner_init(GScanner *scanner); -gboolean parse_tool(GromitData *data, GScanner *scanner, - GromitPaintContext *style); -gboolean parse_style(GScanner *scanner, GromitPaintContext *style); -gfloat parse_get_float(GScanner *scanner, const gchar *msg); -======= - SYM_MAXSIZE -} ToolAttribute; - void scanner_init(GScanner *scanner); gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *style); +gboolean parse_config (GromitData *data); +gchar* parse_name (GScanner *scanner); +gfloat parse_get_float(GScanner *scanner, const gchar *msg); gboolean parse_style(GScanner *scanner, GromitPaintContext *style); -gfloat parse_float(GScanner *scanner, const gchar *msg); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style); +int parse_args (int argc, char **argv, GromitData *data); + + /* fallback hot key, if not specified on command line or in config file */ #ifndef DEFAULT_HOTKEY diff --git a/src/drawing.c b/src/drawing.c index 4e258e3..1307322 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -2,17 +2,6 @@ #include #include "drawing.h" #include "main.h" -<<<<<<< HEAD -======= - -typedef struct -{ - gint x; - gint y; - gint width; -} GromitStrokeCoordinate; - ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) void draw_line (GromitData *data, GdkDevice *dev, @@ -116,110 +105,3 @@ void draw_arrow (GromitData *data, data->painted = 1; } -<<<<<<< HEAD -======= - -void coord_list_prepend (GromitData *data, - GdkDevice* dev, - gint x, - gint y, - gint width) -{ - /* get the data for this device */ - GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev); - - GromitStrokeCoordinate *point; - - point = g_malloc (sizeof (GromitStrokeCoordinate)); - point->x = x; - point->y = y; - point->width = width; - - devdata->coordlist = g_list_prepend (devdata->coordlist, point); -} - - -void coord_list_free (GromitData *data, - GdkDevice* dev) -{ - /* get the data for this device */ - GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev); - - GList *ptr; - ptr = devdata->coordlist; - - while (ptr) - { - g_free (ptr->data); - ptr = ptr->next; - } - - g_list_free (devdata->coordlist); - - devdata->coordlist = NULL; -} - -/* - * for double-ended arrows, two separate calls are required - */ - -gboolean coord_list_get_arrow_param (GromitData *data, - GdkDevice *dev, - gint search_radius, - GromitArrowType arrow_end, - gint *x0, - gint *y0, - gint *ret_width, - gfloat *ret_direction) -{ - gint r2, dist; - gboolean success = FALSE; - GromitStrokeCoordinate *cur_point, *valid_point; - /* get the data for this device */ - GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev); - GList *ptr = devdata->coordlist; - gfloat width; - - valid_point = NULL; - - if (ptr) - { - if (arrow_end == GROMIT_ARROW_START) - ptr = g_list_last(ptr); - cur_point = ptr->data; - *x0 = cur_point->x; - *y0 = cur_point->y; - r2 = search_radius * search_radius; - dist = 0; - - while (ptr && dist < r2) - { - if (arrow_end == GROMIT_ARROW_END) - ptr = ptr->next; - else - ptr = ptr->prev; - if (ptr) - { - cur_point = ptr->data; - dist = (cur_point->x - *x0) * (cur_point->x - *x0) + - (cur_point->y - *y0) * (cur_point->y - *y0); - width = cur_point->width * devdata->cur_context->arrowsize; - if (width * 2 <= dist && - (!valid_point || valid_point->width < cur_point->width)) - valid_point = cur_point; - } - } - - if (valid_point) - { - *ret_width = MAX (valid_point->width * devdata->cur_context->arrowsize, - 2); - *ret_direction = atan2 (*y0 - valid_point->y, *x0 - valid_point->x); - success = TRUE; - } - } - - return success; -} - ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) diff --git a/src/drawing.h b/src/drawing.h index 1cb4a38..2abf151 100644 --- a/src/drawing.h +++ b/src/drawing.h @@ -19,19 +19,4 @@ typedef struct void draw_line (GromitData *data, GdkDevice *dev, gint x1, gint y1, gint x2, gint y2); void draw_arrow (GromitData *data, GdkDevice *dev, gint x1, gint y1, gint width, gfloat direction); -<<<<<<< HEAD -======= -gboolean coord_list_get_arrow_param (GromitData *data, - GdkDevice *dev, - gint search_radius, - GromitArrowType arrow_end, - gint *x0, - gint *y0, - gint *ret_width, - gfloat *ret_direction); -void coord_list_prepend (GromitData *data, GdkDevice* dev, gint x, gint y, gint width); -void coord_list_free (GromitData *data, GdkDevice* dev); - - ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) #endif diff --git a/src/main.c b/src/main.c index 186843b..251537a 100644 --- a/src/main.c +++ b/src/main.c @@ -43,14 +43,11 @@ GromitPaintContext *paint_context_new (GromitData *data, guint width, guint arrowsize, GromitArrowType arrowtype, -<<<<<<< HEAD guint simpilfy, guint radius, guint maxangle, guint minlen, guint snapdist, -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) guint minwidth, guint maxwidth) { @@ -98,7 +95,6 @@ void paint_context_print (gchar *name, switch (context->type) { case GROMIT_PEN: -<<<<<<< HEAD g_printerr ("Pen, "); break; case GROMIT_LINE: g_printerr ("Line, "); break; @@ -108,13 +104,6 @@ void paint_context_print (gchar *name, g_printerr ("Smooth, "); break; case GROMIT_ORTHOGONAL: g_printerr ("Orthogonal, "); break; -======= - g_printerr ("Pen, "); break; - case GROMIT_LINE: - g_printerr ("Line, "); break; - case GROMIT_RECT: - g_printerr ("Rect, "); break; ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) case GROMIT_ERASER: g_printerr ("Eraser, "); break; case GROMIT_RECOLOR: @@ -141,7 +130,6 @@ void paint_context_print (gchar *name, break; } } -<<<<<<< HEAD if (context->type == GROMIT_SMOOTH || context->type == GROMIT_ORTHOGONAL) { g_printerr(" simplify: %u, ", context->simplify); @@ -153,15 +141,16 @@ void paint_context_print (gchar *name, g_printerr(" radius: %u, minlen: %u, maxangle: %u ", context->radius, context->minlen, context->maxangle); } -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) - g_printerr ("color: %s\n", gdk_rgba_to_string(context->paint_color)); + gchar *color_string = gdk_rgba_to_string(context->paint_color); + g_printerr ("color: %s\n", color_string); + g_free(color_string); } void paint_context_free (GromitPaintContext *context) { cairo_destroy(context->paint_ctx); + gdk_rgba_free(context->paint_color); g_free (context); } @@ -707,13 +696,6 @@ void setup_main_app (GromitData *data, int argc, char ** argv) data->undo_buffer_size[i] = 0; data->undo_buffer[i] = NULL; } -<<<<<<< HEAD -======= - - // original state for LINE and RECT tool - cairo_surface_destroy(data->aux_backbuffer); - data->aux_backbuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, data->width, data->height); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) /* EVENTS */ gtk_widget_add_events (data->win, GROMIT_WINDOW_EVENTS); @@ -774,7 +756,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv) gtk_selection_add_target (data->win, GA_CONTROL, GA_UNDO, 8); gtk_selection_add_target (data->win, GA_CONTROL, GA_REDO, 9); gtk_selection_add_target (data->win, GA_CONTROL, GA_LINE, 10); - gtk_selection_add_target (data->win, GA_CONTROL, GA_DEFTOOL, 11); + gtk_selection_add_target (data->win, GA_CONTROL, GA_CHGTOOL, 11); gtk_selection_add_target (data->win, GA_CONTROL, GA_CHGATTR, 12); /* @@ -872,19 +854,11 @@ void setup_main_app (GromitData *data, int argc, char ** argv) data->modified = 0; data->default_pen = -<<<<<<< HEAD paint_context_new (data, GROMIT_PEN, data->red, 7, 0, GROMIT_ARROW_END, 5, 10, 15, 25, 0, 1, G_MAXUINT); data->default_eraser = paint_context_new (data, GROMIT_ERASER, data->red, 75, 0, GROMIT_ARROW_END, 5, 10, 15, 25, 0, 1, G_MAXUINT); -======= - paint_context_new (data, GROMIT_PEN, gdk_rgba_copy(data->red), 7, - 0, GROMIT_ARROW_END, 1, G_MAXUINT); - data->default_eraser = - paint_context_new (data, GROMIT_ERASER, gdk_rgba_copy(data->red), 75, - 0, GROMIT_ARROW_END, 1, G_MAXUINT); ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) gdk_event_handler_set ((GdkEventFunc) main_do_event, data, NULL); gtk_key_snooper_install (snoop_key_press, data); @@ -925,10 +899,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv) GtkWidget* sep1_item = gtk_separator_menu_item_new(); GtkWidget* intro_item = gtk_menu_item_new_with_mnemonic(_("_Introduction")); -<<<<<<< HEAD GtkWidget* edit_config_item = gtk_menu_item_new_with_mnemonic(_("_Edit Config")); -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) GtkWidget* issues_item = gtk_menu_item_new_with_mnemonic(_("_Report Bug / Request Feature")); GtkWidget* support_item = gtk_menu_item_new_with_mnemonic(_("_Support Gromit-MPX")); GtkWidget* about_item = gtk_menu_item_new_with_mnemonic(_("_About")); @@ -951,10 +922,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv) gtk_menu_shell_append (GTK_MENU_SHELL (menu), sep1_item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), intro_item); -<<<<<<< HEAD gtk_menu_shell_append (GTK_MENU_SHELL (menu), edit_config_item); -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) gtk_menu_shell_append (GTK_MENU_SHELL (menu), issues_item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), support_item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), about_item); @@ -1017,12 +985,9 @@ void setup_main_app (GromitData *data, int argc, char ** argv) g_signal_connect(G_OBJECT (intro_item), "activate", G_CALLBACK (on_intro), data); -<<<<<<< HEAD g_signal_connect(G_OBJECT (edit_config_item), "activate", G_CALLBACK (on_edit_config), data); -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) g_signal_connect(G_OBJECT (issues_item), "activate", G_CALLBACK (on_issues), data); @@ -1047,10 +1012,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv) gtk_widget_show (sep1_item); gtk_widget_show (intro_item); -<<<<<<< HEAD gtk_widget_show (edit_config_item); -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) gtk_widget_show (issues_item); gtk_widget_show (support_item); gtk_widget_show (about_item); @@ -1209,7 +1171,7 @@ int main_client (int argc, char **argv, GromitData *data) else { i++; - action = GA_DEFTOOL; + action = GA_CHGTOOL; data->clientdata = argv[i]; } } @@ -1310,7 +1272,7 @@ int main (int argc, char **argv) gtk_selection_owner_set (data->win, GA_DATA, GDK_CURRENT_TIME); gtk_selection_add_target (data->win, GA_DATA, GA_TOGGLEDATA, 1007); gtk_selection_add_target (data->win, GA_DATA, GA_LINEDATA, 1008); - gtk_selection_add_target (data->win, GA_DATA, GA_DEFTOOLDATA, 1009); + gtk_selection_add_target (data->win, GA_DATA, GA_CHGTOOLDATA, 1009); gtk_selection_add_target (data->win, GA_DATA, GA_CHGATTRDATA, 1010); /* Try to get a status message. If there is a response gromit diff --git a/src/main.h b/src/main.h index 79e2afa..138fba7 100644 --- a/src/main.h +++ b/src/main.h @@ -54,13 +54,13 @@ #define GA_RELOAD gdk_atom_intern ("Gromit/reload", FALSE) #define GA_UNDO gdk_atom_intern ("Gromit/undo", FALSE) #define GA_REDO gdk_atom_intern ("Gromit/redo", FALSE) -#define GA_DEFTOOL gdk_atom_intern ("Gromit/deftool", FALSE) +#define GA_CHGTOOL gdk_atom_intern ("Gromit/chgtool", FALSE) #define GA_CHGATTR gdk_atom_intern ("Gromit/chgattr", FALSE) #define GA_DATA gdk_atom_intern ("Gromit/data", FALSE) #define GA_TOGGLEDATA gdk_atom_intern ("Gromit/toggledata", FALSE) #define GA_LINEDATA gdk_atom_intern ("Gromit/linedata", FALSE) -#define GA_DEFTOOLDATA gdk_atom_intern ("Gromit/deftooldata", FALSE) +#define GA_CHGTOOLDATA gdk_atom_intern ("Gromit/chgtooldata", FALSE) #define GA_CHGATTRDATA gdk_atom_intern ("Gromit/chgattrdata", FALSE) #define GROMIT_MAX_UNDO 100 @@ -70,11 +70,8 @@ typedef enum GROMIT_PEN, GROMIT_LINE, GROMIT_RECT, -<<<<<<< HEAD GROMIT_SMOOTH, GROMIT_ORTHOGONAL, -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) GROMIT_ERASER, GROMIT_RECOLOR } GromitPaintType; @@ -203,10 +200,7 @@ void clear_screen (GromitData *data); GromitPaintContext *paint_context_new (GromitData *data, GromitPaintType type, GdkRGBA *fg_color, guint width, guint arrowsize, GromitArrowType arrowtype, -<<<<<<< HEAD guint simpilfy, guint radius, guint maxangle, guint minlen, guint snapdist, -======= ->>>>>>> 5385d7b (config, callbacks: add option to change tool definitions and individual tool attributes) guint minwidth, guint maxwidth); void paint_context_free (GromitPaintContext *context);