2014-09-27 11:52:59 -06:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Intel Corporation
|
|
|
|
* Copyright © 2011 Kristian Høgsberg
|
|
|
|
*
|
|
|
|
* 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 "xwayland.h"
|
|
|
|
|
|
|
|
#include <mipointer.h>
|
|
|
|
|
|
|
|
static DevPrivateKeyRec xwl_cursor_private_key;
|
|
|
|
|
|
|
|
static void
|
|
|
|
expand_source_and_mask(CursorPtr cursor, CARD32 *data)
|
|
|
|
{
|
|
|
|
CARD32 *p, d, fg, bg;
|
|
|
|
CursorBitsPtr bits = cursor->bits;
|
|
|
|
int x, y, stride, i, bit;
|
|
|
|
|
|
|
|
p = data;
|
|
|
|
fg = ((cursor->foreRed & 0xff00) << 8) |
|
|
|
|
(cursor->foreGreen & 0xff00) | (cursor->foreGreen >> 8);
|
|
|
|
bg = ((cursor->backRed & 0xff00) << 8) |
|
|
|
|
(cursor->backGreen & 0xff00) | (cursor->backGreen >> 8);
|
2018-02-18 10:16:37 -07:00
|
|
|
stride = BitmapBytePad(bits->width);
|
2014-09-27 11:52:59 -06:00
|
|
|
for (y = 0; y < bits->height; y++)
|
|
|
|
for (x = 0; x < bits->width; x++) {
|
|
|
|
i = y * stride + x / 8;
|
|
|
|
bit = 1 << (x & 7);
|
|
|
|
if (bits->source[i] & bit)
|
|
|
|
d = fg;
|
|
|
|
else
|
|
|
|
d = bg;
|
|
|
|
if (bits->mask[i] & bit)
|
|
|
|
d |= 0xff000000;
|
|
|
|
else
|
|
|
|
d = 0x00000000;
|
|
|
|
|
|
|
|
*p++ = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
xwl_realize_cursor(DeviceIntPtr device, ScreenPtr screen, CursorPtr cursor)
|
|
|
|
{
|
|
|
|
PixmapPtr pixmap;
|
|
|
|
|
|
|
|
pixmap = xwl_shm_create_pixmap(screen, cursor->bits->width,
|
|
|
|
cursor->bits->height, 32, 0);
|
|
|
|
dixSetPrivate(&cursor->devPrivates, &xwl_cursor_private_key, pixmap);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
xwl_unrealize_cursor(DeviceIntPtr device, ScreenPtr screen, CursorPtr cursor)
|
|
|
|
{
|
|
|
|
PixmapPtr pixmap;
|
2017-12-08 08:01:59 -07:00
|
|
|
struct xwl_screen *xwl_screen;
|
2016-08-09 12:59:50 -06:00
|
|
|
struct xwl_seat *xwl_seat;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
pixmap = dixGetPrivate(&cursor->devPrivates, &xwl_cursor_private_key);
|
2016-08-09 12:59:50 -06:00
|
|
|
if (!pixmap)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
dixSetPrivate(&cursor->devPrivates, &xwl_cursor_private_key, NULL);
|
|
|
|
|
|
|
|
/* When called from FreeCursor(), device is always NULL */
|
2017-12-08 08:01:59 -07:00
|
|
|
xwl_screen = xwl_screen_get(screen);
|
|
|
|
xorg_list_for_each_entry(xwl_seat, &xwl_screen->seat_list, link) {
|
|
|
|
if (cursor == xwl_seat->x_cursor)
|
2016-08-09 12:59:50 -06:00
|
|
|
xwl_seat->x_cursor = NULL;
|
|
|
|
}
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
return xwl_shm_destroy_pixmap(pixmap);
|
|
|
|
}
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
static void
|
|
|
|
clear_cursor_frame_callback(struct xwl_seat *xwl_seat)
|
|
|
|
{
|
|
|
|
if (xwl_seat->cursor_frame_cb) {
|
|
|
|
wl_callback_destroy (xwl_seat->cursor_frame_cb);
|
|
|
|
xwl_seat->cursor_frame_cb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
static void
|
|
|
|
frame_callback(void *data,
|
|
|
|
struct wl_callback *callback,
|
|
|
|
uint32_t time)
|
|
|
|
{
|
|
|
|
struct xwl_seat *xwl_seat = data;
|
2017-12-08 08:01:59 -07:00
|
|
|
|
|
|
|
clear_cursor_frame_callback(xwl_seat);
|
2015-09-16 13:10:19 -06:00
|
|
|
if (xwl_seat->cursor_needs_update) {
|
|
|
|
xwl_seat->cursor_needs_update = FALSE;
|
|
|
|
xwl_seat_set_cursor(xwl_seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener = {
|
|
|
|
frame_callback
|
|
|
|
};
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
void
|
|
|
|
xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
|
|
|
|
{
|
|
|
|
PixmapPtr pixmap;
|
|
|
|
CursorPtr cursor;
|
|
|
|
int stride;
|
|
|
|
|
|
|
|
if (!xwl_seat->wl_pointer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!xwl_seat->x_cursor) {
|
|
|
|
wl_pointer_set_cursor(xwl_seat->wl_pointer,
|
|
|
|
xwl_seat->pointer_enter_serial, NULL, 0, 0);
|
2017-12-08 08:01:59 -07:00
|
|
|
clear_cursor_frame_callback(xwl_seat);
|
|
|
|
xwl_seat->cursor_needs_update = FALSE;
|
2014-09-27 11:52:59 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
if (xwl_seat->cursor_frame_cb) {
|
|
|
|
xwl_seat->cursor_needs_update = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
cursor = xwl_seat->x_cursor;
|
|
|
|
pixmap = dixGetPrivate(&cursor->devPrivates, &xwl_cursor_private_key);
|
2016-08-09 12:59:50 -06:00
|
|
|
if (!pixmap)
|
|
|
|
return;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
stride = cursor->bits->width * 4;
|
|
|
|
if (cursor->bits->argb)
|
|
|
|
memcpy(pixmap->devPrivate.ptr,
|
|
|
|
cursor->bits->argb, cursor->bits->height * stride);
|
|
|
|
else
|
|
|
|
expand_source_and_mask(cursor, pixmap->devPrivate.ptr);
|
|
|
|
|
|
|
|
wl_pointer_set_cursor(xwl_seat->wl_pointer,
|
|
|
|
xwl_seat->pointer_enter_serial,
|
|
|
|
xwl_seat->cursor,
|
|
|
|
xwl_seat->x_cursor->bits->xhot,
|
|
|
|
xwl_seat->x_cursor->bits->yhot);
|
|
|
|
wl_surface_attach(xwl_seat->cursor,
|
|
|
|
xwl_shm_pixmap_get_wl_buffer(pixmap), 0, 0);
|
|
|
|
wl_surface_damage(xwl_seat->cursor, 0, 0,
|
|
|
|
xwl_seat->x_cursor->bits->width,
|
|
|
|
xwl_seat->x_cursor->bits->height);
|
2015-09-16 13:10:19 -06:00
|
|
|
|
|
|
|
xwl_seat->cursor_frame_cb = wl_surface_frame(xwl_seat->cursor);
|
|
|
|
wl_callback_add_listener(xwl_seat->cursor_frame_cb, &frame_listener, xwl_seat);
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
wl_surface_commit(xwl_seat->cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_set_cursor(DeviceIntPtr device,
|
|
|
|
ScreenPtr screen, CursorPtr cursor, int x, int y)
|
|
|
|
{
|
|
|
|
struct xwl_seat *xwl_seat;
|
2017-12-08 08:01:59 -07:00
|
|
|
Bool cursor_visibility_changed;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
xwl_seat = device->public.devicePrivate;
|
|
|
|
if (xwl_seat == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
cursor_visibility_changed = !!xwl_seat->x_cursor ^ !!cursor;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
xwl_seat->x_cursor = cursor;
|
2017-12-08 08:01:59 -07:00
|
|
|
|
|
|
|
if (cursor_visibility_changed)
|
|
|
|
xwl_seat_cursor_visibility_changed(xwl_seat);
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
xwl_seat_set_cursor(xwl_seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_move_cursor(DeviceIntPtr device, ScreenPtr screen, int x, int y)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
xwl_device_cursor_initialize(DeviceIntPtr device, ScreenPtr screen)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_device_cursor_cleanup(DeviceIntPtr device, ScreenPtr screen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static miPointerSpriteFuncRec xwl_pointer_sprite_funcs = {
|
|
|
|
xwl_realize_cursor,
|
|
|
|
xwl_unrealize_cursor,
|
|
|
|
xwl_set_cursor,
|
|
|
|
xwl_move_cursor,
|
|
|
|
xwl_device_cursor_initialize,
|
|
|
|
xwl_device_cursor_cleanup
|
|
|
|
};
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
xwl_cursor_off_screen(ScreenPtr *ppScreen, int *x, int *y)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_cross_screen(ScreenPtr pScreen, Bool entering)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xwl_pointer_warp_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
|
|
|
|
{
|
2016-05-29 06:02:34 -06:00
|
|
|
miPointerWarpCursor(pDev, pScreen, x, y);
|
2014-09-27 11:52:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static miPointerScreenFuncRec xwl_pointer_screen_funcs = {
|
|
|
|
xwl_cursor_off_screen,
|
|
|
|
xwl_cross_screen,
|
|
|
|
xwl_pointer_warp_cursor
|
|
|
|
};
|
|
|
|
|
|
|
|
Bool
|
|
|
|
xwl_screen_init_cursor(struct xwl_screen *xwl_screen)
|
|
|
|
{
|
|
|
|
if (!dixRegisterPrivateKey(&xwl_cursor_private_key, PRIVATE_CURSOR_BITS, 0))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return miPointerInitialize(xwl_screen->screen,
|
|
|
|
&xwl_pointer_sprite_funcs,
|
|
|
|
&xwl_pointer_screen_funcs, TRUE);
|
|
|
|
}
|