2011-01-18 15:53:49 +03:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
* Copyright © 2011 Collabora, Ltd.
|
2011-01-18 15:53:49 +03:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2011-09-06 21:48:16 +04:00
|
|
|
#include <stdio.h>
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
#include <stdbool.h>
|
2011-01-18 15:53:49 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2011-04-13 01:25:42 +04:00
|
|
|
#include <linux/input.h>
|
2011-11-03 16:11:32 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <fcntl.h>
|
2011-11-15 15:34:54 +04:00
|
|
|
#include <assert.h>
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
#include "wayland-server.h"
|
|
|
|
#include "compositor.h"
|
2011-09-06 21:48:16 +04:00
|
|
|
#include "desktop-shell-server-protocol.h"
|
2011-01-18 15:53:49 +03:00
|
|
|
|
2011-04-23 21:04:11 +04:00
|
|
|
struct wl_shell {
|
2011-09-06 21:48:16 +04:00
|
|
|
struct wlsc_compositor *compositor;
|
2011-04-23 21:04:11 +04:00
|
|
|
struct wlsc_shell shell;
|
2011-09-06 21:48:16 +04:00
|
|
|
struct wlsc_surface *panel;
|
|
|
|
struct wl_listener panel_listener;
|
|
|
|
struct wlsc_surface *background;
|
|
|
|
struct wl_listener background_listener;
|
2011-11-03 16:11:32 +04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct wlsc_process process;
|
|
|
|
struct wl_client *client;
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
struct wl_resource *desktop_shell;
|
2011-11-03 16:11:32 +04:00
|
|
|
} child;
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
|
|
|
|
bool locked;
|
|
|
|
bool prepare_event_sent;
|
2011-11-15 15:34:54 +04:00
|
|
|
|
2011-11-16 01:39:55 +04:00
|
|
|
struct wlsc_surface *lock_surface;
|
|
|
|
struct wl_listener lock_surface_listener;
|
2011-11-15 15:34:54 +04:00
|
|
|
struct wl_list hidden_surface_list;
|
|
|
|
};
|
|
|
|
|
2011-01-18 15:53:49 +03:00
|
|
|
struct wlsc_move_grab {
|
|
|
|
struct wl_grab grab;
|
2011-01-22 01:00:09 +03:00
|
|
|
struct wlsc_surface *surface;
|
2011-01-18 15:53:49 +03:00
|
|
|
int32_t dx, dy;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_grab_motion(struct wl_grab *grab,
|
|
|
|
uint32_t time, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
struct wlsc_move_grab *move = (struct wlsc_move_grab *) grab;
|
2011-01-22 01:00:09 +03:00
|
|
|
struct wlsc_surface *es = move->surface;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
2011-06-24 05:43:50 +04:00
|
|
|
wlsc_surface_configure(es, x + move->dx, y + move->dy,
|
|
|
|
es->width, es->height);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_grab_button(struct wl_grab *grab,
|
|
|
|
uint32_t time, int32_t button, int32_t state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_grab_end(struct wl_grab *grab, uint32_t time)
|
|
|
|
{
|
|
|
|
free(grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_grab_interface move_grab_interface = {
|
|
|
|
move_grab_motion,
|
|
|
|
move_grab_button,
|
|
|
|
move_grab_end
|
|
|
|
};
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
static int
|
|
|
|
wlsc_surface_move(struct wlsc_surface *es,
|
|
|
|
struct wlsc_input_device *wd, uint32_t time)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
|
|
|
struct wlsc_move_grab *move;
|
|
|
|
|
|
|
|
move = malloc(sizeof *move);
|
2011-08-27 01:21:20 +04:00
|
|
|
if (!move)
|
|
|
|
return -1;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
move->grab.interface = &move_grab_interface;
|
|
|
|
move->dx = es->x - wd->input_device.grab_x;
|
|
|
|
move->dy = es->y - wd->input_device.grab_y;
|
2011-01-22 01:00:09 +03:00
|
|
|
move->surface = es;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
if (wl_input_device_update_grab(&wd->input_device,
|
2011-08-27 01:21:20 +04:00
|
|
|
&move->grab, &es->surface, time) < 0)
|
|
|
|
return 0;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
wlsc_input_device_set_pointer_image(wd, WLSC_POINTER_DRAGGING);
|
2011-08-27 01:21:20 +04:00
|
|
|
wl_input_device_set_pointer_focus(&wd->input_device,
|
|
|
|
NULL, time, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_move(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
struct wl_resource *input_resource, uint32_t time)
|
|
|
|
{
|
|
|
|
struct wlsc_input_device *wd = input_resource->data;
|
|
|
|
struct wlsc_surface *es = surface_resource->data;
|
|
|
|
|
|
|
|
if (wlsc_surface_move(es, wd, time) < 0)
|
2011-09-01 17:54:57 +04:00
|
|
|
wl_resource_post_no_memory(resource);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct wlsc_resize_grab {
|
|
|
|
struct wl_grab grab;
|
|
|
|
uint32_t edges;
|
|
|
|
int32_t dx, dy, width, height;
|
2011-01-22 01:00:09 +03:00
|
|
|
struct wlsc_surface *surface;
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_resource *resource;
|
2011-01-18 15:53:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
resize_grab_motion(struct wl_grab *grab,
|
|
|
|
uint32_t time, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
struct wlsc_resize_grab *resize = (struct wlsc_resize_grab *) grab;
|
|
|
|
struct wl_input_device *device = grab->input_device;
|
2011-01-22 01:00:09 +03:00
|
|
|
struct wl_surface *surface = &resize->surface->surface;
|
2011-01-18 15:53:49 +03:00
|
|
|
int32_t width, height;
|
|
|
|
|
2011-01-22 05:57:55 +03:00
|
|
|
if (resize->edges & WL_SHELL_RESIZE_LEFT) {
|
2011-01-18 15:53:49 +03:00
|
|
|
width = device->grab_x - x + resize->width;
|
2011-01-22 05:57:55 +03:00
|
|
|
} else if (resize->edges & WL_SHELL_RESIZE_RIGHT) {
|
2011-01-18 15:53:49 +03:00
|
|
|
width = x - device->grab_x + resize->width;
|
|
|
|
} else {
|
|
|
|
width = resize->width;
|
|
|
|
}
|
|
|
|
|
2011-01-22 05:57:55 +03:00
|
|
|
if (resize->edges & WL_SHELL_RESIZE_TOP) {
|
2011-01-18 15:53:49 +03:00
|
|
|
height = device->grab_y - y + resize->height;
|
2011-01-22 05:57:55 +03:00
|
|
|
} else if (resize->edges & WL_SHELL_RESIZE_BOTTOM) {
|
2011-01-18 15:53:49 +03:00
|
|
|
height = y - device->grab_y + resize->height;
|
|
|
|
} else {
|
|
|
|
height = resize->height;
|
|
|
|
}
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
wl_resource_post_event(resize->resource,
|
2011-08-19 01:55:30 +04:00
|
|
|
WL_SHELL_CONFIGURE, time, resize->edges,
|
|
|
|
surface, width, height);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
resize_grab_button(struct wl_grab *grab,
|
|
|
|
uint32_t time, int32_t button, int32_t state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
resize_grab_end(struct wl_grab *grab, uint32_t time)
|
|
|
|
{
|
|
|
|
free(grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_grab_interface resize_grab_interface = {
|
|
|
|
resize_grab_motion,
|
|
|
|
resize_grab_button,
|
|
|
|
resize_grab_end
|
|
|
|
};
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
static int
|
|
|
|
wlsc_surface_resize(struct wlsc_surface *es,
|
|
|
|
struct wlsc_input_device *wd,
|
|
|
|
uint32_t time, uint32_t edges,
|
|
|
|
struct wl_resource *resource)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
|
|
|
struct wlsc_resize_grab *resize;
|
|
|
|
enum wlsc_pointer_type pointer = WLSC_POINTER_LEFT_PTR;
|
|
|
|
|
2011-01-28 23:18:33 +03:00
|
|
|
/* FIXME: Reject if fullscreen */
|
|
|
|
|
2011-01-18 15:53:49 +03:00
|
|
|
resize = malloc(sizeof *resize);
|
2011-08-27 01:21:20 +04:00
|
|
|
if (!resize)
|
|
|
|
return -1;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
resize->grab.interface = &resize_grab_interface;
|
|
|
|
resize->edges = edges;
|
|
|
|
resize->dx = es->x - wd->input_device.grab_x;
|
|
|
|
resize->dy = es->y - wd->input_device.grab_y;
|
|
|
|
resize->width = es->width;
|
|
|
|
resize->height = es->height;
|
2011-01-22 01:00:09 +03:00
|
|
|
resize->surface = es;
|
2011-08-27 01:21:20 +04:00
|
|
|
resize->resource = resource;
|
2011-08-19 01:55:30 +04:00
|
|
|
|
2011-01-18 15:53:49 +03:00
|
|
|
if (edges == 0 || edges > 15 ||
|
|
|
|
(edges & 3) == 3 || (edges & 12) == 12)
|
2011-08-27 01:21:20 +04:00
|
|
|
return 0;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
switch (edges) {
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_TOP:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_TOP;
|
|
|
|
break;
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_BOTTOM:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_BOTTOM;
|
|
|
|
break;
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_LEFT:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_LEFT;
|
|
|
|
break;
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_TOP_LEFT:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_TOP_LEFT;
|
|
|
|
break;
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_BOTTOM_LEFT:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_BOTTOM_LEFT;
|
|
|
|
break;
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_RIGHT:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_RIGHT;
|
|
|
|
break;
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_TOP_RIGHT:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_TOP_RIGHT;
|
|
|
|
break;
|
2011-01-22 05:57:55 +03:00
|
|
|
case WL_SHELL_RESIZE_BOTTOM_RIGHT:
|
2011-01-18 15:53:49 +03:00
|
|
|
pointer = WLSC_POINTER_BOTTOM_RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wl_input_device_update_grab(&wd->input_device,
|
2011-08-27 01:21:20 +04:00
|
|
|
&resize->grab, &es->surface, time) < 0)
|
|
|
|
return 0;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
wlsc_input_device_set_pointer_image(wd, pointer);
|
2011-08-27 01:21:20 +04:00
|
|
|
wl_input_device_set_pointer_focus(&wd->input_device,
|
|
|
|
NULL, time, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_resize(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
struct wl_resource *input_resource, uint32_t time, uint32_t edges)
|
|
|
|
{
|
|
|
|
struct wlsc_input_device *wd = input_resource->data;
|
|
|
|
struct wlsc_surface *es = surface_resource->data;
|
|
|
|
|
|
|
|
/* FIXME: Reject if fullscreen */
|
|
|
|
|
|
|
|
if (wlsc_surface_resize(es, wd, time, edges, resource) < 0)
|
2011-09-01 17:54:57 +04:00
|
|
|
wl_resource_post_no_memory(resource);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
2011-06-18 14:12:54 +04:00
|
|
|
static void
|
|
|
|
shell_set_toplevel(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource,
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_resource *surface_resource)
|
2011-06-18 14:12:54 +04:00
|
|
|
|
|
|
|
{
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wlsc_surface *es = surface_resource->data;
|
2011-06-18 14:12:54 +04:00
|
|
|
|
|
|
|
if (es->map_type == WLSC_SURFACE_MAP_FULLSCREEN) {
|
|
|
|
es->x = es->saved_x;
|
|
|
|
es->y = es->saved_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlsc_surface_damage(es);
|
|
|
|
es->map_type = WLSC_SURFACE_MAP_TOPLEVEL;
|
|
|
|
es->fullscreen_output = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_set_transient(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource,
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
struct wl_resource *parent_resource,
|
2011-06-18 14:12:54 +04:00
|
|
|
int x, int y, uint32_t flags)
|
|
|
|
{
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wlsc_surface *es = surface_resource->data;
|
|
|
|
struct wlsc_surface *pes = parent_resource->data;
|
2011-06-18 14:12:54 +04:00
|
|
|
|
|
|
|
/* assign to parents output */
|
|
|
|
es->output = pes->output;
|
|
|
|
|
|
|
|
es->x = pes->x + x;
|
|
|
|
es->y = pes->y + y;
|
|
|
|
|
|
|
|
wlsc_surface_damage(es);
|
|
|
|
es->map_type = WLSC_SURFACE_MAP_TRANSIENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_set_fullscreen(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource,
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_resource *surface_resource)
|
2011-06-18 14:12:54 +04:00
|
|
|
|
|
|
|
{
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wlsc_surface *es = surface_resource->data;
|
2011-06-18 14:12:54 +04:00
|
|
|
struct wlsc_output *output;
|
|
|
|
|
|
|
|
/* FIXME: Fullscreen on first output */
|
|
|
|
/* FIXME: Handle output going away */
|
|
|
|
output = container_of(es->compositor->output_list.next,
|
|
|
|
struct wlsc_output, link);
|
|
|
|
es->output = output;
|
|
|
|
|
|
|
|
es->saved_x = es->x;
|
|
|
|
es->saved_y = es->y;
|
2011-06-21 19:16:58 +04:00
|
|
|
es->x = (output->current->width - es->width) / 2;
|
|
|
|
es->y = (output->current->height - es->height) / 2;
|
2011-06-18 14:12:54 +04:00
|
|
|
es->fullscreen_output = output;
|
|
|
|
wlsc_surface_damage(es);
|
|
|
|
es->map_type = WLSC_SURFACE_MAP_FULLSCREEN;
|
|
|
|
}
|
|
|
|
|
2011-01-18 15:53:49 +03:00
|
|
|
static void
|
2011-08-19 01:55:30 +04:00
|
|
|
destroy_drag(struct wl_resource *resource)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
|
|
|
struct wl_drag *drag =
|
|
|
|
container_of(resource, struct wl_drag, resource);
|
|
|
|
|
|
|
|
wl_list_remove(&drag->drag_focus_listener.link);
|
|
|
|
if (drag->grab.input_device)
|
2011-04-23 21:04:11 +04:00
|
|
|
wl_input_device_end_grab(drag->grab.input_device,
|
|
|
|
wlsc_compositor_get_time());
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
free(drag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
wl_drag_set_pointer_focus(struct wl_drag *drag,
|
|
|
|
struct wl_surface *surface, uint32_t time,
|
|
|
|
int32_t x, int32_t y, int32_t sx, int32_t sy)
|
|
|
|
{
|
|
|
|
char **p, **end;
|
|
|
|
|
|
|
|
if (drag->drag_focus == surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (drag->drag_focus &&
|
2011-08-19 01:55:30 +04:00
|
|
|
(!surface ||
|
|
|
|
drag->drag_focus->resource.client != surface->resource.client))
|
|
|
|
wl_resource_post_event(&drag->drag_offer.resource,
|
2011-01-18 15:53:49 +03:00
|
|
|
WL_DRAG_OFFER_POINTER_FOCUS,
|
|
|
|
time, NULL, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
if (surface &&
|
|
|
|
(!drag->drag_focus ||
|
2011-08-19 01:55:30 +04:00
|
|
|
drag->drag_focus->resource.client != surface->resource.client)) {
|
|
|
|
|
|
|
|
drag->drag_offer.resource.client = surface->resource.client;
|
2011-01-18 15:53:49 +03:00
|
|
|
end = drag->types.data + drag->types.size;
|
|
|
|
for (p = drag->types.data; p < end; p++)
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&drag->drag_offer.resource,
|
|
|
|
WL_DRAG_OFFER_OFFER, *p);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (surface) {
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&drag->drag_offer.resource,
|
|
|
|
WL_DRAG_OFFER_POINTER_FOCUS,
|
|
|
|
time, surface,
|
|
|
|
x, y, sx, sy);
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
drag->drag_focus = surface;
|
|
|
|
drag->pointer_focus_time = time;
|
|
|
|
drag->target = NULL;
|
|
|
|
|
|
|
|
wl_list_remove(&drag->drag_focus_listener.link);
|
|
|
|
if (surface)
|
2011-05-06 19:13:17 +04:00
|
|
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
2011-01-18 15:53:49 +03:00
|
|
|
&drag->drag_focus_listener.link);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-19 01:55:30 +04:00
|
|
|
drag_offer_accept(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t time, const char *type)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_drag_offer *offer = resource->data;
|
2011-01-18 15:53:49 +03:00
|
|
|
struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer);
|
|
|
|
char **p, **end;
|
|
|
|
|
|
|
|
/* If the client responds to drag pointer_focus or motion
|
|
|
|
* events after the pointer has left the surface, we just
|
|
|
|
* discard the accept requests. The drag source just won't
|
|
|
|
* get the corresponding 'target' events and eventually the
|
|
|
|
* next surface/root will start sending events. */
|
|
|
|
if (time < drag->pointer_focus_time)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drag->target = client;
|
|
|
|
drag->type = NULL;
|
|
|
|
end = drag->types.data + drag->types.size;
|
|
|
|
for (p = drag->types.data; p < end; p++)
|
|
|
|
if (type && strcmp(*p, type) == 0)
|
|
|
|
drag->type = *p;
|
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&drag->resource, WL_DRAG_TARGET, drag->type);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_offer_receive(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource, int fd)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_drag_offer *offer = resource->data;
|
2011-01-18 15:53:49 +03:00
|
|
|
struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer);
|
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&drag->resource, WL_DRAG_FINISH, fd);
|
2011-01-18 15:53:49 +03:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-19 01:55:30 +04:00
|
|
|
drag_offer_reject(struct wl_client *client, struct wl_resource *resource)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_drag_offer *offer = resource->data;
|
2011-01-18 15:53:49 +03:00
|
|
|
struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer);
|
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&drag->resource, WL_DRAG_REJECT);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_drag_offer_interface drag_offer_interface = {
|
|
|
|
drag_offer_accept,
|
|
|
|
drag_offer_receive,
|
|
|
|
drag_offer_reject
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2011-08-19 01:55:30 +04:00
|
|
|
drag_offer(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, const char *type)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_drag *drag = resource->data;
|
2011-01-18 15:53:49 +03:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
p = wl_array_add(&drag->types, sizeof *p);
|
|
|
|
if (p)
|
|
|
|
*p = strdup(type);
|
|
|
|
if (!p || !*p)
|
2011-09-01 17:54:57 +04:00
|
|
|
wl_resource_post_no_memory(resource);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_motion(struct wl_grab *grab,
|
|
|
|
uint32_t time, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
struct wl_drag *drag = container_of(grab, struct wl_drag, grab);
|
|
|
|
struct wlsc_surface *es;
|
|
|
|
int32_t sx, sy;
|
|
|
|
|
|
|
|
es = pick_surface(grab->input_device, &sx, &sy);
|
|
|
|
wl_drag_set_pointer_focus(drag, &es->surface, time, x, y, sx, sy);
|
|
|
|
if (es)
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&drag->drag_offer.resource,
|
|
|
|
WL_DRAG_OFFER_MOTION,
|
|
|
|
time, x, y, sx, sy);
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_button(struct wl_grab *grab,
|
|
|
|
uint32_t time, int32_t button, int32_t state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_grab_end(struct wl_grab *grab, uint32_t time)
|
|
|
|
{
|
|
|
|
struct wl_drag *drag = container_of(grab, struct wl_drag, grab);
|
|
|
|
|
|
|
|
if (drag->target)
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&drag->drag_offer.resource,
|
|
|
|
WL_DRAG_OFFER_DROP);
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_grab_interface drag_grab_interface = {
|
|
|
|
drag_grab_motion,
|
|
|
|
drag_grab_button,
|
|
|
|
drag_grab_end
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_activate(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource,
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
struct wl_resource *device_resource, uint32_t time)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_drag *drag = resource->data;
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_surface *surface = surface_resource->data;
|
|
|
|
struct wl_input_device *device = device_resource->data;
|
2011-01-18 15:53:49 +03:00
|
|
|
struct wl_display *display = wl_client_get_display (client);
|
|
|
|
struct wlsc_surface *target;
|
|
|
|
int32_t sx, sy;
|
|
|
|
|
|
|
|
if (wl_input_device_update_grab(device,
|
|
|
|
&drag->grab, surface, time) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drag->grab.interface = &drag_grab_interface;
|
|
|
|
|
|
|
|
drag->source = surface;
|
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
drag->drag_offer.resource.object.interface = &wl_drag_offer_interface;
|
|
|
|
drag->drag_offer.resource.object.implementation =
|
2011-01-18 15:53:49 +03:00
|
|
|
(void (**)(void)) &drag_offer_interface;
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
wl_display_add_global(display, &wl_drag_offer_interface, drag, NULL);
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
target = pick_surface(device, &sx, &sy);
|
2011-01-22 01:00:09 +03:00
|
|
|
wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
|
2011-01-18 15:53:49 +03:00
|
|
|
wl_drag_set_pointer_focus(drag, &target->surface, time,
|
|
|
|
device->x, device->y, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-19 01:55:30 +04:00
|
|
|
drag_destroy(struct wl_client *client, struct wl_resource *resource)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_destroy(resource, wlsc_compositor_get_time());
|
2011-01-18 15:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_drag_interface drag_interface = {
|
|
|
|
drag_offer,
|
|
|
|
drag_activate,
|
|
|
|
drag_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
drag_handle_surface_destroy(struct wl_listener *listener,
|
2011-05-06 19:13:17 +04:00
|
|
|
struct wl_resource *resource, uint32_t time)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
|
|
|
struct wl_drag *drag =
|
|
|
|
container_of(listener, struct wl_drag, drag_focus_listener);
|
2011-05-06 19:13:17 +04:00
|
|
|
struct wl_surface *surface = (struct wl_surface *) resource;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
|
|
|
if (drag->drag_focus == surface)
|
|
|
|
wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_create_drag(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource, uint32_t id)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
|
|
|
struct wl_drag *drag;
|
|
|
|
|
|
|
|
drag = malloc(sizeof *drag);
|
|
|
|
if (drag == NULL) {
|
2011-09-01 17:54:57 +04:00
|
|
|
wl_resource_post_no_memory(resource);
|
2011-01-18 15:53:49 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(drag, 0, sizeof *drag);
|
|
|
|
drag->resource.object.id = id;
|
|
|
|
drag->resource.object.interface = &wl_drag_interface;
|
|
|
|
drag->resource.object.implementation =
|
|
|
|
(void (**)(void)) &drag_interface;
|
|
|
|
|
2011-10-24 18:34:53 +04:00
|
|
|
drag->resource.data = drag;
|
2011-01-18 15:53:49 +03:00
|
|
|
drag->resource.destroy = destroy_drag;
|
|
|
|
|
|
|
|
drag->drag_focus_listener.func = drag_handle_surface_destroy;
|
|
|
|
wl_list_init(&drag->drag_focus_listener.link);
|
|
|
|
|
|
|
|
wl_client_add_resource(client, &drag->resource);
|
|
|
|
}
|
|
|
|
|
2011-05-03 06:09:20 +04:00
|
|
|
static void
|
|
|
|
wlsc_selection_set_focus(struct wlsc_shell *shell,
|
|
|
|
struct wl_selection *selection,
|
2011-01-18 17:08:53 +03:00
|
|
|
struct wl_surface *surface, uint32_t time)
|
|
|
|
{
|
|
|
|
char **p, **end;
|
|
|
|
|
|
|
|
if (selection->selection_focus == surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selection->selection_focus != NULL)
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&selection->selection_offer.resource,
|
2011-01-18 17:08:53 +03:00
|
|
|
WL_SELECTION_OFFER_KEYBOARD_FOCUS,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (surface) {
|
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
selection->selection_offer.resource.client = surface->resource.client;
|
2011-01-18 17:08:53 +03:00
|
|
|
end = selection->types.data + selection->types.size;
|
|
|
|
for (p = selection->types.data; p < end; p++)
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&selection->selection_offer.resource,
|
|
|
|
WL_SELECTION_OFFER_OFFER, *p);
|
2011-01-18 17:08:53 +03:00
|
|
|
|
|
|
|
wl_list_remove(&selection->selection_focus_listener.link);
|
2011-05-06 19:13:17 +04:00
|
|
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
2011-01-18 17:08:53 +03:00
|
|
|
&selection->selection_focus_listener.link);
|
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&selection->selection_offer.resource,
|
|
|
|
WL_SELECTION_OFFER_KEYBOARD_FOCUS,
|
|
|
|
selection->input_device);
|
2011-01-18 17:08:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
selection->selection_focus = surface;
|
|
|
|
|
|
|
|
wl_list_remove(&selection->selection_focus_listener.link);
|
|
|
|
if (surface)
|
2011-05-06 19:13:17 +04:00
|
|
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
2011-01-18 17:08:53 +03:00
|
|
|
&selection->selection_focus_listener.link);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_offer_receive(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource,
|
2011-01-18 17:08:53 +03:00
|
|
|
const char *mime_type, int fd)
|
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_selection_offer *offer = resource->data;
|
2011-01-18 17:08:53 +03:00
|
|
|
struct wl_selection *selection =
|
|
|
|
container_of(offer, struct wl_selection, selection_offer);
|
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&selection->resource,
|
|
|
|
WL_SELECTION_SEND, mime_type, fd);
|
2011-01-18 17:08:53 +03:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_selection_offer_interface selection_offer_interface = {
|
|
|
|
selection_offer_receive
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_offer(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource, const char *type)
|
2011-01-18 17:08:53 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_selection *selection = resource->data;
|
2011-01-18 17:08:53 +03:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
p = wl_array_add(&selection->types, sizeof *p);
|
|
|
|
if (p)
|
|
|
|
*p = strdup(type);
|
|
|
|
if (!p || !*p)
|
2011-09-01 17:54:57 +04:00
|
|
|
wl_resource_post_no_memory(resource);
|
2011-01-18 17:08:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_activate(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource,
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_resource *input_resource, uint32_t time)
|
2011-01-18 17:08:53 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_selection *selection = resource->data;
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wlsc_input_device *wd = input_resource->data;
|
2011-01-18 17:08:53 +03:00
|
|
|
struct wl_display *display = wl_client_get_display (client);
|
2011-05-03 06:09:20 +04:00
|
|
|
struct wlsc_compositor *compositor =
|
2011-08-27 01:21:20 +04:00
|
|
|
(struct wlsc_compositor *) wd->input_device.compositor;
|
2011-01-18 17:08:53 +03:00
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
selection->input_device = &wd->input_device;
|
2011-01-18 17:08:53 +03:00
|
|
|
|
2011-08-19 01:55:30 +04:00
|
|
|
selection->selection_offer.resource.object.interface =
|
2011-01-18 17:08:53 +03:00
|
|
|
&wl_selection_offer_interface;
|
2011-08-19 01:55:30 +04:00
|
|
|
selection->selection_offer.resource.object.implementation =
|
2011-01-18 17:08:53 +03:00
|
|
|
(void (**)(void)) &selection_offer_interface;
|
|
|
|
|
2011-08-19 20:07:44 +04:00
|
|
|
wl_display_add_global(display,
|
2011-08-27 01:21:20 +04:00
|
|
|
&wl_selection_offer_interface, selection, NULL);
|
2011-01-18 17:08:53 +03:00
|
|
|
|
|
|
|
if (wd->selection) {
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_post_event(&wd->selection->resource,
|
|
|
|
WL_SELECTION_CANCELLED);
|
2011-01-18 17:08:53 +03:00
|
|
|
}
|
|
|
|
wd->selection = selection;
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
wlsc_selection_set_focus(compositor->shell, selection,
|
|
|
|
wd->input_device.keyboard_focus, time);
|
2011-01-18 17:08:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-19 01:55:30 +04:00
|
|
|
selection_destroy(struct wl_client *client, struct wl_resource *resource)
|
2011-01-18 17:08:53 +03:00
|
|
|
{
|
2011-08-19 01:55:30 +04:00
|
|
|
wl_resource_destroy(resource, wlsc_compositor_get_time());
|
2011-01-18 17:08:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_selection_interface selection_interface = {
|
|
|
|
selection_offer,
|
|
|
|
selection_activate,
|
|
|
|
selection_destroy
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2011-08-19 01:55:30 +04:00
|
|
|
destroy_selection(struct wl_resource *resource)
|
2011-01-18 17:08:53 +03:00
|
|
|
{
|
|
|
|
struct wl_selection *selection =
|
|
|
|
container_of(resource, struct wl_selection, resource);
|
|
|
|
struct wlsc_input_device *wd =
|
|
|
|
(struct wlsc_input_device *) selection->input_device;
|
2011-05-03 06:09:20 +04:00
|
|
|
struct wlsc_compositor *compositor =
|
|
|
|
(struct wlsc_compositor *) wd->input_device.compositor;
|
2011-01-18 17:08:53 +03:00
|
|
|
|
|
|
|
if (wd && wd->selection == selection) {
|
|
|
|
wd->selection = NULL;
|
2011-05-03 06:09:20 +04:00
|
|
|
wlsc_selection_set_focus(compositor->shell,
|
|
|
|
selection, NULL,
|
2011-04-23 21:04:11 +04:00
|
|
|
wlsc_compositor_get_time());
|
2011-01-18 17:08:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove(&selection->selection_focus_listener.link);
|
|
|
|
free(selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
selection_handle_surface_destroy(struct wl_listener *listener,
|
2011-05-06 19:13:17 +04:00
|
|
|
struct wl_resource *resource, uint32_t time)
|
2011-01-18 17:08:53 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_create_selection(struct wl_client *client,
|
2011-08-19 01:55:30 +04:00
|
|
|
struct wl_resource *resource, uint32_t id)
|
2011-01-18 17:08:53 +03:00
|
|
|
{
|
|
|
|
struct wl_selection *selection;
|
|
|
|
|
|
|
|
selection = malloc(sizeof *selection);
|
|
|
|
if (selection == NULL) {
|
2011-09-01 17:54:57 +04:00
|
|
|
wl_resource_post_no_memory(resource);
|
2011-01-18 17:08:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(selection, 0, sizeof *selection);
|
|
|
|
selection->resource.object.id = id;
|
|
|
|
selection->resource.object.interface = &wl_selection_interface;
|
|
|
|
selection->resource.object.implementation =
|
|
|
|
(void (**)(void)) &selection_interface;
|
|
|
|
|
|
|
|
selection->client = client;
|
|
|
|
selection->resource.destroy = destroy_selection;
|
|
|
|
selection->selection_focus = NULL;
|
|
|
|
|
|
|
|
selection->selection_focus_listener.func =
|
|
|
|
selection_handle_surface_destroy;
|
|
|
|
wl_list_init(&selection->selection_focus_listener.link);
|
|
|
|
|
|
|
|
wl_client_add_resource(client, &selection->resource);
|
|
|
|
}
|
|
|
|
|
2011-09-06 21:48:16 +04:00
|
|
|
static const struct wl_shell_interface shell_interface = {
|
2011-01-18 15:53:49 +03:00
|
|
|
shell_move,
|
|
|
|
shell_resize,
|
2011-01-18 17:08:53 +03:00
|
|
|
shell_create_drag,
|
2011-06-18 14:12:54 +04:00
|
|
|
shell_create_selection,
|
|
|
|
shell_set_toplevel,
|
|
|
|
shell_set_transient,
|
|
|
|
shell_set_fullscreen
|
2011-01-18 15:53:49 +03:00
|
|
|
};
|
|
|
|
|
2011-09-06 21:48:16 +04:00
|
|
|
static void
|
|
|
|
handle_background_surface_destroy(struct wl_listener *listener,
|
|
|
|
struct wl_resource *resource, uint32_t time)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell =
|
|
|
|
container_of(listener, struct wl_shell, background_listener);
|
|
|
|
|
|
|
|
fprintf(stderr, "background surface gone\n");
|
|
|
|
shell->background = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
desktop_shell_set_background(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = resource->data;
|
|
|
|
struct wlsc_surface *surface = surface_resource->data;
|
|
|
|
struct wlsc_output *output =
|
|
|
|
container_of(shell->compositor->output_list.next,
|
|
|
|
struct wlsc_output, link);
|
|
|
|
|
|
|
|
shell->background = surface_resource->data;
|
|
|
|
shell->background_listener.func = handle_background_surface_destroy;
|
|
|
|
wl_list_insert(&surface_resource->destroy_listener_list,
|
|
|
|
&shell->background_listener.link);
|
|
|
|
|
|
|
|
wl_resource_post_event(resource,
|
|
|
|
DESKTOP_SHELL_CONFIGURE,
|
|
|
|
wlsc_compositor_get_time(), 0, surface,
|
|
|
|
output->current->width,
|
|
|
|
output->current->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_panel_surface_destroy(struct wl_listener *listener,
|
|
|
|
struct wl_resource *resource, uint32_t time)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell =
|
|
|
|
container_of(listener, struct wl_shell, panel_listener);
|
|
|
|
|
|
|
|
fprintf(stderr, "panel surface gone\n");
|
|
|
|
shell->panel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
desktop_shell_set_panel(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = resource->data;
|
|
|
|
struct wlsc_output *output =
|
|
|
|
container_of(shell->compositor->output_list.next,
|
|
|
|
struct wlsc_output, link);
|
|
|
|
|
|
|
|
shell->panel = surface_resource->data;
|
|
|
|
|
|
|
|
shell->panel_listener.func = handle_panel_surface_destroy;
|
|
|
|
wl_list_insert(&surface_resource->destroy_listener_list,
|
|
|
|
&shell->panel_listener.link);
|
|
|
|
|
|
|
|
wl_resource_post_event(resource,
|
|
|
|
DESKTOP_SHELL_CONFIGURE,
|
|
|
|
wlsc_compositor_get_time(), 0, surface_resource,
|
|
|
|
output->current->width,
|
|
|
|
output->current->height);
|
|
|
|
}
|
|
|
|
|
2011-11-16 01:39:55 +04:00
|
|
|
static void
|
|
|
|
handle_lock_surface_destroy(struct wl_listener *listener,
|
|
|
|
struct wl_resource *resource, uint32_t time)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell =
|
|
|
|
container_of(listener, struct wl_shell, panel_listener);
|
|
|
|
|
|
|
|
fprintf(stderr, "lock surface gone\n");
|
|
|
|
shell->lock_surface = NULL;
|
|
|
|
}
|
|
|
|
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
static void
|
|
|
|
desktop_shell_set_lock_surface(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource)
|
|
|
|
{
|
2011-11-15 15:34:49 +04:00
|
|
|
struct wl_shell *shell = resource->data;
|
2011-11-15 15:34:54 +04:00
|
|
|
|
|
|
|
shell->prepare_event_sent = false;
|
|
|
|
|
|
|
|
if (!shell->locked)
|
|
|
|
return;
|
2011-11-15 15:34:49 +04:00
|
|
|
|
2011-11-16 01:39:55 +04:00
|
|
|
shell->lock_surface = surface_resource->data;
|
2011-11-15 15:34:49 +04:00
|
|
|
|
2011-11-16 01:39:55 +04:00
|
|
|
shell->lock_surface_listener.func = handle_lock_surface_destroy;
|
|
|
|
wl_list_insert(&surface_resource->destroy_listener_list,
|
|
|
|
&shell->lock_surface_listener.link);
|
2011-11-15 15:34:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
resume_desktop(struct wl_shell *shell)
|
|
|
|
{
|
2011-11-16 01:39:55 +04:00
|
|
|
struct wlsc_surface *surface;
|
2011-11-15 15:34:54 +04:00
|
|
|
|
2011-11-16 01:39:55 +04:00
|
|
|
wl_list_for_each(surface, &shell->hidden_surface_list, link)
|
|
|
|
wlsc_surface_configure(surface, surface->x, surface->y,
|
|
|
|
surface->width, surface->height);
|
|
|
|
|
|
|
|
wl_list_insert_list(shell->background->link.prev,
|
|
|
|
&shell->hidden_surface_list);
|
|
|
|
wl_list_init(&shell->hidden_surface_list);
|
2011-11-15 15:34:54 +04:00
|
|
|
|
|
|
|
shell->locked = false;
|
|
|
|
wlsc_compositor_repick(shell->compositor);
|
2011-11-15 15:34:49 +04:00
|
|
|
wlsc_compositor_wake(shell->compositor);
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
desktop_shell_unlock(struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = resource->data;
|
|
|
|
|
|
|
|
shell->prepare_event_sent = false;
|
2011-11-15 15:34:54 +04:00
|
|
|
|
|
|
|
if (shell->locked)
|
|
|
|
resume_desktop(shell);
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-06 21:48:16 +04:00
|
|
|
static const struct desktop_shell_interface desktop_shell_implementation = {
|
|
|
|
desktop_shell_set_background,
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
desktop_shell_set_panel,
|
|
|
|
desktop_shell_set_lock_surface,
|
|
|
|
desktop_shell_unlock
|
2011-09-06 21:48:16 +04:00
|
|
|
};
|
|
|
|
|
2011-04-13 01:25:42 +04:00
|
|
|
static void
|
|
|
|
move_binding(struct wl_input_device *device, uint32_t time,
|
|
|
|
uint32_t key, uint32_t button, uint32_t state, void *data)
|
|
|
|
{
|
2011-09-06 21:48:16 +04:00
|
|
|
struct wl_shell *shell = data;
|
2011-04-13 01:25:42 +04:00
|
|
|
struct wlsc_surface *surface =
|
|
|
|
(struct wlsc_surface *) device->pointer_focus;
|
|
|
|
|
2011-09-09 00:56:57 +04:00
|
|
|
if (surface == NULL ||
|
|
|
|
surface->map_type == WLSC_SURFACE_MAP_FULLSCREEN)
|
2011-04-13 19:52:54 +04:00
|
|
|
return;
|
2011-09-06 21:48:16 +04:00
|
|
|
if (surface == shell->panel)
|
|
|
|
return;
|
|
|
|
if (surface == shell->background)
|
|
|
|
return;
|
2011-04-13 19:52:54 +04:00
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
wlsc_surface_move(surface, (struct wlsc_input_device *) device, time);
|
2011-04-13 01:25:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
resize_binding(struct wl_input_device *device, uint32_t time,
|
|
|
|
uint32_t key, uint32_t button, uint32_t state, void *data)
|
|
|
|
{
|
2011-09-06 21:48:16 +04:00
|
|
|
struct wl_shell *shell = data;
|
2011-04-13 01:25:42 +04:00
|
|
|
struct wlsc_surface *surface =
|
|
|
|
(struct wlsc_surface *) device->pointer_focus;
|
2011-08-27 01:21:20 +04:00
|
|
|
struct wl_resource *resource;
|
2011-04-13 01:25:42 +04:00
|
|
|
uint32_t edges = 0;
|
|
|
|
int32_t x, y;
|
|
|
|
|
2011-09-09 00:56:57 +04:00
|
|
|
if (surface == NULL ||
|
|
|
|
surface->map_type == WLSC_SURFACE_MAP_FULLSCREEN)
|
2011-09-06 21:48:16 +04:00
|
|
|
if (surface == shell->panel)
|
|
|
|
return;
|
|
|
|
if (surface == shell->background)
|
|
|
|
return;
|
2011-04-13 19:52:54 +04:00
|
|
|
|
2011-04-13 01:25:42 +04:00
|
|
|
x = device->grab_x - surface->x;
|
|
|
|
y = device->grab_y - surface->y;
|
|
|
|
|
|
|
|
if (x < surface->width / 3)
|
|
|
|
edges |= WL_SHELL_RESIZE_LEFT;
|
|
|
|
else if (x < 2 * surface->width / 3)
|
|
|
|
edges |= 0;
|
|
|
|
else
|
|
|
|
edges |= WL_SHELL_RESIZE_RIGHT;
|
|
|
|
|
|
|
|
if (y < surface->height / 3)
|
|
|
|
edges |= WL_SHELL_RESIZE_TOP;
|
|
|
|
else if (y < 2 * surface->height / 3)
|
|
|
|
edges |= 0;
|
|
|
|
else
|
|
|
|
edges |= WL_SHELL_RESIZE_BOTTOM;
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
resource = /* Find shell resource for surface client */ 0;
|
|
|
|
|
|
|
|
/* ... or use wl_shell_surface */
|
|
|
|
|
|
|
|
wlsc_surface_resize(surface, (struct wlsc_input_device *) device,
|
|
|
|
time, edges, resource);
|
2011-04-23 21:04:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-06 21:48:16 +04:00
|
|
|
static void
|
|
|
|
activate(struct wlsc_shell *base, struct wlsc_surface *es,
|
|
|
|
struct wlsc_input_device *device, uint32_t time)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = container_of(base, struct wl_shell, shell);
|
|
|
|
struct wlsc_compositor *compositor = shell->compositor;
|
|
|
|
|
|
|
|
wlsc_surface_activate(es, device, time);
|
|
|
|
|
2011-10-12 07:41:17 +04:00
|
|
|
if (compositor->wxs)
|
|
|
|
wlsc_xserver_surface_activate(es);
|
|
|
|
|
2011-09-06 21:48:16 +04:00
|
|
|
if (es == shell->background) {
|
|
|
|
wl_list_remove(&es->link);
|
|
|
|
wl_list_insert(compositor->surface_list.prev, &es->link);
|
2011-11-15 15:34:54 +04:00
|
|
|
} else if (shell->panel && !shell->locked) {
|
2011-09-06 21:48:16 +04:00
|
|
|
wl_list_remove(&shell->panel->link);
|
|
|
|
wl_list_insert(&compositor->surface_list, &shell->panel->link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 21:04:11 +04:00
|
|
|
static void
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
lock(struct wlsc_shell *base)
|
2011-04-23 21:04:11 +04:00
|
|
|
{
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
struct wl_shell *shell = container_of(base, struct wl_shell, shell);
|
2011-11-15 15:34:54 +04:00
|
|
|
struct wl_list *surface_list = &shell->compositor->surface_list;
|
|
|
|
struct wlsc_surface *cur;
|
|
|
|
struct wlsc_surface *tmp;
|
|
|
|
struct wlsc_input_device *device;
|
|
|
|
uint32_t time;
|
|
|
|
|
|
|
|
if (shell->locked)
|
|
|
|
return;
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
|
|
|
|
shell->locked = true;
|
2011-11-15 15:34:54 +04:00
|
|
|
|
|
|
|
/* Move all surfaces from compositor's list to our hidden list,
|
|
|
|
* except the background. This way nothing else can show or
|
|
|
|
* receive input events while we are locked. */
|
|
|
|
|
|
|
|
if (!wl_list_empty(&shell->hidden_surface_list)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Assertion failed: hidden_surface_list is not empty.\n",
|
|
|
|
__func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each_safe(cur, tmp, surface_list, link) {
|
|
|
|
/* skip input device sprites, cur->surface is uninitialised */
|
|
|
|
if (cur->surface.resource.client == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cur == shell->background)
|
|
|
|
continue;
|
|
|
|
|
2011-11-16 01:39:55 +04:00
|
|
|
cur->output = NULL;
|
2011-11-15 15:34:54 +04:00
|
|
|
wl_list_remove(&cur->link);
|
2011-11-16 01:39:55 +04:00
|
|
|
wl_list_insert(shell->hidden_surface_list.prev, &cur->link);
|
2011-11-15 15:34:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reset pointer foci */
|
|
|
|
wlsc_compositor_repick(shell->compositor);
|
|
|
|
|
|
|
|
/* reset keyboard foci */
|
|
|
|
time = wlsc_compositor_get_time();
|
|
|
|
wl_list_for_each(device, &shell->compositor->input_device_list, link) {
|
|
|
|
wl_input_device_set_keyboard_focus(&device->input_device,
|
|
|
|
NULL, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: disable bindings that should not work while locked. */
|
|
|
|
|
|
|
|
/* All this must be undone in resume_desktop(). */
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unlock(struct wlsc_shell *base)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = container_of(base, struct wl_shell, shell);
|
|
|
|
|
|
|
|
if (!shell->locked) {
|
|
|
|
wlsc_compositor_wake(shell->compositor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If desktop-shell client has gone away, unlock immediately. */
|
|
|
|
if (!shell->child.desktop_shell) {
|
2011-11-15 15:34:54 +04:00
|
|
|
resume_desktop(shell);
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shell->prepare_event_sent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_resource_post_event(shell->child.desktop_shell,
|
|
|
|
DESKTOP_SHELL_PREPARE_LOCK_SURFACE);
|
|
|
|
shell->prepare_event_sent = true;
|
2011-04-23 21:04:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-09 21:07:35 +04:00
|
|
|
map(struct wlsc_shell *base,
|
|
|
|
struct wlsc_surface *surface, int32_t width, int32_t height)
|
2011-04-23 21:04:11 +04:00
|
|
|
{
|
2011-09-06 21:48:16 +04:00
|
|
|
struct wl_shell *shell = container_of(base, struct wl_shell, shell);
|
|
|
|
struct wlsc_compositor *compositor = shell->compositor;
|
2011-11-16 01:39:55 +04:00
|
|
|
struct wl_list *list;
|
|
|
|
|
|
|
|
if (shell->locked)
|
|
|
|
list = &shell->hidden_surface_list;
|
|
|
|
else
|
|
|
|
list = &compositor->surface_list;
|
2011-09-06 21:48:16 +04:00
|
|
|
|
2011-11-09 21:07:35 +04:00
|
|
|
/* Map background at the bottom of the stack, panel on top,
|
|
|
|
everything else just below panel. */
|
2011-11-15 15:34:54 +04:00
|
|
|
if (surface == shell->background) {
|
2011-11-09 21:07:35 +04:00
|
|
|
wl_list_insert(compositor->surface_list.prev, &surface->link);
|
2011-11-16 01:39:55 +04:00
|
|
|
} else if (surface == shell->panel) {
|
|
|
|
wl_list_insert(list, &surface->link);
|
|
|
|
} else if (surface == shell->lock_surface) {
|
|
|
|
wl_list_insert(&compositor->surface_list, &surface->link);
|
|
|
|
wlsc_compositor_repick(compositor);
|
|
|
|
wlsc_compositor_wake(compositor);
|
2011-11-15 15:34:54 +04:00
|
|
|
} else {
|
2011-11-16 01:39:55 +04:00
|
|
|
wl_list_insert(&shell->panel->link, &surface->link);
|
2011-11-15 15:34:54 +04:00
|
|
|
}
|
|
|
|
|
2011-11-09 21:38:53 +04:00
|
|
|
if (surface->map_type == WLSC_SURFACE_MAP_TOPLEVEL) {
|
|
|
|
surface->x = 10 + random() % 400;
|
|
|
|
surface->y = 10 + random() % 400;
|
|
|
|
}
|
|
|
|
|
2011-11-16 01:39:55 +04:00
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
|
|
|
if (!shell->locked)
|
|
|
|
wlsc_surface_configure(surface,
|
|
|
|
surface->x, surface->y, width, height);
|
2011-11-09 21:07:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
configure(struct wlsc_shell *shell, struct wlsc_surface *surface,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
struct wlsc_mode *current;
|
|
|
|
|
|
|
|
if (surface->map_type == WLSC_SURFACE_MAP_FULLSCREEN) {
|
|
|
|
current = surface->fullscreen_output->current;
|
|
|
|
x = (current->width - surface->width) / 2;
|
|
|
|
y = (current->height - surface->height) / 2;
|
2011-06-18 14:12:54 +04:00
|
|
|
}
|
2011-11-09 21:07:35 +04:00
|
|
|
|
|
|
|
wlsc_surface_configure(surface, x, y, width, height);
|
2011-04-13 01:25:42 +04:00
|
|
|
}
|
|
|
|
|
2011-11-03 16:11:32 +04:00
|
|
|
static void
|
|
|
|
desktop_shell_sigchld(struct wlsc_process *process, int status)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell =
|
|
|
|
container_of(process, struct wl_shell, child.process);
|
|
|
|
|
|
|
|
shell->child.process.pid = 0;
|
|
|
|
shell->child.client = NULL; /* already destroyed by wayland */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
launch_desktop_shell_process(struct wl_shell *shell)
|
|
|
|
{
|
2011-11-14 23:57:17 +04:00
|
|
|
const char *shell_exe = LIBEXECDIR "/wayland-desktop-shell";
|
2011-11-03 16:11:32 +04:00
|
|
|
struct wlsc_compositor *compositor = shell->compositor;
|
|
|
|
char s[32];
|
|
|
|
int sv[2], flags;
|
|
|
|
|
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
|
|
|
|
fprintf(stderr, "socketpair failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
shell->child.process.pid = fork();
|
|
|
|
shell->child.process.cleanup = desktop_shell_sigchld;
|
|
|
|
|
|
|
|
switch (shell->child.process.pid) {
|
|
|
|
case 0:
|
|
|
|
/* SOCK_CLOEXEC closes both ends, so we need to unset
|
|
|
|
* the flag on the client fd. */
|
|
|
|
flags = fcntl(sv[1], F_GETFD);
|
|
|
|
if (flags != -1)
|
|
|
|
fcntl(sv[1], F_SETFD, flags & ~FD_CLOEXEC);
|
|
|
|
|
|
|
|
snprintf(s, sizeof s, "%d", sv[1]);
|
|
|
|
setenv("WAYLAND_SOCKET", s, 1);
|
|
|
|
if (execl(shell_exe, shell_exe, NULL) < 0)
|
|
|
|
fprintf(stderr, "%s: running '%s' failed: %m\n",
|
|
|
|
__func__, shell_exe);
|
|
|
|
exit(-1);
|
|
|
|
|
|
|
|
default:
|
|
|
|
close(sv[1]);
|
|
|
|
shell->child.client =
|
|
|
|
wl_client_create(compositor->wl_display, sv[0]);
|
|
|
|
wlsc_watch_process(&shell->child.process);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
fprintf(stderr, "%s: fork failed: %m\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
static void
|
|
|
|
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = data;
|
|
|
|
|
|
|
|
wl_client_add_object(client, &wl_shell_interface,
|
|
|
|
&shell_interface, id, shell);
|
|
|
|
}
|
|
|
|
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
static void
|
|
|
|
unbind_desktop_shell(struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = resource->data;
|
2011-11-16 01:39:55 +04:00
|
|
|
|
|
|
|
if (shell->locked)
|
|
|
|
resume_desktop(shell);
|
|
|
|
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
shell->child.desktop_shell = NULL;
|
|
|
|
shell->prepare_event_sent = false;
|
|
|
|
free(resource);
|
|
|
|
}
|
|
|
|
|
2011-09-06 21:48:16 +04:00
|
|
|
static void
|
|
|
|
bind_desktop_shell(struct wl_client *client,
|
|
|
|
void *data, uint32_t version, uint32_t id)
|
|
|
|
{
|
|
|
|
struct wl_shell *shell = data;
|
2011-11-03 16:11:33 +04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource = wl_client_add_object(client, &desktop_shell_interface,
|
|
|
|
&desktop_shell_implementation,
|
|
|
|
id, shell);
|
|
|
|
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
if (client == shell->child.client) {
|
|
|
|
resource->destroy = unbind_desktop_shell;
|
|
|
|
shell->child.desktop_shell = resource;
|
2011-11-03 16:11:33 +04:00
|
|
|
return;
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
}
|
2011-09-06 21:48:16 +04:00
|
|
|
|
2011-11-03 16:11:33 +04:00
|
|
|
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"permission to bind desktop_shell denied");
|
|
|
|
wl_resource_destroy(resource, 0);
|
2011-09-06 21:48:16 +04:00
|
|
|
}
|
|
|
|
|
2011-05-06 22:52:41 +04:00
|
|
|
int
|
|
|
|
shell_init(struct wlsc_compositor *ec);
|
|
|
|
|
2011-05-03 06:09:20 +04:00
|
|
|
WL_EXPORT int
|
|
|
|
shell_init(struct wlsc_compositor *ec)
|
2011-01-18 15:53:49 +03:00
|
|
|
{
|
2011-04-23 21:04:11 +04:00
|
|
|
struct wl_shell *shell;
|
|
|
|
|
|
|
|
shell = malloc(sizeof *shell);
|
|
|
|
if (shell == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2011-10-12 06:44:23 +04:00
|
|
|
memset(shell, 0, sizeof *shell);
|
2011-09-06 21:48:16 +04:00
|
|
|
shell->compositor = ec;
|
|
|
|
shell->shell.activate = activate;
|
2011-04-23 21:04:11 +04:00
|
|
|
shell->shell.lock = lock;
|
desktop-shell: screen locking protocol
Add protocol and functions for supporting screen locking, triggered by
activity timeout.
After activity timeout, compositor starts the fade to black, and then
enters SLEEPING state. At that point it calls lock() in the shell
plugin.
When input events trigger a wakeup, unlock() in the shell plugin is
called. This sends prepare_lock_surface event to the desktop-shell
client. The screen stays locked while the compositor starts fade-in.
At this point, desktop-shell client usually creates a surface for the
unlocking GUI (e.g. a password prompt), and sends it with the
set_lock_surface request. The compositor supposedly shows and allows
interaction only with the given lock surface (not yet implemented).
When desktop-shell has authenticated the user, or instead of issuing
set_lock_surface, it sends the unlock request. Upon receiving the unlock
request, the shell plugin unlocks the screen.
If desktop-shell client dies, the screen is unlocked automatically.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2011-11-15 15:34:48 +04:00
|
|
|
shell->shell.unlock = unlock;
|
2011-11-09 21:07:35 +04:00
|
|
|
shell->shell.map = map;
|
|
|
|
shell->shell.configure = configure;
|
2011-05-03 06:09:20 +04:00
|
|
|
shell->shell.set_selection_focus = wlsc_selection_set_focus;
|
2011-01-18 15:53:49 +03:00
|
|
|
|
2011-11-15 15:34:54 +04:00
|
|
|
wl_list_init(&shell->hidden_surface_list);
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
if (wl_display_add_global(ec->wl_display, &wl_shell_interface,
|
|
|
|
shell, bind_shell) == NULL)
|
2011-01-18 15:53:49 +03:00
|
|
|
return -1;
|
|
|
|
|
2011-09-06 21:48:16 +04:00
|
|
|
if (wl_display_add_global(ec->wl_display,
|
|
|
|
&desktop_shell_interface,
|
|
|
|
shell, bind_desktop_shell) == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2011-11-03 16:11:32 +04:00
|
|
|
if (launch_desktop_shell_process(shell) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2011-04-13 01:25:42 +04:00
|
|
|
wlsc_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
|
2011-04-23 21:04:11 +04:00
|
|
|
move_binding, shell);
|
2011-04-13 01:25:42 +04:00
|
|
|
wlsc_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
|
2011-04-23 21:04:11 +04:00
|
|
|
resize_binding, shell);
|
|
|
|
|
|
|
|
ec->shell = &shell->shell;
|
2011-04-13 01:25:42 +04:00
|
|
|
|
2011-01-18 15:53:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|