feat: add support to two new wayland protocols
- Idle notify - Idle inhibit
This commit is contained in:
5
cursor.c
5
cursor.c
@ -5,6 +5,7 @@
|
||||
#include "view.h"
|
||||
#include "seat.h"
|
||||
#include "node.h"
|
||||
#include "idle.h"
|
||||
|
||||
void diyac_cursor_focus(struct diyac_server *server)
|
||||
{
|
||||
@ -216,6 +217,7 @@ static void server_cursor_motion(struct wl_listener *listener, void *data)
|
||||
struct diyac_seat *seat =
|
||||
wl_container_of(listener, seat, cursor_motion);
|
||||
struct wlr_pointer_motion_event *event = data;
|
||||
diya_idle_manager_notify_activity(seat->wlr_seat);
|
||||
/* The cursor doesn't move unless we tell it to. The cursor automatically
|
||||
* handles constraining the motion to the output layout, as well as any
|
||||
* special configuration applied for the specific input device which
|
||||
@ -237,6 +239,7 @@ static void server_cursor_motion_absolute(
|
||||
* emits these events. */
|
||||
struct diyac_seat *seat =
|
||||
wl_container_of(listener, seat, cursor_motion_absolute);
|
||||
diya_idle_manager_notify_activity(seat->wlr_seat);
|
||||
struct wlr_pointer_motion_absolute_event *event = data;
|
||||
wlr_cursor_warp_absolute(seat->cursor, &event->pointer->base, event->x,
|
||||
event->y);
|
||||
@ -250,6 +253,7 @@ static void server_cursor_button(struct wl_listener *listener, void *data)
|
||||
struct diyac_seat *seat =
|
||||
wl_container_of(listener, seat, cursor_button);
|
||||
struct wlr_pointer_button_event *event = data;
|
||||
diya_idle_manager_notify_activity(seat->wlr_seat);
|
||||
/* Notify the client with pointer focus that a button press has occurred */
|
||||
wlr_seat_pointer_notify_button(seat->wlr_seat,
|
||||
event->time_msec, event->button, event->state);
|
||||
@ -271,6 +275,7 @@ static void server_cursor_axis(struct wl_listener *listener, void *data)
|
||||
* for example when you move the scroll wheel. */
|
||||
struct diyac_seat *seat =
|
||||
wl_container_of(listener, seat, cursor_axis);
|
||||
diya_idle_manager_notify_activity(seat->wlr_seat);
|
||||
struct wlr_pointer_axis_event *event = data;
|
||||
/* Notify the client with pointer focus of the axis event. */
|
||||
wlr_seat_pointer_notify_axis(seat->wlr_seat,
|
||||
|
2
diyac.c
2
diyac.c
@ -19,6 +19,7 @@
|
||||
#include "seat.h"
|
||||
#include "layer.h"
|
||||
#include "session.h"
|
||||
#include "idle.h"
|
||||
|
||||
#define PROC_MON_TO 100
|
||||
|
||||
@ -190,6 +191,7 @@ int main(int argc, char *argv[])
|
||||
wlr_screencopy_manager_v1_create(server.wl_display);
|
||||
wlr_single_pixel_buffer_manager_v1_create(server.wl_display);
|
||||
wlr_fractional_scale_manager_v1_create(server.wl_display,1);
|
||||
diya_init_idle_manager(server.wl_display);
|
||||
/* Set up xdg-shell version 6 The xdg-shell is a Wayland protocol which is
|
||||
* used for application windows. For more detail on shells, refer to
|
||||
* https://drewdevault.com/2018/07/29/Wayland-shells.html.
|
||||
|
77
idle.c
Normal file
77
idle.c
Normal file
@ -0,0 +1,77 @@
|
||||
#include "diyac.h"
|
||||
#include "idle.h"
|
||||
#include <stdlib.h>
|
||||
#include <wlr/types/wlr_idle_notify_v1.h>
|
||||
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
||||
|
||||
struct diya_idle_inhibitor
|
||||
{
|
||||
struct wlr_idle_inhibitor_v1 *wlr_inhibitor;
|
||||
struct wl_listener on_inhibitor_destroy;
|
||||
};
|
||||
|
||||
struct diya_idle_mngr
|
||||
{
|
||||
struct wlr_idle_inhibit_manager_v1 *wlr_inhibitor_mngr;
|
||||
struct wl_listener on_new_inhibitor;
|
||||
|
||||
struct wlr_idle_notifier_v1 *wlr_idle_notifier;
|
||||
// struct wl_listener on_display_destroy;
|
||||
};
|
||||
|
||||
static struct diya_idle_mngr g_idle_mngr;
|
||||
|
||||
static void handle_idle_inhibitor_destroy(struct wl_listener *listener, void *data)
|
||||
{
|
||||
(void) data;
|
||||
struct diya_idle_inhibitor *inhibitor = wl_container_of(listener, inhibitor, on_inhibitor_destroy);
|
||||
|
||||
if (g_idle_mngr.wlr_idle_notifier) {
|
||||
bool still_inhibited = wl_list_length(&g_idle_mngr.wlr_inhibitor_mngr->inhibitors) > 1;
|
||||
wlr_idle_notifier_v1_set_inhibited(g_idle_mngr.wlr_idle_notifier, still_inhibited);
|
||||
}
|
||||
|
||||
wl_list_remove(&inhibitor->on_inhibitor_destroy.link);
|
||||
free(inhibitor);
|
||||
}
|
||||
|
||||
/*
|
||||
static void handle_display_destroy(struct wl_listener *listener, void *data)
|
||||
{
|
||||
(void) data;
|
||||
(void) listener;
|
||||
wl_list_remove(&g_idle_mngr.on_display_destroy.link);
|
||||
g_idle_mngr.wlr_idle_notifier = NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
static void handle_idle_inhibitor_new(struct wl_listener *listener, void *data)
|
||||
{
|
||||
(void) listener;
|
||||
struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
|
||||
struct diya_idle_inhibitor *inhibitor = malloc(sizeof(struct diya_idle_inhibitor));
|
||||
inhibitor->wlr_inhibitor = wlr_inhibitor;
|
||||
inhibitor->on_inhibitor_destroy.notify = handle_idle_inhibitor_destroy;
|
||||
wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->on_inhibitor_destroy);
|
||||
|
||||
wlr_idle_notifier_v1_set_inhibited(g_idle_mngr.wlr_idle_notifier, true);
|
||||
}
|
||||
|
||||
void diya_init_idle_manager(struct wl_display *display)
|
||||
{
|
||||
g_idle_mngr.wlr_idle_notifier = wlr_idle_notifier_v1_create(display);
|
||||
g_idle_mngr.wlr_inhibitor_mngr = wlr_idle_inhibit_v1_create(display);
|
||||
|
||||
g_idle_mngr.on_new_inhibitor.notify = handle_idle_inhibitor_new;
|
||||
wl_signal_add(&g_idle_mngr.wlr_inhibitor_mngr->events.new_inhibitor,&g_idle_mngr.on_new_inhibitor);
|
||||
|
||||
//g_idle_mngr.on_display_destroy.notify = handle_display_destroy;
|
||||
//wl_display_add_destroy_listener(display, &g_idle_mngr.on_display_destroy);
|
||||
}
|
||||
|
||||
void diya_idle_manager_notify_activity(struct wlr_seat *seat)
|
||||
{
|
||||
if (g_idle_mngr.wlr_idle_notifier) {
|
||||
wlr_idle_notifier_v1_notify_activity(g_idle_mngr.wlr_idle_notifier, seat);
|
||||
}
|
||||
}
|
9
idle.h
Normal file
9
idle.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef DIYAC_IDLE_H
|
||||
#define DIYAC_IDLE_H
|
||||
|
||||
struct wl_display;
|
||||
struct wlr_seat;
|
||||
|
||||
void diya_init_idle_manager(struct wl_display *display);
|
||||
void diya_idle_manager_notify_activity(struct wlr_seat *seat);
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
project('diyac',
|
||||
['c'],
|
||||
version: '0.1.0',
|
||||
version: '0.1.1',
|
||||
license: 'MIT',
|
||||
meson_version: '>=0.58.0',
|
||||
default_options: ['c_std=gnu11', 'warning_level=3'])
|
||||
@ -61,6 +61,7 @@ src = [
|
||||
'xdg.c',
|
||||
'layer.c',
|
||||
'session.c',
|
||||
'idle.c',
|
||||
wayland_targets
|
||||
]
|
||||
|
||||
|
3
seat.c
3
seat.c
@ -7,6 +7,7 @@
|
||||
#include "seat.h"
|
||||
#include "view.h"
|
||||
#include "output.h"
|
||||
#include "idle.h"
|
||||
|
||||
static void configure_keyboard(struct diyac_seat* seat, struct diyac_input* input, bool force)
|
||||
{
|
||||
@ -97,7 +98,7 @@ static void keyboard_handle_key(
|
||||
wl_container_of(listener, keyboard, key);
|
||||
struct wlr_keyboard_key_event *event = data;
|
||||
struct wlr_seat *seat = keyboard->input.seat->wlr_seat;
|
||||
|
||||
diya_idle_manager_notify_activity(seat);
|
||||
/* Translate libinput keycode -> xkbcommon */
|
||||
// wlr_log(WLR_INFO, "receive keycode %d", event->keycode);
|
||||
uint32_t keycode = event->keycode + 8;
|
||||
|
Reference in New Issue
Block a user