Skip to content

Commit 7d23b6b

Browse files
committed
wayland: add window decoration options and hide-titlebar-when-maximized hint
This commit adds multiple options for controlling window decorations on Wayland: 1. Prefer server-side decorations (SSD) over client-side decorations (CSD) 2. Add hide-titlebar-when-maximized hint for better compatibility with GNOME extensions like Unite 3. Add environment variable DARKTABLE_HIDE_TITLEBAR_ON_MAXIMIZE to opt-out of HeaderBar usage when maximized (for Unite compatibility) 4. Add darktablerc option 'hide_titlebar_on_maximize' for persistent configuration These changes improve window behavior on Wayland, especially with tiling window managers and GNOME Shell extensions.
1 parent 1c7eebf commit 7d23b6b

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

src/gui/gtk.c

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ dt_gui_session_type_t dt_gui_get_session_type(void)
995995
: DT_GUI_SESSION_X11;
996996
#elif defined(GDK_WINDOWING_X11)
997997
GdkDisplay* disp = gdk_display_get_default();
998-
retun G_TYPE_CHECK_INSTANCE_TYPE(disp, GDK_TYPE_X11_DISPLAY)
998+
return G_TYPE_CHECK_INSTANCE_TYPE(disp, GDK_TYPE_X11_DISPLAY)
999999
? DT_GUI_SESSION_X11
10001000
: DT_GUI_SESSION_WAYLAND;
10011001
#else
@@ -1744,18 +1744,58 @@ static void _init_widgets(dt_gui_gtk_t *gui)
17441744
widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
17451745
gtk_widget_set_name(widget, "main_window");
17461746
gui->ui->main_window = widget;
1747+
/*
1748+
* Optional: hint the WM to hide server-side titlebar when maximized.
1749+
* Default is OFF to preserve the titlebar for users not relying on
1750+
* extensions. Enable to avoid a top gap when an external component
1751+
* (e.g. GNOME Unite) hides the titlebar.
1752+
*
1753+
* Enable via:
1754+
* - env: DARKTABLE_HIDE_TITLEBAR_ON_MAXIMIZE=1|true
1755+
* - conf: ui/hide_titlebar_on_maximize=true
1756+
*
1757+
* By default do NOT hide the titlebar on maximize. Enable only when
1758+
* explicitly requested via env/config for compatibility with extensions
1759+
* such as GNOME Unite. */
1760+
gboolean hide_on_max = FALSE;
1761+
const char *env_hide = g_getenv("DARKTABLE_HIDE_TITLEBAR_ON_MAXIMIZE");
1762+
if(env_hide)
1763+
{
1764+
if(*env_hide == '1' || g_ascii_strcasecmp(env_hide, "true") == 0)
1765+
hide_on_max = TRUE;
1766+
else if(*env_hide == '0' || g_ascii_strcasecmp(env_hide, "false") == 0)
1767+
hide_on_max = FALSE;
1768+
}
1769+
if(dt_conf_key_exists("ui/hide_titlebar_on_maximize"))
1770+
{
1771+
/* config overrides environment */
1772+
hide_on_max = dt_conf_get_bool("ui/hide_titlebar_on_maximize");
1773+
}
1774+
gtk_window_set_hide_titlebar_when_maximized(GTK_WINDOW(widget), hide_on_max);
17471775

17481776
#ifdef GDK_WINDOWING_WAYLAND
17491777
if(dt_gui_get_session_type() == DT_GUI_SESSION_WAYLAND)
17501778
{
17511779
// On Wayland, use NORMAL hint to allow proper window resizing
17521780
gtk_window_set_type_hint(GTK_WINDOW(widget), GDK_WINDOW_TYPE_HINT_NORMAL);
17531781

1754-
GtkWidget *header_bar = gtk_header_bar_new();
1755-
gtk_header_bar_set_title(GTK_HEADER_BAR(header_bar), "darktable");
1756-
gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header_bar), TRUE);
1757-
gtk_window_set_titlebar(GTK_WINDOW(widget), header_bar);
1758-
gtk_widget_show(header_bar);
1782+
/* Wayland: by default use GtkHeaderBar (as in master).
1783+
* If hide_on_max is enabled (compat mode for GNOME Unite extension), do NOT use
1784+
* HeaderBar and prefer server-side decorations so the WM/extension
1785+
* can hide the titlebar and resize correctly. */
1786+
if(hide_on_max)
1787+
{
1788+
/* Use server-side decorations */
1789+
gtk_window_set_decorated(GTK_WINDOW(widget), TRUE);
1790+
}
1791+
else
1792+
{
1793+
GtkWidget *header_bar = gtk_header_bar_new();
1794+
gtk_header_bar_set_title(GTK_HEADER_BAR(header_bar), "darktable");
1795+
gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header_bar), TRUE);
1796+
gtk_window_set_titlebar(GTK_WINDOW(widget), header_bar);
1797+
gtk_widget_show(header_bar);
1798+
}
17591799
}
17601800
#endif
17611801

0 commit comments

Comments
 (0)