Skip to content

Commit 51ab8b2

Browse files
authored
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
1 parent 16aa6a5 commit 51ab8b2

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/gui/gtk.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,42 @@ static gboolean _scrollbar_changed(GtkWidget *widget,
773773
return TRUE;
774774
}
775775

776+
gboolean _valid_window_placement( const gint saved_x,
777+
const gint saved_y,
778+
const gint window_width,
779+
const gint window_height,
780+
const gint border)
781+
{
782+
GdkDisplay *display = gdk_display_get_default();
783+
const gint n_monitors = gdk_display_get_n_monitors(display);
784+
785+
// check each monitor
786+
for(gint i = 0; i < n_monitors; i++)
787+
{
788+
GdkMonitor *monitor = gdk_display_get_monitor(display, i);
789+
GdkRectangle geometry;
790+
gdk_monitor_get_geometry(monitor, &geometry);
791+
792+
// Calculate effective area excluding border
793+
const gint eff_x = geometry.x + border;
794+
const gint eff_y = geometry.y + border;
795+
const gint eff_width = geometry.width - (2 * border);
796+
const gint eff_height = geometry.height - (2 * border);
797+
798+
if(eff_width <= 0 || eff_height <= 0) continue;
799+
800+
// Check overlap
801+
const gboolean x_overlap = (saved_x < eff_x + eff_width) && (saved_x + window_width > eff_x);
802+
const gboolean y_overlap = (saved_y < eff_y + eff_height) && (saved_y + window_height > eff_y);
803+
804+
if(x_overlap && y_overlap)
805+
{
806+
return TRUE;
807+
}
808+
}
809+
return FALSE;
810+
}
811+
776812
int dt_gui_gtk_load_config()
777813
{
778814
dt_pthread_mutex_lock(&darktable.gui->mutex);
@@ -784,7 +820,10 @@ int dt_gui_gtk_load_config()
784820
const gint y = MAX(0, dt_conf_get_int("ui_last/window_y"));
785821

786822
gtk_window_resize(GTK_WINDOW(widget), width, height);
787-
gtk_window_move(GTK_WINDOW(widget), x, y);
823+
if(_valid_window_placement(x, y, width, height, 24))
824+
gtk_window_move(GTK_WINDOW(widget), x, y);
825+
else
826+
gtk_window_move(GTK_WINDOW(widget), 0, 0);
788827
const gboolean fullscreen = dt_conf_get_bool("ui_last/fullscreen");
789828

790829
if(fullscreen)

0 commit comments

Comments
 (0)