Add option to disable cursor
parent
a1d455b0c5
commit
e7a1460cb8
|
@ -20,6 +20,11 @@
|
|||
|
||||
struct wl_cursor_theme;
|
||||
|
||||
enum pointer_cursor_type {
|
||||
POINTER_CURSOR_NONE = 0,
|
||||
POINTER_CURSOR_LEFT_PTR,
|
||||
};
|
||||
|
||||
enum pointer_button_mask {
|
||||
POINTER_BUTTON_LEFT = 1 << 0,
|
||||
POINTER_BUTTON_MIDDLE = 1 << 1,
|
||||
|
@ -37,15 +42,18 @@ struct pointer {
|
|||
|
||||
struct wl_cursor_theme* cursor_theme;
|
||||
struct wl_surface* cursor_surface;
|
||||
|
||||
enum pointer_cursor_type cursor_type;
|
||||
};
|
||||
|
||||
struct pointer_collection {
|
||||
struct wl_list pointers;
|
||||
void (*on_frame)(struct pointer_collection*, struct pointer*);
|
||||
enum pointer_cursor_type cursor_type;
|
||||
void* userdata;
|
||||
};
|
||||
|
||||
struct pointer_collection* pointer_collection_new(void);
|
||||
struct pointer_collection* pointer_collection_new(enum pointer_cursor_type);
|
||||
void pointer_collection_destroy(struct pointer_collection*);
|
||||
|
||||
int pointer_collection_add_wl_pointer(struct pointer_collection* self,
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -456,6 +456,7 @@ Usage: wlvncc <address> [port]\n\
|
|||
Supported values: tight, zrle, ultra, copyrect,\n\
|
||||
hextile, zlib, corre, rre, raw.\n\
|
||||
-h,--help Get help.\n\
|
||||
-n,--hide-cursor Hide the client-side cursor.\n\
|
||||
-q,--quality Quality level (0 - 9).\n\
|
||||
\n\
|
||||
");
|
||||
|
@ -466,10 +467,11 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
int rc = -1;
|
||||
|
||||
enum pointer_cursor_type cursor_type = POINTER_CURSOR_LEFT_PTR;
|
||||
const char* encodings = NULL;
|
||||
int quality = -1;
|
||||
int compression = -1;
|
||||
static const char* shortopts = "a:q:c:e:h";
|
||||
static const char* shortopts = "a:q:c:e:hn";
|
||||
|
||||
static const struct option longopts[] = {
|
||||
{ "app-id", required_argument, NULL, 'a' },
|
||||
|
@ -477,6 +479,7 @@ int main(int argc, char* argv[])
|
|||
{ "encodings", required_argument, NULL, 'e' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "quality", required_argument, NULL, 'q' },
|
||||
{ "hide-cursor", no_argument, NULL, 'n' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
|
@ -498,6 +501,9 @@ int main(int argc, char* argv[])
|
|||
case 'e':
|
||||
encodings = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
cursor_type = POINTER_CURSOR_NONE;
|
||||
break;
|
||||
case 'h':
|
||||
return usage(0);
|
||||
default:
|
||||
|
@ -531,7 +537,7 @@ int main(int argc, char* argv[])
|
|||
if (init_wayland_event_handler() < 0)
|
||||
goto event_handler_failure;
|
||||
|
||||
pointers = pointer_collection_new();
|
||||
pointers = pointer_collection_new(cursor_type);
|
||||
if (!pointers)
|
||||
goto pointer_failure;
|
||||
|
||||
|
|
|
@ -43,14 +43,19 @@ static struct wl_cursor_theme* pointer_load_cursor_theme(void)
|
|||
return wl_cursor_theme_load(xcursor_theme, xcursor_size, wl_shm);
|
||||
}
|
||||
|
||||
struct pointer* pointer_new(struct wl_pointer* wl_pointer)
|
||||
struct pointer* pointer_new(struct wl_pointer* wl_pointer,
|
||||
enum pointer_cursor_type cursor_type)
|
||||
{
|
||||
struct pointer* self = calloc(1, sizeof(*self));
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
self->wl_pointer = wl_pointer;
|
||||
self->cursor_type = cursor_type;
|
||||
|
||||
if (cursor_type == POINTER_CURSOR_LEFT_PTR)
|
||||
self->cursor_theme = pointer_load_cursor_theme();
|
||||
|
||||
self->cursor_surface = wl_compositor_create_surface(wl_compositor);
|
||||
|
||||
return self;
|
||||
|
@ -59,18 +64,21 @@ struct pointer* pointer_new(struct wl_pointer* wl_pointer)
|
|||
void pointer_destroy(struct pointer* self)
|
||||
{
|
||||
wl_pointer_destroy(self->wl_pointer);
|
||||
if (self->cursor_theme)
|
||||
wl_cursor_theme_destroy(self->cursor_theme);
|
||||
wl_surface_destroy(self->cursor_surface);
|
||||
free(self);
|
||||
}
|
||||
|
||||
struct pointer_collection* pointer_collection_new(void)
|
||||
struct pointer_collection* pointer_collection_new(
|
||||
enum pointer_cursor_type cursor_type)
|
||||
{
|
||||
struct pointer_collection* self = calloc(1, sizeof(*self));
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
wl_list_init(&self->pointers);
|
||||
self->cursor_type = cursor_type;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -99,7 +107,15 @@ struct pointer* pointer_collection_find_wl_pointer(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void pointer_update_cursor(struct pointer* self)
|
||||
static void pointer_update_cursor_none(struct pointer* self)
|
||||
{
|
||||
wl_surface_attach(self->cursor_surface, NULL, 0, 0);
|
||||
wl_pointer_set_cursor(self->wl_pointer, self->serial,
|
||||
self->cursor_surface, 0, 0);
|
||||
wl_surface_commit(self->cursor_surface);
|
||||
}
|
||||
|
||||
static void pointer_update_cursor_left_ptr(struct pointer* self)
|
||||
{
|
||||
struct wl_cursor* cursor = wl_cursor_theme_get_cursor(
|
||||
self->cursor_theme, "left_ptr");
|
||||
|
@ -118,6 +134,20 @@ static void pointer_update_cursor(struct pointer* self)
|
|||
wl_surface_commit(self->cursor_surface);
|
||||
}
|
||||
|
||||
static void pointer_update_cursor(struct pointer* self)
|
||||
{
|
||||
switch (self->cursor_type) {
|
||||
case POINTER_CURSOR_NONE:
|
||||
pointer_update_cursor_none(self);
|
||||
return;
|
||||
case POINTER_CURSOR_LEFT_PTR:
|
||||
pointer_update_cursor_left_ptr(self);
|
||||
return;
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
static void pointer_enter(void* data, struct wl_pointer* wl_pointer,
|
||||
uint32_t serial, struct wl_surface* surface, wl_fixed_t x,
|
||||
wl_fixed_t y)
|
||||
|
@ -244,7 +274,7 @@ static struct wl_pointer_listener pointer_listener = {
|
|||
int pointer_collection_add_wl_pointer(struct pointer_collection* self,
|
||||
struct wl_pointer* wl_pointer)
|
||||
{
|
||||
struct pointer* pointer = pointer_new(wl_pointer);
|
||||
struct pointer* pointer = pointer_new(wl_pointer, self->cursor_type);
|
||||
if (!pointer)
|
||||
return -1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue