summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2017-05-30 11:57:06 -0700
committerAnders Broman <a.broman58@gmail.com>2017-06-01 08:07:05 +0000
commit6a37b542e4f1c6de7646d7ebe7fdfa2825fa0453 (patch)
tree4692beb0f863a8718a473fe8d53a6ce9cd266124
parent9719bac5ee8df89cefd4f750acdc5ef75cc75e63 (diff)
downloadwireshark-6a37b542e4f1c6de7646d7ebe7fdfa2825fa0453.tar.gz
Qt+prefs: Add a dark theme check and default colors.
Add prefs_set_gui_theme_is_dark and call it in the WiresharkApplication constructor. Add a set of dark syntax color defaults. We could alternatively add a preference for the syntax foreground color, but that would imply adding a preference for the background color as well. Bug: 11131 Bug: 13738 Change-Id: Iefe135ed04e63372ed434c5b9759647c9f4046e3 Reviewed-on: https://code.wireshark.org/review/21827 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/prefs.c40
-rw-r--r--epan/prefs.h7
-rw-r--r--ui/qt/wireshark_application.cpp4
3 files changed, 40 insertions, 11 deletions
diff --git a/epan/prefs.c b/epan/prefs.c
index 35ff3fa2a2..0c53992d4a 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -78,6 +78,7 @@ static void try_convert_to_custom_column(gpointer *el_data);
static gboolean prefs_initialized = FALSE;
static gchar *gpf_path = NULL;
static gchar *cols_hidden_list = NULL;
+static gboolean gui_theme_is_dark = FALSE;
/*
* XXX - variables to allow us to attempt to interpret the first
@@ -413,6 +414,11 @@ prefs_cleanup(void)
gpf_path = NULL;
}
+void prefs_set_gui_theme_is_dark(gboolean is_dark)
+{
+ gui_theme_is_dark = is_dark;
+}
+
/*
* Register a module that will have preferences.
* Specify the module under which to register it or NULL to register it
@@ -3959,15 +3965,31 @@ pre_init_prefs(void)
prefs.st_server_bg.red = 60909;
prefs.st_server_bg.green = 60909;
prefs.st_server_bg.blue = 64507;
- prefs.gui_text_valid.red = 0xAFFF; /* light green */
- prefs.gui_text_valid.green = 0xFFFF;
- prefs.gui_text_valid.blue = 0xAFFF;
- prefs.gui_text_invalid.red = 0xFFFF; /* light red */
- prefs.gui_text_invalid.green = 0xAFFF;
- prefs.gui_text_invalid.blue = 0xAFFF;
- prefs.gui_text_deprecated.red = 0xFFFF; /* light yellow */
- prefs.gui_text_deprecated.green = 0xFFFF;
- prefs.gui_text_deprecated.blue = 0xAFFF;
+
+ if (gui_theme_is_dark) {
+ // Green, red and yellow with HSV V = 84
+ prefs.gui_text_valid.red = 0x0000; /* dark green */
+ prefs.gui_text_valid.green = 0x66ff;
+ prefs.gui_text_valid.blue = 0x0000;
+ prefs.gui_text_invalid.red = 0x66FF; /* dark red */
+ prefs.gui_text_invalid.green = 0x0000;
+ prefs.gui_text_invalid.blue = 0x0000;
+ prefs.gui_text_deprecated.red = 0x66FF; /* dark yellow / olive */
+ prefs.gui_text_deprecated.green = 0x66FF;
+ prefs.gui_text_deprecated.blue = 0x0000;
+ } else {
+ // Green, red and yellow with HSV V = 20
+ prefs.gui_text_valid.red = 0xAFFF; /* light green */
+ prefs.gui_text_valid.green = 0xFFFF;
+ prefs.gui_text_valid.blue = 0xAFFF;
+ prefs.gui_text_invalid.red = 0xFFFF; /* light red */
+ prefs.gui_text_invalid.green = 0xAFFF;
+ prefs.gui_text_invalid.blue = 0xAFFF;
+ prefs.gui_text_deprecated.red = 0xFFFF; /* light yellow */
+ prefs.gui_text_deprecated.green = 0xFFFF;
+ prefs.gui_text_deprecated.blue = 0xAFFF;
+ }
+
prefs.gui_geometry_save_position = TRUE;
prefs.gui_geometry_save_size = TRUE;
prefs.gui_geometry_save_maximized= TRUE;
diff --git a/epan/prefs.h b/epan/prefs.h
index e757a25533..e68b187d11 100644
--- a/epan/prefs.h
+++ b/epan/prefs.h
@@ -151,7 +151,7 @@ typedef struct _e_prefs {
gint num_cols;
color_t st_client_fg, st_client_bg, st_server_fg, st_server_bg;
color_t gui_text_valid, gui_text_invalid, gui_text_deprecated;
- gboolean gui_altern_colors;
+ gboolean gui_altern_colors; /* GTK only */
gboolean gui_expert_composite_eyecandy;
gboolean filter_toolbar_show_in_statusbar;
gint gui_ptree_line_style;
@@ -170,7 +170,7 @@ typedef struct _e_prefs {
gboolean gui_geometry_save_position;
gboolean gui_geometry_save_size;
gboolean gui_geometry_save_maximized;
- gboolean gui_macosx_style;
+ gboolean gui_macosx_style; /* GTK only */
console_open_e gui_console_open;
guint gui_recent_df_entries_max;
guint gui_recent_files_count_max;
@@ -269,6 +269,9 @@ WS_DLL_PUBLIC void prefs_reset(void);
/** Frees memory used by proto routines. Called at program shutdown */
void prefs_cleanup(void);
+/** Provide a hint about the darkness of the current UI theme so that we can adjust colors when needed */
+WS_DLL_PUBLIC void prefs_set_gui_theme_is_dark(gboolean is_dark);
+
/*
* Register that a protocol has preferences.
*/
diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp
index 93fb1ec675..8414cb4502 100644
--- a/ui/qt/wireshark_application.cpp
+++ b/ui/qt/wireshark_application.cpp
@@ -833,6 +833,10 @@ WiresharkApplication::WiresharkApplication(int &argc, char **argv) :
#endif
qApp->setStyleSheet(app_style_sheet);
+ // If our window text is lighter than the window background, assume the theme is dark.
+ QPalette gui_pal = QGuiApplication::palette();
+ prefs_set_gui_theme_is_dark(gui_pal.windowText().color().value() > gui_pal.window().color().value());
+
#ifdef HAVE_SOFTWARE_UPDATE
connect(this, SIGNAL(softwareUpdateQuit()), this, SLOT(quit()), Qt::QueuedConnection);
#endif