summaryrefslogtreecommitdiff
path: root/graphics/darktable/files/patch-git-0cc770a2e21ced661c5363c5733eb13ac7433748
blob: 4127a55bb2baecef7ad5880d39e5f56104e3ae08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From 0cc770a2e21ced661c5363c5733eb13ac7433748 Mon Sep 17 00:00:00 2001
From: Martin Straeten <39386816+MStraeten@users.noreply.github.com>
Date: Fri, 27 Jun 2025 17:06:45 +0200
Subject: [PATCH] reset window placement if last position is out of available
 display space (#18988)

* reset window if position is out of display space

on initialisation darktable moves the window to the last position even thats outside of the available displays.

_valid_window_placement checks for an overlay with an existing display

dt_gui_gtk_load_config() resets position to default if there's no overlap

* 24 pixel as a border

a border of 24 pixels is used to define the effective area that must be overlapped from the last window position to avoid a reset of position

* stile fixes

one parameter per line
several const additions
---
 src/gui/gtk.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/gui/gtk.c b/src/gui/gtk.c
index 671d87345850..a620dcb42332 100644
--- src/gui/gtk.c
+++ b/src/gui/gtk.c
@@ -773,6 +773,42 @@ static gboolean _scrollbar_changed(GtkWidget *widget,
   return TRUE;
 }
 
+gboolean _valid_window_placement( const gint saved_x,
+                                  const gint saved_y,
+                                  const gint window_width,
+                                  const gint window_height,
+                                  const gint border)
+{
+  GdkDisplay *display = gdk_display_get_default();
+  const gint n_monitors = gdk_display_get_n_monitors(display);
+
+  // check each monitor
+  for(gint i = 0; i < n_monitors; i++)
+  {
+    GdkMonitor *monitor = gdk_display_get_monitor(display, i);
+    GdkRectangle geometry;
+    gdk_monitor_get_geometry(monitor, &geometry);
+
+    // Calculate effective area excluding border
+    const gint eff_x = geometry.x + border;
+    const gint eff_y = geometry.y + border;
+    const gint eff_width = geometry.width - (2 * border);
+    const gint eff_height = geometry.height - (2 * border);
+
+    if(eff_width <= 0 || eff_height <= 0) continue;
+
+    // Check overlap
+    const gboolean x_overlap = (saved_x < eff_x + eff_width) && (saved_x + window_width > eff_x);
+    const gboolean y_overlap = (saved_y < eff_y + eff_height) && (saved_y + window_height > eff_y);
+
+    if(x_overlap && y_overlap)
+    {
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
 int dt_gui_gtk_load_config()
 {
   dt_pthread_mutex_lock(&darktable.gui->mutex);
@@ -784,7 +820,10 @@ int dt_gui_gtk_load_config()
   const gint y = MAX(0, dt_conf_get_int("ui_last/window_y"));
 
   gtk_window_resize(GTK_WINDOW(widget), width, height);
-  gtk_window_move(GTK_WINDOW(widget), x, y);
+  if(_valid_window_placement(x, y, width, height, 24))
+    gtk_window_move(GTK_WINDOW(widget), x, y);
+  else
+    gtk_window_move(GTK_WINDOW(widget), 0, 0);
   const gboolean fullscreen = dt_conf_get_bool("ui_last/fullscreen");
 
   if(fullscreen)