From 7306501cdbb96eb047d76d183d16cbd152b2c524 Mon Sep 17 00:00:00 2001 From: Rakksor Date: Wed, 25 Jan 2017 06:25:32 +0100 Subject: [PATCH 1/4] make message window themable --- src/highlighting.c | 28 +++++++++++++++++++++++++++- src/highlighting.h | 4 ++++ src/msgwindow.c | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/highlighting.c b/src/highlighting.c index 5dd0e0f435..bbb6359ee4 100644 --- a/src/highlighting.c +++ b/src/highlighting.c @@ -60,6 +60,10 @@ static gchar *whitespace_chars = NULL; +gint msg_context = 0x880000; +gint msg_default = 0x000000; +gint msg_error = 0xff0000; +gint msg_message = 0x0000cc; typedef struct { @@ -456,7 +460,29 @@ static void add_named_style(GKeyFile *config, const gchar *key) GeanyLexerStyle *style = g_new0(GeanyLexerStyle, 1); parse_keyfile_style(config, list, &gsd_default, style); - g_hash_table_insert(named_style_hash, g_strdup(key), style); + + if (!strcmp(key, "msg_context")) + { + msg_context = style->foreground; + g_free(style); + } + else if (!strcmp(key, "msg_default")) + { + msg_default = style->foreground; + g_free(style); + } + else if (!strcmp(key, "msg_error")) + { + msg_error = style->foreground; + g_free(style); + } + else if (!strcmp(key, "msg_message")) + { + msg_message = style->foreground; + g_free(style); + } + else + g_hash_table_insert(named_style_hash, g_strdup(key), style); } g_strfreev(list); } diff --git a/src/highlighting.h b/src/highlighting.h index c1190516f4..4aa3cd6aa7 100644 --- a/src/highlighting.h +++ b/src/highlighting.h @@ -45,6 +45,10 @@ typedef struct GeanyLexerStyle } GeanyLexerStyle; +extern gint msg_context; +extern gint msg_default; +extern gint msg_error; +extern gint msg_message; const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id); diff --git a/src/msgwindow.c b/src/msgwindow.c index 3a5e2c4000..9a242c2d1f 100644 --- a/src/msgwindow.c +++ b/src/msgwindow.c @@ -37,6 +37,7 @@ #include "document.h" #include "callbacks.h" #include "filetypes.h" +#include "highlighting.h" #include "keybindings.h" #include "main.h" #include "navqueue.h" @@ -262,21 +263,30 @@ static void prepare_compiler_tree_view(void) /*g_signal_connect(selection, "changed", G_CALLBACK(on_msg_tree_selection_changed), NULL);*/ } - -static const GdkColor color_error = {0, 65535, 0, 0}; - -static const GdkColor *get_color(gint msg_color) +GdkColor get_color(gint msg_color) { - static const GdkColor dark_red = {0, 65535 / 2, 0, 0}; - static const GdkColor blue = {0, 0, 0, 0xD000}; /* not too bright ;-) */ - + gint color; switch (msg_color) { - case COLOR_RED: return &color_error; - case COLOR_DARK_RED: return &dark_red; - case COLOR_BLUE: return &blue; - default: return NULL; + case COLOR_RED: + color = msg_error; + break; + case COLOR_DARK_RED: + color = msg_context; + break; + case COLOR_BLUE: + color = msg_message; + break; + default: + color = msg_default; } + + gint red = color & 0xFF; + gint green = (color >> 8) & 0xFF; + gint blue = (color >> 16) & 0xFF; + GdkColor gdk_color = {0, red * 255, green * 255, blue * 255}; + + return gdk_color; } @@ -304,7 +314,7 @@ void msgwin_compiler_add(gint msg_color, const gchar *format, ...) void msgwin_compiler_add_string(gint msg_color, const gchar *msg) { GtkTreeIter iter; - const GdkColor *color = get_color(msg_color); + const GdkColor color = get_color(msg_color); gchar *utf8_msg; if (! g_utf8_validate(msg, -1, NULL)) @@ -314,7 +324,7 @@ void msgwin_compiler_add_string(gint msg_color, const gchar *msg) gtk_list_store_append(msgwindow.store_compiler, &iter); gtk_list_store_set(msgwindow.store_compiler, &iter, - COMPILER_COL_COLOR, color, COMPILER_COL_STRING, utf8_msg, -1); + COMPILER_COL_COLOR, &color, COMPILER_COL_STRING, utf8_msg, -1); if (ui_prefs.msgwindow_visible && interface_prefs.compiler_tab_autoscroll) { @@ -380,7 +390,7 @@ void msgwin_msg_add(gint msg_color, gint line, GeanyDocument *doc, const gchar * void msgwin_msg_add_string(gint msg_color, gint line, GeanyDocument *doc, const gchar *string) { GtkTreeIter iter; - const GdkColor *color = get_color(msg_color); + const GdkColor color = get_color(msg_color); gchar *tmp; gsize len; gchar *utf8_msg; @@ -405,7 +415,7 @@ void msgwin_msg_add_string(gint msg_color, gint line, GeanyDocument *doc, const gtk_list_store_append(msgwindow.store_msg, &iter); gtk_list_store_set(msgwindow.store_msg, &iter, MSG_COL_LINE, line, MSG_COL_DOC_ID, doc ? doc->id : 0, MSG_COL_COLOR, - color, MSG_COL_STRING, utf8_msg, -1); + &color, MSG_COL_STRING, utf8_msg, -1); g_free(tmp); if (utf8_msg != tmp) @@ -730,7 +740,8 @@ gboolean msgwin_goto_compiler_file_line(gboolean focus_editor) { /* if the item is not coloured red, it's not an error line */ gtk_tree_model_get(model, &iter, COMPILER_COL_COLOR, &color, -1); - if (color == NULL || ! gdk_color_equal(color, &color_error)) + const GdkColor error = get_color(COLOR_RED); + if (color == NULL || ! gdk_color_equal(color, &error)) { if (color != NULL) gdk_color_free(color); From 50b689fd8ac96ca49aa4f3b1aa32e39265fd0363 Mon Sep 17 00:00:00 2001 From: Rakksor Date: Wed, 25 Jan 2017 06:59:29 +0100 Subject: [PATCH 2/4] added documentation for message window theme options --- doc/geany.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/geany.txt b/doc/geany.txt index 670b540f1b..403245db07 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -4597,6 +4597,33 @@ indicator_error *Example:* ``indicator_error=0xff0000`` +msg_default + The default foreground color in the compiler tab of the message window. + + Only the first argument (foreground color) is used. + + *Example:* ``msg_default=0x000000`` + +msg_error + The foreground color of compiler errors in the message window. + + Only the first argument (foreground color) is used. + + *Example:* ``msg_error=0xff0000`` + +msg_context + The foreground color of the surrounding lines of compiler errors. + + Only the first argument (foreground color) is used. + + *Example:* ``msg_context=0x880000`` + +msg_message + The foreground color of messages and commands in the message window. + + Only the first argument (foreground color) is used. + + *Example:* ``msg_message=0x0000cc`` [settings] section `````````````````` From 33a8cc906caf6224a2c7820747cd956d8902bfec Mon Sep 17 00:00:00 2001 From: Rakksor Date: Sat, 28 Jan 2017 00:11:05 +0100 Subject: [PATCH 3/4] Make compiler messages use GTK+ theme --- data/geany.css | 11 +++++++ data/geany.gtkrc | 17 ++++++++++ src/highlighting.c | 28 +--------------- src/highlighting.h | 4 --- src/msgwindow.c | 80 ++++++++++++++++++++++++++++++---------------- 5 files changed, 82 insertions(+), 58 deletions(-) diff --git a/data/geany.css b/data/geany.css index 1c1f4cf986..f22a8f9734 100644 --- a/data/geany.css +++ b/data/geany.css @@ -36,6 +36,17 @@ color: #007f00; } +/* compiler message colors */ +#geany-compiler-error { + color: #ff0000; +} +#geany-compiler-context { + color: #880000; +} +#geany-compiler-message { + color: #0000D0; +} + /* red "Terminal" label when terminal dirty */ #geany-terminal-dirty { color: #ff0000; diff --git a/data/geany.gtkrc b/data/geany.gtkrc index 28a07812ad..2fe55f80ed 100644 --- a/data/geany.gtkrc +++ b/data/geany.gtkrc @@ -50,5 +50,22 @@ widget "*.geany-document-status-changed" style "geany-document-status-changed-st widget "*.geany-document-status-disk-changed" style "geany-document-status-disk-changed-style" widget "*.geany-document-status-readonly" style "geany-document-status-readonly-style" +# compiler message colors +style "geany-compiler-error-style" { + fg[NORMAL] = "#ffff00000000" + fg[ACTIVE] = "#ffff00000000" +} +style "geany-compiler-context-style" { + fg[NORMAL] = "#888800000000" + fg[ACTIVE] = "#888800000000" +} +style "geany-compiler-message-style" { + fg[NORMAL] = "#00000000D000" + fg[ACTIVE] = "#00000000D000" +} +widget "*.geany-compiler-error" style "geany-compiler-error-style" +widget "*.geany-compiler-context" style "geany-compiler-context-style" +widget "*.geany-compiler-message" style "geany-compiler-message-style" + # red "Terminal" label when terminal dirty widget "*.geany-terminal-dirty" style "geany-document-status-changed-style" diff --git a/src/highlighting.c b/src/highlighting.c index bbb6359ee4..5dd0e0f435 100644 --- a/src/highlighting.c +++ b/src/highlighting.c @@ -60,10 +60,6 @@ static gchar *whitespace_chars = NULL; -gint msg_context = 0x880000; -gint msg_default = 0x000000; -gint msg_error = 0xff0000; -gint msg_message = 0x0000cc; typedef struct { @@ -460,29 +456,7 @@ static void add_named_style(GKeyFile *config, const gchar *key) GeanyLexerStyle *style = g_new0(GeanyLexerStyle, 1); parse_keyfile_style(config, list, &gsd_default, style); - - if (!strcmp(key, "msg_context")) - { - msg_context = style->foreground; - g_free(style); - } - else if (!strcmp(key, "msg_default")) - { - msg_default = style->foreground; - g_free(style); - } - else if (!strcmp(key, "msg_error")) - { - msg_error = style->foreground; - g_free(style); - } - else if (!strcmp(key, "msg_message")) - { - msg_message = style->foreground; - g_free(style); - } - else - g_hash_table_insert(named_style_hash, g_strdup(key), style); + g_hash_table_insert(named_style_hash, g_strdup(key), style); } g_strfreev(list); } diff --git a/src/highlighting.h b/src/highlighting.h index 4aa3cd6aa7..c1190516f4 100644 --- a/src/highlighting.h +++ b/src/highlighting.h @@ -45,10 +45,6 @@ typedef struct GeanyLexerStyle } GeanyLexerStyle; -extern gint msg_context; -extern gint msg_default; -extern gint msg_error; -extern gint msg_message; const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id); diff --git a/src/msgwindow.c b/src/msgwindow.c index 9a242c2d1f..5d7395de35 100644 --- a/src/msgwindow.c +++ b/src/msgwindow.c @@ -37,7 +37,6 @@ #include "document.h" #include "callbacks.h" #include "filetypes.h" -#include "highlighting.h" #include "keybindings.h" #include "main.h" #include "navqueue.h" @@ -84,6 +83,11 @@ enum }; +static GdkColor color_error = {0, 65535, 0, 0}; +static GdkColor color_context = {0, 65535 / 2, 0, 0}; +static GdkColor color_message = {0, 0, 0, 0xD000}; + + static void prepare_msg_tree_view(void); static void prepare_status_tree_view(void); static void prepare_compiler_tree_view(void); @@ -113,6 +117,40 @@ void msgwin_set_messages_dir(const gchar *messages_dir) } +GdkColor load_color(gchar *color_name) { + GdkColor color; + +#if GTK_CHECK_VERSION(3, 0, 0) + GdkRGBA rgba_color; + GtkWidgetPath *path = gtk_widget_path_new(); + GtkStyleContext *ctx = gtk_style_context_new(); + + gtk_widget_path_append_type(path, GTK_TYPE_WINDOW); + gtk_widget_path_iter_set_name(path, -1, color_name); + gtk_style_context_set_screen(ctx, gdk_screen_get_default()); + gtk_style_context_set_path(ctx, path); + gtk_style_context_get_color(ctx, gtk_style_context_get_state(ctx), &rgba_color); + + color.red = 0xffff * rgba_color.red; + color.green = 0xffff * rgba_color.green; + color.blue = 0xffff * rgba_color.blue; + + gtk_widget_path_unref(path); + g_object_unref(ctx); +#else + gchar *path = g_strconcat("*.", color_name, NULL); + + GtkSettings *settings = gtk_settings_get_default(); + GtkStyle *style = gtk_rc_get_style_by_paths(settings, path, NULL, GTK_TYPE_WIDGET); + color = style->fg[GTK_STATE_NORMAL]; + + g_free(path); +#endif + + return color; +} + + void msgwin_init(void) { msgwindow.notebook = ui_lookup_widget(main_widgets.window, "notebook_info"); @@ -131,6 +169,10 @@ void msgwin_init(void) ui_widget_modify_font_from_string(msgwindow.scribble, interface_prefs.msgwin_font); g_signal_connect(msgwindow.scribble, "populate-popup", G_CALLBACK(on_scribble_populate), NULL); + + color_error = load_color("geany-compiler-error"); + color_context = load_color("geany-compiler-context"); + color_message = load_color("geany-compiler-message"); } @@ -263,30 +305,15 @@ static void prepare_compiler_tree_view(void) /*g_signal_connect(selection, "changed", G_CALLBACK(on_msg_tree_selection_changed), NULL);*/ } -GdkColor get_color(gint msg_color) +static const GdkColor *get_color(gint msg_color) { - gint color; switch (msg_color) { - case COLOR_RED: - color = msg_error; - break; - case COLOR_DARK_RED: - color = msg_context; - break; - case COLOR_BLUE: - color = msg_message; - break; - default: - color = msg_default; + case COLOR_RED: return &color_error; + case COLOR_DARK_RED: return &color_context; + case COLOR_BLUE: return &color_message; + default: return NULL; } - - gint red = color & 0xFF; - gint green = (color >> 8) & 0xFF; - gint blue = (color >> 16) & 0xFF; - GdkColor gdk_color = {0, red * 255, green * 255, blue * 255}; - - return gdk_color; } @@ -314,7 +341,7 @@ void msgwin_compiler_add(gint msg_color, const gchar *format, ...) void msgwin_compiler_add_string(gint msg_color, const gchar *msg) { GtkTreeIter iter; - const GdkColor color = get_color(msg_color); + const GdkColor *color = get_color(msg_color); gchar *utf8_msg; if (! g_utf8_validate(msg, -1, NULL)) @@ -324,7 +351,7 @@ void msgwin_compiler_add_string(gint msg_color, const gchar *msg) gtk_list_store_append(msgwindow.store_compiler, &iter); gtk_list_store_set(msgwindow.store_compiler, &iter, - COMPILER_COL_COLOR, &color, COMPILER_COL_STRING, utf8_msg, -1); + COMPILER_COL_COLOR, color, COMPILER_COL_STRING, utf8_msg, -1); if (ui_prefs.msgwindow_visible && interface_prefs.compiler_tab_autoscroll) { @@ -390,7 +417,7 @@ void msgwin_msg_add(gint msg_color, gint line, GeanyDocument *doc, const gchar * void msgwin_msg_add_string(gint msg_color, gint line, GeanyDocument *doc, const gchar *string) { GtkTreeIter iter; - const GdkColor color = get_color(msg_color); + const GdkColor *color = get_color(msg_color); gchar *tmp; gsize len; gchar *utf8_msg; @@ -415,7 +442,7 @@ void msgwin_msg_add_string(gint msg_color, gint line, GeanyDocument *doc, const gtk_list_store_append(msgwindow.store_msg, &iter); gtk_list_store_set(msgwindow.store_msg, &iter, MSG_COL_LINE, line, MSG_COL_DOC_ID, doc ? doc->id : 0, MSG_COL_COLOR, - &color, MSG_COL_STRING, utf8_msg, -1); + color, MSG_COL_STRING, utf8_msg, -1); g_free(tmp); if (utf8_msg != tmp) @@ -740,8 +767,7 @@ gboolean msgwin_goto_compiler_file_line(gboolean focus_editor) { /* if the item is not coloured red, it's not an error line */ gtk_tree_model_get(model, &iter, COMPILER_COL_COLOR, &color, -1); - const GdkColor error = get_color(COLOR_RED); - if (color == NULL || ! gdk_color_equal(color, &error)) + if (color == NULL || ! gdk_color_equal(color, &color_error)) { if (color != NULL) gdk_color_free(color); From ced8595fa2e79df0df530310e58436970bc5b75e Mon Sep 17 00:00:00 2001 From: Rakksor Date: Sat, 28 Jan 2017 00:36:36 +0100 Subject: [PATCH 4/4] Remove now invalid documentation --- doc/geany.txt | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/doc/geany.txt b/doc/geany.txt index 403245db07..670b540f1b 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -4597,33 +4597,6 @@ indicator_error *Example:* ``indicator_error=0xff0000`` -msg_default - The default foreground color in the compiler tab of the message window. - - Only the first argument (foreground color) is used. - - *Example:* ``msg_default=0x000000`` - -msg_error - The foreground color of compiler errors in the message window. - - Only the first argument (foreground color) is used. - - *Example:* ``msg_error=0xff0000`` - -msg_context - The foreground color of the surrounding lines of compiler errors. - - Only the first argument (foreground color) is used. - - *Example:* ``msg_context=0x880000`` - -msg_message - The foreground color of messages and commands in the message window. - - Only the first argument (foreground color) is used. - - *Example:* ``msg_message=0x0000cc`` [settings] section ``````````````````