-
Notifications
You must be signed in to change notification settings - Fork 18
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
Port to GTK3/Xfce 4.16 #63
Merged
Merged
Changes from all commits
Commits
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 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 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 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 |
---|---|---|
|
@@ -58,14 +58,14 @@ config_dialog_closed(GtkWidget *dialog, int response, ConfigDialogClosedParam *p | |
/* Function Implementations */ | ||
|
||
guint32 | ||
serialize_gdkcolor(GdkColor *gdkcolor) | ||
serialize_gdkrgba(GdkRGBA *gdkrgba) | ||
{ | ||
guint32 color = 0; | ||
|
||
// truncate the GdkColor components to 8 bit | ||
guint16 red_component = gdkcolor->red >> 8; | ||
guint16 green_component = gdkcolor->green >> 8; | ||
guint16 blue_component = gdkcolor->blue >> 8; | ||
// convert the GdkRGBA components to 8 bit ints | ||
guint8 red_component = gdkrgba->red * 255; | ||
guint8 green_component = gdkrgba->green * 255; | ||
guint8 blue_component = gdkrgba->blue * 255; | ||
|
||
// shift and add the color components | ||
color += ((guint32) red_component) << 16; | ||
|
@@ -75,22 +75,23 @@ serialize_gdkcolor(GdkColor *gdkcolor) | |
return color; | ||
} | ||
|
||
GdkColor * | ||
unserialize_gdkcolor(guint32 color) | ||
GdkRGBA * | ||
unserialize_gdkrgba(guint32 color) | ||
{ | ||
GdkColor *gdkcolor = g_new0(GdkColor, 1); | ||
GdkRGBA *gdkrgba = g_new0(GdkRGBA, 1); | ||
|
||
// Mask and shift the color components | ||
guint16 red_component = (guint16) ((color & 0xff0000) >> 16); | ||
guint16 green_component = (guint16) ((color & 0x00ff00) >> 8); | ||
guint16 blue_component = (guint16) ((color & 0x0000ff)); | ||
guint8 red_component = (color & 0xff0000) >> 16; | ||
guint8 green_component = (color & 0x00ff00) >> 8; | ||
guint8 blue_component = (color & 0x0000ff); | ||
|
||
// expand the GdkColor components to 16 bit | ||
gdkcolor->red = red_component << 8; | ||
gdkcolor->green = green_component << 8; | ||
gdkcolor->blue = blue_component << 8; | ||
// convert back to floats in range 0.0 to 1.0 | ||
gdkrgba->red = red_component / 255.0; | ||
gdkrgba->green = green_component / 255.0; | ||
gdkrgba->blue = blue_component / 255.0; | ||
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.
|
||
gdkrgba->alpha = 1.0; | ||
|
||
return gdkcolor; | ||
return gdkrgba; | ||
} | ||
|
||
i3WorkspacesConfig * | ||
|
@@ -162,15 +163,14 @@ void add_color_picker(i3WorkspacesConfig *config, GtkWidget *dialog_vbox, char * | |
GtkWidget *hbox, *button, *label; | ||
|
||
/* focused color */ | ||
hbox = gtk_hbox_new(FALSE, 3); | ||
hbox = gtk_box_new(FALSE, 3); | ||
gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); | ||
gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); | ||
|
||
label = gtk_label_new(_(text)); | ||
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | ||
|
||
button = gtk_color_button_new_with_color(unserialize_gdkcolor( | ||
color)); | ||
button = gtk_color_button_new_with_rgba(unserialize_gdkrgba(color)); | ||
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | ||
g_signal_connect(G_OBJECT(button), "color-set", G_CALLBACK(callback), config); | ||
} | ||
|
@@ -179,29 +179,33 @@ void | |
i3_workspaces_config_show(i3WorkspacesConfig *config, XfcePanelPlugin *plugin, | ||
ConfigChangedCallback cb, gpointer cb_data) | ||
{ | ||
GtkWidget *dialog, *dialog_vbox, *hbox, *button, *label; | ||
GtkWidget *dialog, *dialog_content, *hbox, *button, *label; | ||
|
||
xfce_panel_plugin_block_menu(plugin); | ||
|
||
dialog = xfce_titled_dialog_new_with_buttons(_("i3 Workspaces Plugin"), | ||
NULL, GTK_DIALOG_NO_SEPARATOR, GTK_STOCK_CLOSE, GTK_RESPONSE_OK, NULL); | ||
dialog = xfce_titled_dialog_new_with_mixed_buttons(_("i3 Workspaces Plugin"), | ||
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(plugin))), | ||
GTK_DIALOG_DESTROY_WITH_PARENT, | ||
"window-close", "_Close", | ||
GTK_RESPONSE_OK, | ||
NULL); | ||
xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(dialog), _("Configuration")); | ||
|
||
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); | ||
gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); | ||
gtk_window_stick(GTK_WINDOW(dialog)); | ||
|
||
dialog_vbox = GTK_DIALOG(dialog)->vbox; | ||
dialog_content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | ||
|
||
add_color_picker(config, dialog_vbox, "Normal Workspace Color:", config->normal_color, normal_color_changed); | ||
add_color_picker(config, dialog_vbox, "Focused Workspace Color:", config->focused_color, focused_color_changed); | ||
add_color_picker(config, dialog_vbox, "Urgent Workspace Color:", config->urgent_color, urgent_color_changed); | ||
add_color_picker(config, dialog_vbox, "Unfocused Visible Workspace Color:", config->visible_color, visible_color_changed); | ||
add_color_picker(config, dialog_vbox, "Binding Mode Color:", config->mode_color, mode_color_changed); | ||
add_color_picker(config, dialog_content, "Normal Workspace Color:", config->normal_color, normal_color_changed); | ||
add_color_picker(config, dialog_content, "Focused Workspace Color:", config->focused_color, focused_color_changed); | ||
add_color_picker(config, dialog_content, "Urgent Workspace Color:", config->urgent_color, urgent_color_changed); | ||
add_color_picker(config, dialog_content, "Unfocused Visible Workspace Color:", config->visible_color, visible_color_changed); | ||
add_color_picker(config, dialog_content, "Binding Mode Color:", config->mode_color, mode_color_changed); | ||
|
||
/* strip workspace numbers */ | ||
hbox = gtk_hbox_new(FALSE, 3); | ||
gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); | ||
hbox = gtk_box_new(FALSE, 3); | ||
gtk_container_add(GTK_CONTAINER(dialog_content), hbox); | ||
gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); | ||
|
||
button = gtk_check_button_new_with_mnemonic(_("Strip Workspace Numbers")); | ||
|
@@ -210,8 +214,8 @@ i3_workspaces_config_show(i3WorkspacesConfig *config, XfcePanelPlugin *plugin, | |
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(strip_workspace_numbers_changed), config); | ||
|
||
/* auto detect output */ | ||
hbox = gtk_hbox_new(FALSE, 3); | ||
gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); | ||
hbox = gtk_box_new(FALSE, 3); | ||
gtk_container_add(GTK_CONTAINER(dialog_content), hbox); | ||
gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); | ||
|
||
button = gtk_check_button_new_with_mnemonic(_("Auto detect outputs")); | ||
|
@@ -220,8 +224,8 @@ i3_workspaces_config_show(i3WorkspacesConfig *config, XfcePanelPlugin *plugin, | |
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(auto_detect_outputs_changed), config); | ||
|
||
/* output */ | ||
hbox = gtk_hbox_new(FALSE, 3); | ||
gtk_container_add(GTK_CONTAINER(dialog_vbox), hbox); | ||
hbox = gtk_box_new(FALSE, 3); | ||
gtk_container_add(GTK_CONTAINER(dialog_content), hbox); | ||
gtk_container_set_border_width(GTK_CONTAINER(hbox), 3); | ||
|
||
label = gtk_label_new(_("Output:")); | ||
|
@@ -265,42 +269,42 @@ output_changed(GtkWidget *entry, i3WorkspacesConfig *config) | |
void | ||
normal_color_changed(GtkWidget *button, i3WorkspacesConfig *config) | ||
{ | ||
GdkColor color; | ||
gtk_color_button_get_color(GTK_COLOR_BUTTON(button), &color); | ||
config->normal_color = serialize_gdkcolor(&color); | ||
GdkRGBA color; | ||
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(button), &color); | ||
config->normal_color = serialize_gdkrgba(&color); | ||
} | ||
|
||
void | ||
focused_color_changed(GtkWidget *button, i3WorkspacesConfig *config) | ||
{ | ||
GdkColor color; | ||
gtk_color_button_get_color(GTK_COLOR_BUTTON(button), &color); | ||
config->focused_color = serialize_gdkcolor(&color); | ||
GdkRGBA color; | ||
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(button), &color); | ||
config->focused_color = serialize_gdkrgba(&color); | ||
} | ||
|
||
void | ||
urgent_color_changed(GtkWidget *button, i3WorkspacesConfig *config) | ||
{ | ||
GdkColor color; | ||
gtk_color_button_get_color(GTK_COLOR_BUTTON(button), &color); | ||
config->urgent_color = serialize_gdkcolor(&color); | ||
GdkRGBA color; | ||
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(button), &color); | ||
config->urgent_color = serialize_gdkrgba(&color); | ||
} | ||
|
||
void | ||
visible_color_changed(GtkWidget *button, i3WorkspacesConfig *config) | ||
{ | ||
GdkColor color; | ||
gtk_color_button_get_color(GTK_COLOR_BUTTON(button), &color); | ||
config->visible_color = serialize_gdkcolor(&color); | ||
GdkRGBA color; | ||
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(button), &color); | ||
config->visible_color = serialize_gdkrgba(&color); | ||
} | ||
|
||
void | ||
|
||
mode_color_changed(GtkWidget *button, i3WorkspacesConfig *config) | ||
{ | ||
GdkColor color; | ||
gtk_color_button_get_color(GTK_COLOR_BUTTON(button), &color); | ||
config->mode_color = serialize_gdkcolor(&color); | ||
GdkRGBA color; | ||
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(button), &color); | ||
config->mode_color = serialize_gdkrgba(&color); | ||
} | ||
|
||
void | ||
|
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 255
is not equivalent to>> 8
, is this a difference between the two APIs?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! GdkRGBA stores its components in floats of range 0.0 to 1.0. Multiplying and dividing by 255 (max of a uint8) converts to/from 8 bit ints, whereas shifts will do interesting (incorrect) things.
I also have a branch (https://github.com/ad1217/xfce4-i3-workspaces-plugin/tree/gtk3-css) which I wrote last night that does away with this part entirely in favor of CSS styling, which seems to be the preferred method for GTK3 and simplifies a lot of the color-related code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your branch works for me in Arch. I've not noticed any bugs, just that only the text is coloured, rather than the coloured boxes as in the original. If you're planning to maintain this package for the future, is it beyond your scope to add a few features? It would be nice to be able to change the font and customise the background, border, and text colours for each workspace type, to make it look like the native i3 bar. Otherwise I'm just happy that functionality is restored, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ad1217 I'm going to merge this branch as-is, and you can submit your CSS branch as a follow-up (if you want to).