Skip to content

Commit

Permalink
Handle deprecation of gdk_screen_{width,height}
Browse files Browse the repository at this point in the history
GTK+ 3.22 deprecates gdk_screen_{width,height} on the grounds that the
"screen" here actually refers to a virtual screen that may span multiple
monitors, and applications should generally be considering the width and
height of individual monitors.  It's not entirely clear to me how this
fits with X geometry specifications, but I've gone with trying to get
hold of the geometry of the monitor that the window in question is on.
  • Loading branch information
cjwatson authored and sgtatham committed Mar 7, 2017
1 parent 8833634 commit 921afd3
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions unix/gtkwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -4302,6 +4302,30 @@ static void start_backend(struct gui_data *inst)
gtk_widget_set_sensitive(inst->restartitem, FALSE);
}

static void get_monitor_geometry(GtkWidget *widget, GdkRectangle *geometry)
{
#if GTK_CHECK_VERSION(3,4,0)
GdkDisplay *display = gtk_widget_get_display(widget);
GdkWindow *gdkwindow = gtk_widget_get_window(widget);
# if GTK_CHECK_VERSION(3,22,0)
GdkMonitor *monitor;
if (gdkwindow)
monitor = gdk_display_get_monitor_at_window(display, gdkwindow);
else
monitor = gdk_display_get_monitor(display, 0);
gdk_monitor_get_geometry(monitor, geometry);
# else
GdkScreen *screen = gdk_display_get_default_screen(display);
gint monitor_num = gdk_screen_get_monitor_at_window(screen, gdkwindow);
gdk_screen_get_monitor_geometry(screen, monitor_num, geometry);
# endif
#else
geometry->x = geometry->y = 0;
geometry->width = gdk_screen_width();
geometry->height = gdk_screen_height();
#endif
}

struct gui_data *new_session_window(Conf *conf, const char *geometry_string)
{
struct gui_data *inst;
Expand Down Expand Up @@ -4436,9 +4460,11 @@ struct gui_data *new_session_window(Conf *conf, const char *geometry_string)
};
int x = inst->xpos, y = inst->ypos;
int wp, hp;
GdkRectangle monitor_geometry;
compute_whole_window_size(inst, inst->width, inst->height, &wp, &hp);
if (inst->gravity & 1) x += (gdk_screen_width() - wp);
if (inst->gravity & 2) y += (gdk_screen_height() - hp);
get_monitor_geometry(GTK_WIDGET(inst->window), &monitor_geometry);
if (inst->gravity & 1) x += (monitor_geometry.width - wp);
if (inst->gravity & 2) y += (monitor_geometry.height - hp);
gtk_window_set_gravity(GTK_WINDOW(inst->window),
gravities[inst->gravity & 3]);
gtk_window_move(GTK_WINDOW(inst->window), x, y);
Expand Down

0 comments on commit 921afd3

Please sign in to comment.