gsimplecal icon indicating copy to clipboard operation
gsimplecal copied to clipboard

Add `mainwindow_position = topleft` etc

Open dmedvinsky opened this issue 4 years ago • 1 comments

Got this patch in email from Kent Friis.

Unfortunately it currently raises a bunch of warnings that gdk_screen_width and gdk_screen_height are deprecated when compiling against gtk3.

So far we got

apparently you are supposed to use gdk_monitor_get_workarea(), which doesn't even exist in the gtk 3.18 on Slackware, so it's not even a case of if(gtk2), it's before gtk 3.22 and after gtk 3.22

I've been putting this off for a while because I've got no time for this, unfortunately. Opening a pull request for this to not get lost forever.

If anyone has any input, please comment.

dmedvinsky avatar Apr 29 '21 11:04 dmedvinsky

fix deprecation

diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 064bd3d..bfbbecb 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -138,22 +138,37 @@ MainWindow::MainWindow()
 
     if (config->mainwindow_gravity) {
         gtk_window_get_size(GTK_WINDOW(widget), &xpos, &ypos);
+       int screen_width = 0;
+       int screen_height = 0;
+#if (GTK_MAJOR_VERSION < 3) or (GTK_MAJOR_VERION == 3 and GTK_MINOR_VERSION < 22)
+       screen_width = gdk_screen_width();
+       screen_height = gdk_screen_height();
+#else
+       GdkRectangle    work_area;
+       gdk_monitor_get_workarea(gdk_display_get_primary_monitor(gdk_display_get_default()),
+                                &work_area);
+       screen_width = work_area.width;
+       screen_height = work_area.height;
+#endif
+       GdkRectangle workarea = {0};
+       gdk_monitor_get_workarea(gdk_display_get_primary_monitor(gdk_display_get_default()), &workarea);
+
         switch(config->mainwindow_gravity) {
             case GDK_GRAVITY_NORTH_WEST:
                 xpos = config->mainwindow_xoffset;
                 ypos = config->mainwindow_yoffset;
                 break;
             case GDK_GRAVITY_NORTH_EAST:
-                xpos = gdk_screen_width() - xpos - config->mainwindow_xoffset;
+                xpos = screen_width - xpos - config->mainwindow_xoffset;
                 ypos = config->mainwindow_yoffset;
                 break;
             case GDK_GRAVITY_SOUTH_WEST:
                 xpos = config->mainwindow_xoffset;
-                ypos = gdk_screen_height() - ypos - config->mainwindow_yoffset;
+                ypos = screen_height - ypos - config->mainwindow_yoffset;
                 break;
             case GDK_GRAVITY_SOUTH_EAST:
-                xpos = gdk_screen_width() - xpos - config->mainwindow_xoffset;
-                ypos = gdk_screen_height() - ypos - config->mainwindow_yoffset;
+                xpos = screen_width - xpos - config->mainwindow_xoffset;
+                ypos = screen_height - ypos - config->mainwindow_yoffset;
                 break;
         }
         gtk_window_set_gravity(GTK_WINDOW(widget), config->mainwindow_gravity);

lleroy avatar May 16 '25 08:05 lleroy