Skip to content

Commit

Permalink
Merge pull request #202 from JosephMcc/master
Browse files Browse the repository at this point in the history
screen: Add a public meta_screen_get_current_monitor(). A convenience…
  • Loading branch information
clefebvre committed Sep 3, 2015
2 parents 9129236 + 42eb83b commit b344d32
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/core/keybindings.c
Expand Up @@ -2366,7 +2366,7 @@ handle_move_to_center (MetaDisplay *display,
int window_width, window_height;
int center_x, center_y;

monitor = meta_screen_get_current_monitor (window->screen);
monitor = meta_screen_get_current_monitor_info (window->screen);
meta_frame_calc_borders (window->frame, &borders);

window_width = (window->frame ? window->frame->rect.width : window->rect.width);
Expand Down
10 changes: 5 additions & 5 deletions src/core/place.c
Expand Up @@ -139,7 +139,7 @@ place_in_center (MetaWindow *window,
int center_x, center_y;
const MetaMonitorInfo *xi;

xi = meta_screen_get_current_monitor (window->screen);
xi = meta_screen_get_current_monitor_info (window->screen);
center_x = *new_x + xi->rect.width / 2;
center_y = *new_y + xi->rect.height / 2;

Expand Down Expand Up @@ -177,7 +177,7 @@ find_next_cascade (MetaWindow *window,
int window_width, window_height;
int cascade_stage;
MetaRectangle work_area;
const MetaMonitorInfo* current;
int current;

sorted = g_list_copy (windows);
sorted = g_list_sort (sorted, northwestcmp);
Expand All @@ -203,7 +203,7 @@ find_next_cascade (MetaWindow *window,
*/

current = meta_screen_get_current_monitor (window->screen);
meta_window_get_work_area_for_monitor (window, current->number, &work_area);
meta_window_get_work_area_for_monitor (window, current, &work_area);

cascade_x = MAX (0, work_area.x);
cascade_y = MAX (0, work_area.y);
Expand Down Expand Up @@ -881,7 +881,7 @@ meta_window_place (MetaWindow *window,
int w, h;

/* Warning, this function is a round trip! */
xi = meta_screen_get_current_monitor (window->screen);
xi = meta_screen_get_current_monitor_info (window->screen);

w = xi->rect.width;
h = xi->rect.height;
Expand Down Expand Up @@ -928,7 +928,7 @@ meta_window_place (MetaWindow *window,
}

/* Warning, this is a round trip! */
xi = meta_screen_get_current_monitor (window->screen);
xi = meta_screen_get_current_monitor_info (window->screen);

/* "Origin" placement algorithm */
x = xi->rect.x;
Expand Down
10 changes: 5 additions & 5 deletions src/core/screen-private.h
Expand Up @@ -180,11 +180,11 @@ gboolean meta_screen_tile_hud_get_visible (MetaScreen *screen);

void meta_screen_hide_hud_and_preview (MetaScreen *screen);

const MetaMonitorInfo* meta_screen_get_current_monitor (MetaScreen *screen);
const MetaMonitorInfo* meta_screen_get_monitor_for_rect (MetaScreen *screen,
MetaRectangle *rect);
const MetaMonitorInfo* meta_screen_get_monitor_for_window (MetaScreen *screen,
MetaWindow *window);
const MetaMonitorInfo* meta_screen_get_current_monitor_info (MetaScreen *screen);
const MetaMonitorInfo* meta_screen_get_monitor_for_rect (MetaScreen *screen,
MetaRectangle *rect);
const MetaMonitorInfo* meta_screen_get_monitor_for_window (MetaScreen *screen,
MetaWindow *window);


const MetaMonitorInfo* meta_screen_get_monitor_neighbor (MetaScreen *screen,
Expand Down
32 changes: 24 additions & 8 deletions src/core/screen.c
Expand Up @@ -1785,13 +1785,13 @@ static gboolean
snap_osd_timeout (void *data)
{
MetaScreen *screen = data;
const MetaMonitorInfo *monitor;
int monitor;

monitor = meta_screen_get_current_monitor (screen);

if (meta_screen_tile_preview_get_visible (screen) ||
meta_screen_tile_hud_get_visible (screen))
g_signal_emit (screen, screen_signals[SNAP_OSD_SHOW], 0, monitor->number);
g_signal_emit (screen, screen_signals[SNAP_OSD_SHOW], 0, monitor);
screen->snap_osd_timeout_id = 0;
return FALSE;
}
Expand Down Expand Up @@ -1940,9 +1940,9 @@ meta_screen_tile_hud_update_timeout (gpointer data)
/* This bit is liable to get more complicated when there are multiple
monitors involved - we'll have partial hud, with a bare area at the
monitor 'joint' or something... */
const MetaMonitorInfo *monitor;
int monitor;
monitor = meta_screen_get_current_monitor (screen);
meta_window_get_work_area_for_monitor (window, monitor->number, &work_area);
meta_window_get_work_area_for_monitor (window, monitor, &work_area);
meta_compositor_show_hud_preview (screen->display->compositor,
screen, window->current_proximity_zone,
&work_area, window->snap_queued);
Expand Down Expand Up @@ -2201,7 +2201,7 @@ meta_screen_get_natural_monitor_list (MetaScreen *screen,
visited[i] = FALSE;
}

current = meta_screen_get_current_monitor (screen);
current = meta_screen_get_current_monitor_info (screen);
monitor_queue = g_queue_new ();
g_queue_push_tail (monitor_queue, (gpointer) current);
visited[current->number] = TRUE;
Expand Down Expand Up @@ -2267,11 +2267,27 @@ meta_screen_get_natural_monitor_list (MetaScreen *screen,
g_queue_free (monitor_queue);
}

LOCAL_SYMBOL const MetaMonitorInfo*
const MetaMonitorInfo *
meta_screen_get_current_monitor_info (MetaScreen *screen)
{
int monitor_index;
monitor_index = meta_screen_get_current_monitor (screen);
return &screen->monitor_infos[monitor_index];
}

/**
* meta_screen_get_current_monitor:
* @screen: a #MetaScreen
*
* Gets the index of the monitor that currently has the mouse pointer.
*
* Return value: a monitor index
*/
int
meta_screen_get_current_monitor (MetaScreen *screen)
{
if (screen->n_monitor_infos == 1)
return &screen->monitor_infos[0];
return 0;

/* Sadly, we have to do it this way. Yuck.
*/
Expand Down Expand Up @@ -2313,7 +2329,7 @@ meta_screen_get_current_monitor (MetaScreen *screen)
screen->last_monitor_index);
}

return &screen->monitor_infos[screen->last_monitor_index];
return screen->last_monitor_index;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/core/window.c
Expand Up @@ -3888,15 +3888,15 @@ meta_window_can_tile_maximized (MetaWindow *window)
LOCAL_SYMBOL gboolean
meta_window_can_tile_side_by_side (MetaWindow *window)
{
const MetaMonitorInfo *monitor;
int monitor;
MetaRectangle tile_area;
MetaFrameBorders borders;

if (!meta_window_can_tile_maximized (window))
return FALSE;

monitor = meta_screen_get_current_monitor (window->screen);
meta_window_get_work_area_for_monitor (window, monitor->number, &tile_area);
meta_window_get_work_area_for_monitor (window, monitor, &tile_area);

tile_area.width /= 2;

Expand All @@ -3912,15 +3912,15 @@ meta_window_can_tile_side_by_side (MetaWindow *window)
LOCAL_SYMBOL gboolean
meta_window_can_tile_top_bottom (MetaWindow *window)
{
const MetaMonitorInfo *monitor;
int monitor;
MetaRectangle tile_area;
MetaFrameBorders borders;

if (!meta_window_can_tile_maximized (window))
return FALSE;

monitor = meta_screen_get_current_monitor (window->screen);
meta_window_get_work_area_for_monitor (window, monitor->number, &tile_area);
meta_window_get_work_area_for_monitor (window, monitor, &tile_area);

tile_area.height /= 2;

Expand All @@ -3936,15 +3936,15 @@ meta_window_can_tile_top_bottom (MetaWindow *window)
LOCAL_SYMBOL gboolean
meta_window_can_tile_corner (MetaWindow *window)
{
const MetaMonitorInfo *monitor;
int monitor;
MetaRectangle tile_area;
MetaFrameBorders borders;

if (!meta_window_can_tile_maximized (window))
return FALSE;

monitor = meta_screen_get_current_monitor (window->screen);
meta_window_get_work_area_for_monitor (window, monitor->number, &tile_area);
meta_window_get_work_area_for_monitor (window, monitor, &tile_area);

tile_area.width /= 2;
tile_area.height /= 2;
Expand Down Expand Up @@ -9155,7 +9155,7 @@ update_move (MetaWindow *window,
* refers to the monitor which contains the largest part of the window,
* the latter to the one where the pointer is located.
*/
monitor = meta_screen_get_current_monitor (window->screen);
monitor = meta_screen_get_current_monitor_info (window->screen);
meta_window_get_work_area_for_monitor (window,
monitor->number,
&work_area);
Expand Down Expand Up @@ -11721,15 +11721,15 @@ meta_window_mouse_on_edge (MetaWindow *window, gint x, gint y)
{
MetaRectangle work_area;
gboolean ret = FALSE;
const MetaMonitorInfo *monitor;
int monitor;
gint left_shift, right_shift, up_shift, down_shift;
left_shift = right_shift = up_shift = down_shift = 0;

monitor = meta_screen_get_current_monitor (window->screen);
meta_window_get_work_area_for_monitor (window, monitor->number, &work_area);
meta_window_get_work_area_for_monitor (window, monitor, &work_area);

get_extra_padding_for_common_monitor_edges (window,
monitor->number,
monitor,
work_area,
&left_shift,
&right_shift,
Expand Down
1 change: 1 addition & 0 deletions src/meta/screen.h
Expand Up @@ -85,6 +85,7 @@ void meta_screen_unshow_desktop (MetaScreen *screen);

int meta_screen_get_n_monitors (MetaScreen *screen);
int meta_screen_get_primary_monitor (MetaScreen *screen);
int meta_screen_get_current_monitor (MetaScreen *screen);
void meta_screen_get_monitor_geometry (MetaScreen *screen,
int monitor,
MetaRectangle *geometry);
Expand Down

0 comments on commit b344d32

Please sign in to comment.