Skip to content
Permalink
Browse files

screen: Remove get_current_monitor in favor of get_current_xinerama

Since xinerama already contains information on the monitor and its rectangle, there is no need to go through Gdk to get this information again.
  • Loading branch information...
vkareh authored and lukefromdc committed Jan 31, 2019
1 parent 8abba9a commit fad23c9979d3ba04f377eb0704b6d78b9ebf43c4
Showing with 10 additions and 56 deletions.
  1. +0 −3 src/core/screen-private.h
  2. +4 −37 src/core/screen.c
  3. +2 −2 src/core/window.c
  4. +4 −14 src/ui/tabpopup.c
@@ -36,7 +36,6 @@
#include "display-private.h"
#include "screen.h"
#include <X11/Xutil.h>
#include <gdk/gdk.h>
#include "ui.h"

typedef struct _MetaXineramaScreenInfo MetaXineramaScreenInfo;
@@ -194,8 +193,6 @@ void meta_screen_update_workspace_layout (MetaScreen *scree
void meta_screen_update_workspace_names (MetaScreen *screen);
void meta_screen_queue_workarea_recalc (MetaScreen *screen);

GdkMonitor* meta_screen_get_current_monitor (void);

Window meta_create_offscreen_window (Display *xdisplay,
Window parent,
long valuemask);
@@ -1224,8 +1224,7 @@ get_window_pixbuf (MetaWindow *window,
MetaDisplay *display;
cairo_surface_t *surface;
GdkPixbuf *pixbuf, *scaled;
GdkMonitor *monitor;
GdkRectangle rect;
const MetaXineramaScreenInfo *current;
double ratio;

display = window->display;
@@ -1248,28 +1247,19 @@ get_window_pixbuf (MetaWindow *window,
*width = gdk_pixbuf_get_width (pixbuf);
*height = gdk_pixbuf_get_height (pixbuf);

monitor = meta_screen_get_current_monitor ();
if (monitor != NULL)
{
gdk_monitor_get_geometry (monitor, &rect);
}
else
{
rect.width = window->screen->rect.width;
rect.height = window->screen->rect.height;
}
current = meta_screen_get_current_xinerama (window->screen);

/* Scale pixbuf to max dimension based on monitor size */
if (*width > *height)
{
int max_preview_width = rect.width / MAX_PREVIEW_SCALE;
int max_preview_width = current->rect.width / MAX_PREVIEW_SCALE;
ratio = ((double) *width) / max_preview_width;
*width = (int) max_preview_width;
*height = (int) (((double) *height) / ratio);
}
else
{
int max_preview_height = rect.height / MAX_PREVIEW_SCALE;
int max_preview_height = current->rect.height / MAX_PREVIEW_SCALE;
ratio = ((double) *height) / max_preview_height;
*height = (int) max_preview_height;
*width = (int) (((double) *width) / ratio);
@@ -1812,29 +1802,6 @@ meta_screen_get_current_xinerama (MetaScreen *screen)
return &screen->xinerama_infos[screen->last_xinerama_index];
}

GdkMonitor *
meta_screen_get_current_monitor ()
{
GdkDisplay *display;
GdkSeat *seat;
GdkDevice *device;
GdkMonitor *current;
gint x, y;

display = gdk_display_get_default ();
seat = gdk_display_get_default_seat (display);
device = gdk_seat_get_pointer (seat);

gdk_device_get_position (device, NULL, &x, &y);
current = gdk_display_get_monitor_at_point (display, x, y);

if (current != NULL) {
return current;
}

return gdk_display_get_primary_monitor (display);
}

#define _NET_WM_ORIENTATION_HORZ 0
#define _NET_WM_ORIENTATION_VERT 1

@@ -7197,8 +7197,8 @@ update_move (MetaWindow *window,
* inside edge, because we don't want to force users to maximize
* windows they are placing near the top of their screens.
*
* The "current" idea of meta_window_get_work_area_current_monitor() and
* meta_screen_get_current_monitor() is slightly different: the former
* The "current" idea of meta_window_get_work_area_for_xinerama() and
* meta_screen_get_current_xinerama() is slightly different: the former
* refers to the monitor which contains the largest part of the window,
* the latter to the one where the pointer is located.
*/
@@ -760,34 +760,24 @@ static GtkWidget*
selectable_workspace_new (MetaWorkspace *workspace, int entry_count)
{
GtkWidget *widget;
GdkMonitor *monitor;
GdkRectangle rect;
const MetaXineramaScreenInfo *current;
int mini_workspace_width, mini_workspace_height;
double mini_workspace_ratio;

widget = g_object_new (meta_select_workspace_get_type (), NULL);

monitor = meta_screen_get_current_monitor ();
if (monitor != NULL)
{
gdk_monitor_get_geometry (monitor, &rect);
}
else
{
rect.width = workspace->screen->rect.width;
rect.height = workspace->screen->rect.height;
}
current = meta_screen_get_current_xinerama (workspace->screen);

if (workspace->screen->rect.width < workspace->screen->rect.height)
{
mini_workspace_ratio = (double) workspace->screen->rect.width / (double) workspace->screen->rect.height;
mini_workspace_height = (int) ((double) rect.height / entry_count - SELECT_OUTLINE_WIDTH * 2);
mini_workspace_height = (int) ((double) current->rect.height / entry_count - SELECT_OUTLINE_WIDTH * 2);
mini_workspace_width = (int) ((double) mini_workspace_height * mini_workspace_ratio);
}
else
{
mini_workspace_ratio = (double) workspace->screen->rect.height / (double) workspace->screen->rect.width;
mini_workspace_width = (int) ((double) rect.width / entry_count - SELECT_OUTLINE_WIDTH * 2);
mini_workspace_width = (int) ((double) current->rect.width / entry_count - SELECT_OUTLINE_WIDTH * 2);
mini_workspace_height = (int) ((double) mini_workspace_width * mini_workspace_ratio);
}

0 comments on commit fad23c9

Please sign in to comment.
You can’t perform that action at this time.