2014-03-19 09:26:17 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Red Hat
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "window-wayland.h"
|
|
|
|
|
|
|
|
#include "window-private.h"
|
2014-03-19 10:30:12 -04:00
|
|
|
#include "boxes-private.h"
|
2014-03-19 09:36:15 -04:00
|
|
|
#include "stack-tracker.h"
|
|
|
|
#include "meta-wayland-surface.h"
|
2014-03-19 09:26:17 -04:00
|
|
|
|
|
|
|
struct _MetaWindowWayland
|
|
|
|
{
|
|
|
|
MetaWindow parent;
|
2014-04-28 16:19:06 -04:00
|
|
|
|
|
|
|
gboolean has_saved_pos;
|
|
|
|
int saved_x;
|
|
|
|
int saved_y;
|
2014-05-12 18:05:31 -04:00
|
|
|
|
|
|
|
int last_sent_width;
|
|
|
|
int last_sent_height;
|
2014-03-19 09:26:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaWindowWaylandClass
|
|
|
|
{
|
|
|
|
MetaWindowClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaWindowWayland, meta_window_wayland, META_TYPE_WINDOW)
|
|
|
|
|
2014-03-19 09:36:15 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_manage (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaDisplay *display = window->display;
|
|
|
|
|
|
|
|
meta_display_register_wayland_window (display, window);
|
|
|
|
|
|
|
|
{
|
|
|
|
MetaStackWindow stack_window;
|
|
|
|
stack_window.any.type = META_WINDOW_CLIENT_TYPE_WAYLAND;
|
|
|
|
stack_window.wayland.meta_window = window;
|
|
|
|
meta_stack_tracker_record_add (window->screen->stack_tracker,
|
|
|
|
&stack_window,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_unmanage (MetaWindow *window)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MetaStackWindow stack_window;
|
|
|
|
stack_window.any.type = META_WINDOW_CLIENT_TYPE_WAYLAND;
|
|
|
|
stack_window.wayland.meta_window = window;
|
|
|
|
meta_stack_tracker_record_remove (window->screen->stack_tracker,
|
|
|
|
&stack_window,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_display_unregister_wayland_window (window->display, window);
|
|
|
|
}
|
|
|
|
|
2014-03-20 15:12:44 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_ping (MetaWindow *window,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
|
|
|
meta_wayland_surface_ping (window->surface, serial);
|
|
|
|
}
|
|
|
|
|
2014-03-20 15:07:44 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_delete (MetaWindow *window,
|
|
|
|
guint32 timestamp)
|
|
|
|
{
|
|
|
|
meta_wayland_surface_delete (window->surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_kill (MetaWindow *window)
|
|
|
|
{
|
2014-03-25 12:05:21 -04:00
|
|
|
MetaWaylandSurface *surface = window->surface;
|
|
|
|
struct wl_resource *resource = surface->resource;
|
|
|
|
|
|
|
|
/* Send the client an unrecoverable error to kill the client. */
|
|
|
|
wl_resource_post_error (resource,
|
|
|
|
WL_DISPLAY_ERROR_NO_MEMORY,
|
|
|
|
"User requested that we kill you. Sorry. Don't take it too personally.");
|
2014-03-20 15:07:44 -04:00
|
|
|
}
|
|
|
|
|
2014-03-20 15:16:57 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_focus (MetaWindow *window,
|
|
|
|
guint32 timestamp)
|
|
|
|
{
|
|
|
|
meta_display_set_input_focus_window (window->display,
|
|
|
|
window,
|
|
|
|
FALSE,
|
|
|
|
timestamp);
|
|
|
|
}
|
|
|
|
|
2014-03-19 10:30:12 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_move_resize_internal (MetaWindow *window,
|
|
|
|
int gravity,
|
|
|
|
MetaRectangle requested_rect,
|
|
|
|
MetaRectangle constrained_rect,
|
|
|
|
MetaMoveResizeFlags flags,
|
|
|
|
MetaMoveResizeResultFlags *result)
|
|
|
|
{
|
2014-04-28 16:19:06 -04:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
2014-04-16 16:28:43 -04:00
|
|
|
gboolean should_move = FALSE;
|
|
|
|
|
2014-03-19 10:30:12 -04:00
|
|
|
g_assert (window->frame == NULL);
|
|
|
|
|
|
|
|
/* For wayland clients, the size is completely determined by the client,
|
|
|
|
* and while this allows to avoid some trickery with frames and the resulting
|
|
|
|
* lagging, we also need to insist a bit when the constraints would apply
|
|
|
|
* a different size than the client decides.
|
|
|
|
*
|
|
|
|
* Note that this is not generally a problem for normal toplevel windows (the
|
|
|
|
* constraints don't see the size hints, or just change the position), but
|
|
|
|
* it can be for maximized or fullscreen.
|
|
|
|
*/
|
|
|
|
|
2014-04-28 16:21:06 -04:00
|
|
|
if (flags & META_IS_WAYLAND_RESIZE)
|
2014-03-19 10:30:12 -04:00
|
|
|
{
|
|
|
|
/* This is a call to wl_surface_commit(), ignore the constrained_rect and
|
|
|
|
* update the real client size to match the buffer size.
|
|
|
|
*/
|
|
|
|
|
2014-04-16 16:30:11 -04:00
|
|
|
*result |= META_MOVE_RESIZE_RESULT_RESIZED;
|
2014-03-19 10:30:12 -04:00
|
|
|
window->rect.width = requested_rect.width;
|
|
|
|
window->rect.height = requested_rect.height;
|
2014-04-16 16:28:43 -04:00
|
|
|
|
|
|
|
/* This is a commit of an attach. We should move the window to match the
|
|
|
|
* new position the client wants. */
|
|
|
|
should_move = TRUE;
|
2014-03-19 10:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (constrained_rect.width != window->rect.width ||
|
|
|
|
constrained_rect.height != window->rect.height)
|
|
|
|
{
|
2014-04-28 16:19:06 -04:00
|
|
|
wl_window->has_saved_pos = TRUE;
|
|
|
|
wl_window->saved_x = constrained_rect.x;
|
|
|
|
wl_window->saved_y = constrained_rect.y;
|
|
|
|
|
2014-05-12 18:05:31 -04:00
|
|
|
wl_window->last_sent_width = constrained_rect.width;
|
|
|
|
wl_window->last_sent_height = constrained_rect.height;
|
|
|
|
|
2014-03-19 10:30:12 -04:00
|
|
|
meta_wayland_surface_configure_notify (window->surface,
|
|
|
|
constrained_rect.width,
|
|
|
|
constrained_rect.height);
|
|
|
|
}
|
2014-04-28 16:21:06 -04:00
|
|
|
else
|
2014-04-16 16:28:43 -04:00
|
|
|
{
|
|
|
|
/* We're just moving the window, so we don't need to wait for a configure
|
|
|
|
* and then ack to simply move the window. */
|
|
|
|
should_move = TRUE;
|
|
|
|
}
|
2014-03-19 10:30:12 -04:00
|
|
|
|
2014-04-28 15:50:40 -04:00
|
|
|
if (should_move)
|
2014-04-16 16:16:01 -04:00
|
|
|
{
|
2014-04-28 18:15:03 -04:00
|
|
|
int new_x = constrained_rect.x;
|
|
|
|
int new_y = constrained_rect.y;
|
2014-04-28 16:20:53 -04:00
|
|
|
|
2014-04-28 15:51:41 -04:00
|
|
|
if (new_x != window->rect.x || new_y != window->rect.y)
|
2014-04-28 15:50:40 -04:00
|
|
|
{
|
|
|
|
*result |= META_MOVE_RESIZE_RESULT_MOVED;
|
2014-04-28 15:51:41 -04:00
|
|
|
window->rect.x = new_x;
|
|
|
|
window->rect.y = new_y;
|
2014-04-28 15:50:40 -04:00
|
|
|
}
|
2014-03-19 10:30:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:09:22 -04:00
|
|
|
static void
|
|
|
|
surface_state_changed (MetaWindow *window)
|
|
|
|
{
|
2014-05-12 18:05:31 -04:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
|
|
|
|
2014-05-05 19:09:22 -04:00
|
|
|
meta_wayland_surface_configure_notify (window->surface,
|
2014-05-12 18:05:31 -04:00
|
|
|
wl_window->last_sent_width,
|
|
|
|
wl_window->last_sent_height);
|
2014-05-05 19:09:22 -04:00
|
|
|
}
|
|
|
|
|
2014-03-19 09:26:17 -04:00
|
|
|
static void
|
2014-05-12 18:19:11 -04:00
|
|
|
appears_focused_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
2014-03-19 09:26:17 -04:00
|
|
|
{
|
2014-05-12 18:19:11 -04:00
|
|
|
MetaWindow *window = META_WINDOW (object);
|
|
|
|
|
|
|
|
/* When we're unmanaging, we remove focus from the window,
|
|
|
|
* causing this to fire. Don't do anything in that case. */
|
|
|
|
if (window->unmanaging)
|
|
|
|
return;
|
|
|
|
|
2014-05-05 19:09:22 -04:00
|
|
|
surface_state_changed (window);
|
2014-05-12 18:19:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_init (MetaWindowWayland *wl_window)
|
|
|
|
{
|
|
|
|
MetaWindow *window = META_WINDOW (wl_window);
|
|
|
|
|
|
|
|
g_signal_connect (window, "notify::appears-focused",
|
|
|
|
G_CALLBACK (appears_focused_changed), NULL);
|
2014-03-19 09:26:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_class_init (MetaWindowWaylandClass *klass)
|
|
|
|
{
|
2014-03-19 09:36:15 -04:00
|
|
|
MetaWindowClass *window_class = META_WINDOW_CLASS (klass);
|
|
|
|
|
|
|
|
window_class->manage = meta_window_wayland_manage;
|
|
|
|
window_class->unmanage = meta_window_wayland_unmanage;
|
2014-03-20 15:12:44 -04:00
|
|
|
window_class->ping = meta_window_wayland_ping;
|
2014-03-20 15:07:44 -04:00
|
|
|
window_class->delete = meta_window_wayland_delete;
|
|
|
|
window_class->kill = meta_window_wayland_kill;
|
2014-03-20 15:16:57 -04:00
|
|
|
window_class->focus = meta_window_wayland_focus;
|
2014-03-19 10:30:12 -04:00
|
|
|
window_class->move_resize_internal = meta_window_wayland_move_resize_internal;
|
2014-03-19 09:26:17 -04:00
|
|
|
}
|
2014-04-28 17:44:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_window_move_resize_wayland:
|
|
|
|
*
|
|
|
|
* Complete a resize operation from a wayland client.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_window_wayland_move_resize (MetaWindow *window,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int dx,
|
|
|
|
int dy)
|
|
|
|
{
|
2014-04-28 18:15:03 -04:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
2014-05-01 19:09:13 -04:00
|
|
|
int gravity;
|
|
|
|
MetaRectangle rect;
|
2014-04-28 17:44:45 -04:00
|
|
|
MetaMoveResizeFlags flags;
|
|
|
|
|
|
|
|
flags = META_IS_WAYLAND_RESIZE;
|
|
|
|
|
2014-05-01 18:55:34 -04:00
|
|
|
/* x/y are ignored when we're doing interactive resizing */
|
2014-04-28 17:44:45 -04:00
|
|
|
if (!meta_grab_op_is_resizing (window->display->grab_op))
|
|
|
|
{
|
2014-05-01 18:55:34 -04:00
|
|
|
if (wl_window->has_saved_pos)
|
|
|
|
{
|
2014-05-01 19:09:13 -04:00
|
|
|
rect.x = wl_window->saved_x;
|
|
|
|
rect.y = wl_window->saved_y;
|
2014-05-01 18:55:34 -04:00
|
|
|
wl_window->has_saved_pos = FALSE;
|
|
|
|
flags |= META_IS_MOVE_ACTION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-01 19:09:13 -04:00
|
|
|
meta_window_get_position (window, &rect.x, &rect.y);
|
2014-05-01 18:55:34 -04:00
|
|
|
}
|
|
|
|
|
2014-04-28 17:44:45 -04:00
|
|
|
if (dx != 0 || dy != 0)
|
|
|
|
{
|
2014-05-01 19:09:13 -04:00
|
|
|
rect.x += dx;
|
|
|
|
rect.y += dy;
|
2014-04-28 17:44:45 -04:00
|
|
|
flags |= META_IS_MOVE_ACTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-01 19:09:13 -04:00
|
|
|
rect.width = width;
|
|
|
|
rect.height = height;
|
|
|
|
|
|
|
|
if (rect.width != window->rect.width || rect.height != window->rect.height)
|
2014-04-28 17:44:45 -04:00
|
|
|
flags |= META_IS_RESIZE_ACTION;
|
|
|
|
|
2014-05-01 19:09:13 -04:00
|
|
|
gravity = meta_resize_gravity_from_grab_op (window->display->grab_op);
|
|
|
|
meta_window_move_resize_internal (window, flags, gravity, rect);
|
2014-04-28 17:44:45 -04:00
|
|
|
}
|