Issue #7172: option to apply Client-Side decoration on image windows.

This patch does the following things:

- An option "Merge menu and title bar" (this is hopefully more understandable
  than calling it "Client-side decoration" or again "header bar") is added in
  Preferences > Image Windows. This option triggers the restart warning.
  Moreover when checked a small warning message will tell that in some cases, it
  may not work (there are feedbacks of people having 2 title bars when using GTK
  applications using CSD).
- For the reason evoked above (sometimes 2 title bars) and also because the CSD
  concept seem really to divide people a lot (some love this as much as others
  hate this), this new option "custom-title-bar" on GimpGuiConfig is FALSE by
  default.
- When the option is checked, the image windows will use a GTK header bar
  containing the menu, the window title (image name and information) as well as
  the usual minimize/maximize/close buttons per your OS conventions.
- Since the header bar is set to be hidden when maximizing, if you checked "Show
  menubar" for the "Default Appearance in Fullscreen Mode" in Preferences >
  Image Windows > Appearance, the menu will be moved to its "old style"
  position, i.e. above the canvas. This makes the menu possibly visible (if
  relevant option is checked) even in fullscreen mode.
- I tweaked the Default theme to show the header bar with minimal height,
  because I find GTK default theme's headerbar height unreasonably high
  (especially if the point of the header bar is to save screen space). I am
  unsure if this was the right move though, because maybe the default theme
  should not do such choices (maybe this should go in the Compact theme?).
This commit is contained in:
Jehan 2023-06-09 19:56:33 +02:00
parent 10742367c5
commit 317aa803d2
6 changed files with 103 additions and 6 deletions

View File

@ -85,6 +85,7 @@ enum
PROP_USER_MANUAL_ONLINE_URI,
PROP_DOCK_WINDOW_HINT,
PROP_CURSOR_HANDEDNESS,
PROP_CUSTOM_TITLE_BAR,
PROP_PLAYGROUND_NPD_TOOL,
PROP_PLAYGROUND_SEAMLESS_CLONE_TOOL,
@ -424,6 +425,14 @@ gimp_gui_config_class_init (GimpGuiConfigClass *klass)
GIMP_HANDEDNESS_RIGHT,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_CUSTOM_TITLE_BAR,
"custom-title-bar",
"Custom title bar embedding the menu",
CUSTOM_TITLE_BAR_BLURB,
FALSE,
GIMP_PARAM_STATIC_STRINGS |
GIMP_CONFIG_PARAM_RESTART);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_PLAYGROUND_NPD_TOOL,
"playground-npd-tool",
"Playground N-Point Deformation tool",
@ -715,6 +724,9 @@ gimp_gui_config_set_property (GObject *object,
case PROP_CURSOR_HANDEDNESS:
gui_config->cursor_handedness = g_value_get_enum (value);
break;
case PROP_CUSTOM_TITLE_BAR:
gui_config->custom_title_bar = g_value_get_boolean (value);
break;
case PROP_PLAYGROUND_NPD_TOOL:
gui_config->playground_npd_tool = g_value_get_boolean (value);
@ -887,6 +899,9 @@ gimp_gui_config_get_property (GObject *object,
case PROP_CURSOR_HANDEDNESS:
g_value_set_enum (value, gui_config->cursor_handedness);
break;
case PROP_CUSTOM_TITLE_BAR:
g_value_set_boolean (value, gui_config->custom_title_bar);
break;
case PROP_PLAYGROUND_NPD_TOOL:
g_value_set_boolean (value, gui_config->playground_npd_tool);

View File

@ -79,6 +79,7 @@ struct _GimpGuiConfig
gint action_history_size;
GimpWindowHint dock_window_hint;
GimpHandedness cursor_handedness;
gboolean custom_title_bar;
/* experimental playground */
gboolean playground_npd_tool;

View File

@ -77,6 +77,9 @@ _("Context-dependent mouse pointers are helpful. They are enabled by " \
"Specify a default tool preset. The tool preset is searched for in the " \
"specified tool prests path."
#define CUSTOM_TITLE_BAR_BLURB \
_("Merge menu and title bar (client-side decoration)")
#define DEFAULT_SHOW_ALL_BLURB \
_("Show full image content by default.")

View File

@ -3102,6 +3102,18 @@ prefs_dialog_new (Gimp *gimp,
/* General */
vbox2 = prefs_frame_new (_("General"), GTK_CONTAINER (vbox), FALSE);
prefs_check_button_add (object, "custom-title-bar",
_("Merge menu and title bar"),
GTK_BOX (vbox2));
hbox = prefs_hint_box_new (GIMP_ICON_DIALOG_WARNING,
_("GIMP will try to convince your system not to decorate image windows. "
"If it doesn't work properly on your system "
"(i.e. you get 2 title bars), please report."));
gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
g_object_bind_property (object, "custom-title-bar",
hbox, "visible",
G_BINDING_SYNC_CREATE);
prefs_check_button_add (object, "default-show-all",
_("Use \"Show _all\" by default"),
GTK_BOX (vbox2));

View File

@ -405,9 +405,6 @@ gimp_image_window_constructed (GObject *object)
{
private->menubar = gimp_menu_bar_new (private->menubar_model, menubar_manager);
gtk_box_pack_start (GTK_BOX (private->main_vbox),
private->menubar, FALSE, FALSE, 0);
/* make sure we can activate accels even if the menubar is invisible
* (see https://bugzilla.gnome.org/show_bug.cgi?id=137151)
*/
@ -425,6 +422,35 @@ gimp_image_window_constructed (GObject *object)
g_signal_connect (private->menubar, "key-press-event",
G_CALLBACK (gimp_image_window_shell_events),
window);
if (config->custom_title_bar)
{
GtkWidget *headerbar;
headerbar = gtk_header_bar_new ();
gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);
/* This is important to turn off space reservation for the subtitle
* (resulting in too high header bar).
*/
gtk_header_bar_set_has_subtitle (GTK_HEADER_BAR (headerbar), FALSE);
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), TRUE);
gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), private->menubar);
gtk_widget_show (headerbar);
/* XXX There are competing propositions on how the title should be
* aligned. GTK is trying to center it (relatively to the window) as
* much as it can. But some people seem to thing it should be centered
* relatively to the remaining empty space after the menu.
* I am personally unsure so leaving GTK's defaults for now.
*/
}
else
{
gtk_box_pack_start (GTK_BOX (private->main_vbox),
private->menubar, FALSE, FALSE, 0);
}
}
#ifndef GDK_WINDOWING_QUARTZ
@ -691,10 +717,42 @@ static void
gimp_image_window_update_csd_on_fullscreen (GtkWidget *child,
gpointer user_data)
{
gboolean fullscreen = GPOINTER_TO_INT (user_data);
GimpImageWindow *window = GIMP_IMAGE_WINDOW (user_data);
GimpImageWindowPrivate *private = GIMP_IMAGE_WINDOW_GET_PRIVATE (window);
gboolean fullscreen;
fullscreen = gimp_image_window_get_fullscreen (window);
if (GTK_IS_HEADER_BAR (child))
gtk_widget_set_visible (child, !fullscreen);
{
gtk_widget_set_visible (child, !fullscreen);
/* When we manage the menubar ourselves (i.e. not when using the GTK
* menubar, e.g. on macOS), if the menubar was set to stay visible in
* fullscreen mode, we need to move it out of the header bar.
* Note that here we only move the menubar from one parent to another.
* This is not where we handle whether we make it visible or not.
*/
if (private->menubar)
{
GtkWidget *parent = gtk_widget_get_parent (private->menubar);
g_object_ref (private->menubar);
gtk_container_remove (GTK_CONTAINER (parent), private->menubar);
if (fullscreen)
{
gtk_box_pack_start (GTK_BOX (private->main_vbox),
private->menubar, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (private->main_vbox),
private->menubar, 0);
}
else
{
gtk_header_bar_pack_start (GTK_HEADER_BAR (child), private->menubar);
}
g_object_unref (private->menubar);
}
}
}
static gboolean
@ -732,7 +790,7 @@ gimp_image_window_window_state_event (GtkWidget *widget,
* an internal child, so we use this workaround instead */
gtk_container_forall (GTK_CONTAINER (window),
gimp_image_window_update_csd_on_fullscreen,
GINT_TO_POINTER (fullscreen));
window);
}
if (event->changed_mask & GDK_WINDOW_STATE_ICONIFIED)

View File

@ -444,3 +444,11 @@ switch {
switch:checked {
background-color: rgb(200,200,255);
}
/* XXX: should this actually go in the Compact theme instead?
* I find the headerbar on GNOME default theme (Adwaita) to be kinda huge. But
* maybe the default theme should not try and override this?
*/
headerbar {
min-height: 0px
}