-
-
Notifications
You must be signed in to change notification settings - Fork 103
Add option to change tools on the command line #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pascal-niklaus
wants to merge
7
commits into
bk138:master
Choose a base branch
from
pascal-niklaus:devel_change_tool
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75db865
first version of --deftool
pascal-niklaus 0c06510
duplicated tool parser code moved to separate functions
pascal-niklaus f446416
tool change
pascal-niklaus e1ceeec
added cairo_destroy
pascal-niklaus 074531a
config, callbacks: add option to change tool definitions and individu…
pascal-niklaus 048ec6a
parser.[ch] removed from CMakeLists.txt
pascal-niklaus c96bd53
README, config, main, callbacks: added tool options -A, -T, moved com…
pascal-niklaus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,10 +141,9 @@ void on_monitors_changed ( GdkScreen *screen, | |
|
|
||
| parse_config(data); // also calls paint_context_new() :-( | ||
|
|
||
|
|
||
| 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, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still have the allocated GdkRGBA here which should be freed.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pascal-niklaus what do you think about those? |
||
| 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); | ||
|
|
||
| if(!data->composited) // set shape | ||
|
|
@@ -211,7 +210,10 @@ void on_clientapp_selection_get (GtkWidget *widget, | |
| g_printerr("DEBUG: clientapp received request.\n"); | ||
|
|
||
|
|
||
| if (gtk_selection_data_get_target(selection_data) == GA_TOGGLEDATA || gtk_selection_data_get_target(selection_data) == GA_LINEDATA) | ||
| 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_CHGTOOLDATA || | ||
| gtk_selection_data_get_target(selection_data) == GA_CHGATTRDATA) | ||
| { | ||
| ans = data->clientdata; | ||
| } | ||
|
|
@@ -398,9 +400,8 @@ gboolean on_motion (GtkWidget *win, | |
| } | ||
| if (type == GROMIT_LINE) | ||
| { | ||
| GromitArrowType atype = devdata->cur_context->arrow_type; | ||
| 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) | ||
bk138 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| GromitArrowType atype = devdata->cur_context->arrow_type; | ||
| gint width = devdata->cur_context->arrowsize * devdata->cur_context->width / 2; | ||
|
|
@@ -528,7 +529,7 @@ void on_mainapp_selection_get (GtkWidget *widget, | |
| gpointer user_data) | ||
| { | ||
| GromitData *data = (GromitData *) user_data; | ||
|
|
||
| gchar *uri = "OK"; | ||
| GdkAtom action = gtk_selection_data_get_target(selection_data); | ||
|
|
||
|
|
@@ -558,10 +559,20 @@ void on_mainapp_selection_get (GtkWidget *widget, | |
| undo_drawing (data); | ||
| else if (action == GA_REDO) | ||
| redo_drawing (data); | ||
| else if (action == GA_CHGTOOL) | ||
| { | ||
| gtk_selection_convert(data->win, GA_DATA, GA_CHGTOOLDATA, time); | ||
| gtk_main(); | ||
| } | ||
| else if (action == GA_CHGATTR) | ||
| { | ||
| gtk_selection_convert(data->win, GA_DATA, GA_CHGATTRDATA, time); | ||
| gtk_main(); | ||
| } | ||
| else | ||
| uri = "NOK"; | ||
|
|
||
|
|
||
| gtk_selection_data_set (selection_data, | ||
| gtk_selection_data_get_target(selection_data), | ||
| 8, (guchar*)uri, strlen (uri)); | ||
|
|
@@ -574,6 +585,7 @@ void on_mainapp_selection_received (GtkWidget *widget, | |
| gpointer user_data) | ||
| { | ||
| GromitData *data = (GromitData *) user_data; | ||
| gchar *name = NULL; | ||
|
|
||
| if(gtk_selection_data_get_length(selection_data) < 0) | ||
| { | ||
|
|
@@ -585,35 +597,35 @@ void on_mainapp_selection_received (GtkWidget *widget, | |
| if(gtk_selection_data_get_target(selection_data) == GA_TOGGLEDATA ) | ||
| { | ||
| intptr_t dev_nr = strtoull((gchar*)gtk_selection_data_get_data(selection_data), NULL, 10); | ||
|
|
||
| if(data->debug) | ||
| g_printerr("DEBUG: mainapp got toggle id '%ld' back from client.\n", (long)dev_nr); | ||
|
|
||
| if(dev_nr < 0) | ||
| toggle_grab(data, NULL); /* toggle all */ | ||
| else | ||
| else | ||
| { | ||
| /* find dev numbered dev_nr */ | ||
| GHashTableIter it; | ||
| gpointer value; | ||
| GromitDeviceData* devdata = NULL; | ||
| GromitDeviceData* devdata = NULL; | ||
| g_hash_table_iter_init (&it, data->devdatatable); | ||
| while (g_hash_table_iter_next (&it, NULL, &value)) | ||
| while (g_hash_table_iter_next (&it, NULL, &value)) | ||
| { | ||
| devdata = value; | ||
| if(devdata->index == dev_nr) | ||
| break; | ||
| else | ||
| devdata = NULL; | ||
| } | ||
|
|
||
| if(devdata) | ||
| toggle_grab(data, devdata->device); | ||
| else | ||
| g_printerr("ERROR: No device at index %ld.\n", (long)dev_nr); | ||
| } | ||
| } | ||
| else if (gtk_selection_data_get_target(selection_data) == GA_LINEDATA) | ||
| else if (gtk_selection_data_get_target(selection_data) == GA_LINEDATA) | ||
| { | ||
|
|
||
| gchar** line_args = g_strsplit((gchar*)gtk_selection_data_get_data(selection_data), " ", 6); | ||
|
|
@@ -624,7 +636,7 @@ void on_mainapp_selection_received (GtkWidget *widget, | |
| gchar* hex_code = line_args[4]; | ||
| int thickness = atoi(line_args[5]); | ||
|
|
||
| if(data->debug) | ||
| if(data->debug) | ||
| { | ||
| g_printerr("DEBUG: mainapp got line data back from client:\n"); | ||
| g_printerr("startX startY endX endY: %d %d %d %d\n", startX, startY, endX, endY); | ||
|
|
@@ -662,14 +674,136 @@ void on_mainapp_selection_received (GtkWidget *widget, | |
| cairo_stroke(line_ctx->paint_ctx); | ||
|
|
||
| data->modified = 1; | ||
| gdk_window_invalidate_rect(gtk_widget_get_window(data->win), &rect, 0); | ||
| gdk_window_invalidate_rect(gtk_widget_get_window(data->win), &rect, 0); | ||
| data->painted = 1; | ||
|
|
||
| g_free(line_ctx); | ||
| g_free (color); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| GdkAtom atom = gtk_selection_data_get_target(selection_data); | ||
| 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); | ||
|
|
||
| GScanner *scanner = g_scanner_new(NULL); | ||
| scanner_init(scanner); | ||
| g_scanner_input_text(scanner, a, strlen(a)); | ||
|
|
||
| GTokenType token = g_scanner_get_next_token (scanner); | ||
|
|
||
| GromitPaintContext style; | ||
| style.paint_color = NULL; | ||
|
|
||
| if (token != G_TOKEN_STRING || ! (name = parse_name (scanner))) | ||
| { | ||
| g_printerr("Could not parse tool in expression '%s'!\n", a); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| GromitPaintContext *context = g_hash_table_lookup(data->tool_config, name); | ||
| if (context == NULL) | ||
| { | ||
| g_printerr("Cannot change tool '%s' because it does not exist...\n", name); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| if (atom == GA_CHGATTRDATA) | ||
| { | ||
| if (g_scanner_cur_token(scanner) != G_TOKEN_EQUAL_SIGN) | ||
| { | ||
| g_printerr("Expected equal sign after tool name...\n"); | ||
| goto cleanup; | ||
| } | ||
| token = g_scanner_get_next_token(scanner); | ||
| if (token == G_TOKEN_SYMBOL) | ||
| { | ||
| context->type = (GromitPaintType) scanner->value.v_symbol; | ||
| token = g_scanner_get_next_token (scanner); | ||
| } | ||
| if (token == G_TOKEN_LEFT_PAREN) | ||
| { | ||
| style.paint_color = g_malloc(sizeof(GdkRGBA)); | ||
| *style.paint_color = *data->red; | ||
| scanner->scope_id = 2; | ||
| while (token != G_TOKEN_RIGHT_PAREN) | ||
| { | ||
| token = g_scanner_get_next_token(scanner); | ||
| if (token == G_TOKEN_SYMBOL) | ||
| { | ||
| switch (parse_attribute(scanner, &style)) | ||
| { | ||
| case SYM_SIZE: | ||
| context->width = style.width; | ||
| cairo_set_line_width(context->paint_ctx, style.width); | ||
| break; | ||
| case SYM_COLOR: | ||
| *context->paint_color = *style.paint_color; | ||
| cairo_set_source_rgba(context->paint_ctx, | ||
| style.paint_color->red, | ||
| style.paint_color->green, | ||
| style.paint_color->blue, | ||
| style.paint_color->alpha); | ||
| break; | ||
| case SYM_ARROWSIZE: | ||
| context->arrowsize = style.arrowsize; | ||
| break; | ||
| case SYM_ARROWTYPE: | ||
| context->arrow_type = style.arrow_type; | ||
| break; | ||
| case SYM_MINSIZE: | ||
| context->minwidth = style.minwidth; | ||
| break; | ||
| case SYM_MAXSIZE: | ||
| context->maxwidth = style.maxwidth; | ||
| break; | ||
| case SYM_ERROR: | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if (g_scanner_get_next_token(scanner) != G_TOKEN_EOF) | ||
| g_printerr("WARNING: skipping extra content after ')' !\n"); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (!parse_tool(data, scanner, &style)) goto cleanup; | ||
| if (g_scanner_cur_token(scanner) != G_TOKEN_LEFT_PAREN) goto cleanup; | ||
| if (! parse_style(scanner, &style)) goto cleanup; | ||
| if (g_scanner_cur_token(scanner) != G_TOKEN_EOF) goto cleanup; | ||
|
|
||
| context->type = style.type; | ||
| *context->paint_color = *style.paint_color; | ||
| context->width = style.width; | ||
| context->arrowsize = style.arrowsize; | ||
| context->arrow_type = style.arrow_type; | ||
| context->minwidth = style.minwidth; | ||
| context->maxwidth = style.maxwidth; | ||
|
|
||
| cairo_set_source_rgba(context->paint_ctx, | ||
| style.paint_color->red, | ||
| style.paint_color->green, | ||
| style.paint_color->blue, | ||
| style.paint_color->alpha); | ||
| cairo_set_line_width(context->paint_ctx, style.width); | ||
| } | ||
| if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF) | ||
| { | ||
| g_printerr("WARNING: skipping extra content tool definition!\n"); | ||
| } | ||
|
|
||
| cleanup: | ||
| if (style.paint_color) g_free(style.paint_color); | ||
| g_scanner_destroy (scanner); | ||
| } // if (tool change) ... | ||
| } | ||
| } | ||
|
|
||
|
|
||
| if (name) g_free(name); | ||
|
|
||
| gtk_main_quit (); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.