drop KDE idle protocol support

This commit is contained in:
Simon Zeni 2022-10-14 10:25:52 -04:00
parent ddfec31b4c
commit a289f812d6
7 changed files with 0 additions and 612 deletions

View file

@ -1,196 +0,0 @@
#include <getopt.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wayland-client-protocol.h>
#include <wayland-client.h>
#include "idle-client-protocol.h"
static struct org_kde_kwin_idle *idle_manager = NULL;
static struct wl_seat *seat = NULL;
static uint32_t timeout = 0, simulate_activity_timeout = 0, close_timeout = 0;
static int run = 1;
struct thread_args {
struct wl_display *display;
struct org_kde_kwin_idle_timeout *timer;
};
static void handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) {
fprintf(stdout, "interfaces found: %s\n", interface);
if (strcmp(interface, "org_kde_kwin_idle") == 0) {
idle_manager = wl_registry_bind(registry, name, &org_kde_kwin_idle_interface, 1);
}
else if (strcmp(interface, "wl_seat") == 0) {
seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
}
}
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
//TODO
}
static const struct wl_registry_listener registry_listener = {
.global = handle_global,
.global_remove = handle_global_remove,
};
static void handle_idle(void* data, struct org_kde_kwin_idle_timeout *timer) {
fprintf(stdout, "idle state\n");
}
static void handle_resume(void* data, struct org_kde_kwin_idle_timeout *timer) {
fprintf(stdout, "active state\n");
}
static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
.idle = handle_idle,
.resumed = handle_resume,
};
static int parse_args(int argc, char *argv[]) {
int c;
while ((c = getopt(argc, argv, "c:hs:t:")) != -1) {
switch(c)
{
case 'c':
close_timeout = strtoul(optarg, NULL, 10);
break;
case 's':
simulate_activity_timeout = strtoul(optarg, NULL, 10);
break;
case 't':
timeout = strtoul(optarg, NULL, 10);
break;
case 'h':
case '?':
printf("Usage: %s [OPTIONS]\n", argv[0]);
printf(" -t seconds\t\t\tidle timeout in seconds\n");
printf(" -s seconds optional\t\tsimulate user activity after x seconds\n");
printf(" -c seconds optional\t\tclose program after x seconds\n");
printf(" -h\t\t\t\tthis help menu\n");
return 1;
default:
return 1;
}
}
return 0;
}
static void *simulate_activity(void *data) {
sleep(simulate_activity_timeout);
fprintf(stdout, "simulate user activity\n");
struct thread_args *arg = data;
org_kde_kwin_idle_timeout_simulate_user_activity(arg->timer);
wl_display_roundtrip(arg->display);
return NULL;
}
static void *close_program(void *data) {
sleep(close_timeout);
struct thread_args *arg = data;
org_kde_kwin_idle_timeout_release(arg->timer);
wl_display_roundtrip(arg->display);
fprintf(stdout, "close program\n");
run = 0;
return NULL;
}
static void *main_loop(void *data) {
struct wl_display *display = data;
while (wl_display_dispatch(display) != -1) {
;
}
return NULL;
}
int main(int argc, char *argv[]) {
if (parse_args(argc, argv) != 0) {
return -1;
}
if (timeout == 0) {
printf("idle timeout 0 is invalid\n");
return -1;
}
struct wl_display *display = wl_display_connect(NULL);
if (display == NULL) {
fprintf(stderr, "failed to create display\n");
return -1;
}
struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(display);
wl_registry_destroy(registry);
if (idle_manager == NULL) {
fprintf(stderr, "display doesn't support idle protocol\n");
return -1;
}
if (seat== NULL) {
fprintf(stderr, "seat error\n");
return -1;
}
struct org_kde_kwin_idle_timeout *timer =
org_kde_kwin_idle_get_idle_timeout(idle_manager, seat, timeout * 1000);
if (timer == NULL) {
fprintf(stderr, "Could not create idle_timeout\n");
return -1;
}
pthread_t t1, t2, t3;
struct thread_args arg = {
.timer = timer,
.display = display,
};
bool create_t1 = (simulate_activity_timeout != 0) &&
(simulate_activity_timeout < close_timeout);
if (create_t1) {
if (pthread_create(&t1, NULL, &simulate_activity, (void *)&arg) != 0) {
return -1;
}
}
bool create_t2 = (close_timeout != 0);
if (create_t2) {
if (pthread_create(&t2, NULL, &close_program, (void *)&arg) != 0) {
if (create_t1) {
pthread_cancel(t1);
}
return -1;
}
}
org_kde_kwin_idle_timeout_add_listener(timer, &idle_timer_listener, timer);
fprintf(stdout, "waiting\n");
if (pthread_create(&t3, NULL, &main_loop, (void *)display) != 0) {
if (create_t1) {
pthread_cancel(t1);
}
if (create_t2) {
pthread_cancel(t2);
}
return -1;
}
if (create_t1) {
pthread_join(t1, NULL);
}
if (create_t2) {
pthread_join(t2, NULL);
}
pthread_cancel(t3);
wl_display_disconnect(display);
return 0;
}

View file

@ -65,11 +65,6 @@ compositors = {
}
clients = {
'idle': {
'src': 'idle.c',
'dep': threads,
'proto': ['kde-idle'],
},
'idle-inhibit': {
'src': ['idle-inhibit.c', 'egl_common.c'],
'dep': [wayland_egl, egl, glesv2],

View file

@ -1,86 +0,0 @@
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
#ifndef WLR_TYPES_WLR_IDLE_H
#define WLR_TYPES_WLR_IDLE_H
#include <wayland-server-core.h>
#include <wlr/types/wlr_seat.h>
/**
* Idle protocol is used to create timers which will notify the client when the
* compositor does not receive any input for a given time(in milliseconds). Also
* the client will be notified when the timer receives an activity notify and already
* was in idle state. Besides this, the client is able to simulate user activity
* which will reset the timers and at any time can destroy the timer.
*/
struct wlr_idle {
struct wl_global *global;
struct wl_list idle_timers; // wlr_idle_timeout.link
struct wl_event_loop *event_loop;
bool enabled;
struct wl_listener display_destroy;
struct {
struct wl_signal activity_notify;
struct wl_signal destroy;
} events;
void *data;
};
struct wlr_idle_timeout {
struct wl_resource *resource;
struct wl_list link;
struct wlr_seat *seat;
struct wl_event_source *idle_source;
bool idle_state;
bool enabled;
uint32_t timeout; // milliseconds
struct {
struct wl_signal idle;
struct wl_signal resume;
struct wl_signal destroy;
} events;
struct wl_listener input_listener;
struct wl_listener seat_destroy;
void *data;
};
struct wlr_idle *wlr_idle_create(struct wl_display *display);
/**
* Send notification to restart all timers for the given seat. Called by
* compositor when there is an user activity event on that seat.
*/
void wlr_idle_notify_activity(struct wlr_idle *idle, struct wlr_seat *seat);
/**
* Enable or disable timers for a given idle resource by seat.
* Passing a NULL seat means update timers for all seats.
*/
void wlr_idle_set_enabled(struct wlr_idle *idle, struct wlr_seat *seat,
bool enabled);
/**
* Create a new timer on the given seat. The idle event will be called after
* the given amount of milliseconds of inactivity, and the resumed event will
* be sent at the first user activity after the fired event.
*/
struct wlr_idle_timeout *wlr_idle_timeout_create(struct wlr_idle *idle,
struct wlr_seat *seat, uint32_t timeout);
void wlr_idle_timeout_destroy(struct wlr_idle_timeout *timeout);
#endif

View file

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="idle">
<copyright><![CDATA[
Copyright (C) 2015 Martin Gräßlin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]></copyright>
<interface name="org_kde_kwin_idle" version="1">
<description summary="User idle time manager">
This interface allows to monitor user idle time on a given seat. The interface
allows to register timers which trigger after no user activity was registered
on the seat for a given interval. It notifies when user activity resumes.
This is useful for applications wanting to perform actions when the user is not
interacting with the system, e.g. chat applications setting the user as away, power
management features to dim screen, etc..
</description>
<request name="get_idle_timeout">
<arg name="id" type="new_id" interface="org_kde_kwin_idle_timeout"/>
<arg name="seat" type="object" interface="wl_seat"/>
<arg name="timeout" type="uint" summary="The idle timeout in msec"/>
</request>
</interface>
<interface name="org_kde_kwin_idle_timeout" version="1">
<request name="release" type="destructor">
<description summary="release the timeout object"/>
</request>
<request name="simulate_user_activity">
<description summary="Simulates user activity for this timeout, behaves just like real user activity on the seat"/>
</request>
<event name="idle">
<description summary="Triggered when there has not been any user activity in the requested idle time interval"/>
</event>
<event name="resumed">
<description summary="Triggered on the first user activity after an idle event"/>
</event>
</interface>
</protocol>

View file

@ -48,7 +48,6 @@ protocols = {
# Other protocols
'drm': 'drm.xml',
'input-method-unstable-v2': 'input-method-unstable-v2.xml',
'kde-idle': 'idle.xml',
'kde-server-decoration': 'server-decoration.xml',
'virtual-keyboard-unstable-v1': 'virtual-keyboard-unstable-v1.xml',
'wlr-data-control-unstable-v1': 'wlr-data-control-unstable-v1.xml',

View file

@ -46,7 +46,6 @@ wlr_files += files(
'wlr_fullscreen_shell_v1.c',
'wlr_gamma_control_v1.c',
'wlr_idle_inhibit_v1.c',
'wlr_idle.c',
'wlr_idle_notify_v1.c',
'wlr_input_device.c',
'wlr_input_inhibitor.c',

View file

@ -1,274 +0,0 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/util/log.h>
#include "idle-protocol.h"
static const struct org_kde_kwin_idle_timeout_interface idle_timeout_impl;
static struct wlr_idle_timeout *idle_timeout_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource,
&org_kde_kwin_idle_timeout_interface, &idle_timeout_impl));
return wl_resource_get_user_data(resource);
}
static int idle_notify(void *data) {
struct wlr_idle_timeout *timer = data;
if (timer->idle_state) {
return 0;
}
timer->idle_state = true;
wl_signal_emit_mutable(&timer->events.idle, timer);
if (timer->resource) {
org_kde_kwin_idle_timeout_send_idle(timer->resource);
}
return 1;
}
static void handle_activity(struct wlr_idle_timeout *timer) {
if (!timer->enabled) {
return;
}
// in case the previous state was sleeping send a resume event and switch state
if (timer->idle_state) {
timer->idle_state = false;
wl_signal_emit_mutable(&timer->events.resume, timer);
if (timer->resource) {
org_kde_kwin_idle_timeout_send_resumed(timer->resource);
}
}
// rearm the timer
wl_event_source_timer_update(timer->idle_source, timer->timeout);
if (timer->timeout == 0) {
idle_notify(timer);
}
}
static void handle_timer_resource_destroy(struct wl_resource *timer_resource) {
struct wlr_idle_timeout *timer = idle_timeout_from_resource(timer_resource);
if (timer != NULL) {
wlr_idle_timeout_destroy(timer);
}
}
static void handle_seat_destroy(struct wl_listener *listener, void *data) {
struct wlr_idle_timeout *timer = wl_container_of(listener, timer, seat_destroy);
if (timer != NULL) {
wlr_idle_timeout_destroy(timer);
}
}
static void release_idle_timeout(struct wl_client *client,
struct wl_resource *resource){
handle_timer_resource_destroy(resource);
}
static void simulate_activity(struct wl_client *client,
struct wl_resource *resource){
struct wlr_idle_timeout *timer = idle_timeout_from_resource(resource);
handle_activity(timer);
}
static const struct org_kde_kwin_idle_timeout_interface idle_timeout_impl = {
.release = release_idle_timeout,
.simulate_user_activity = simulate_activity,
};
static const struct org_kde_kwin_idle_interface idle_impl;
static struct wlr_idle *idle_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &org_kde_kwin_idle_interface,
&idle_impl));
return wl_resource_get_user_data(resource);
}
static void handle_input_notification(struct wl_listener *listener, void *data) {
struct wlr_idle_timeout *timer =
wl_container_of(listener, timer, input_listener);
struct wlr_seat *seat = data;
if (timer->seat == seat) {
handle_activity(timer);
}
}
static struct wlr_idle_timeout *create_timer(struct wlr_idle *idle,
struct wlr_seat *seat, uint32_t timeout, struct wl_resource *resource) {
struct wlr_idle_timeout *timer = calloc(1, sizeof(*timer));
if (!timer) {
return NULL;
}
timer->seat = seat;
timer->timeout = timeout;
timer->idle_state = false;
timer->enabled = idle->enabled;
wl_list_insert(&idle->idle_timers, &timer->link);
wl_signal_init(&timer->events.idle);
wl_signal_init(&timer->events.resume);
wl_signal_init(&timer->events.destroy);
timer->seat_destroy.notify = handle_seat_destroy;
wl_signal_add(&timer->seat->events.destroy, &timer->seat_destroy);
timer->input_listener.notify = handle_input_notification;
wl_signal_add(&idle->events.activity_notify, &timer->input_listener);
// create the timer
timer->idle_source =
wl_event_loop_add_timer(idle->event_loop, idle_notify, timer);
if (timer->idle_source == NULL) {
wl_list_remove(&timer->link);
wl_list_remove(&timer->input_listener.link);
wl_list_remove(&timer->seat_destroy.link);
free(timer);
return NULL;
}
if (resource) {
timer->resource = resource;
wl_resource_set_user_data(resource, timer);
}
if (timer->enabled) {
// arm the timer
wl_event_source_timer_update(timer->idle_source, timer->timeout);
if (timer->timeout == 0) {
idle_notify(timer);
}
}
return timer;
}
static void create_idle_timer(struct wl_client *client,
struct wl_resource *idle_resource, uint32_t id,
struct wl_resource *seat_resource, uint32_t timeout) {
struct wlr_idle *idle = idle_from_resource(idle_resource);
struct wlr_seat_client *client_seat =
wlr_seat_client_from_resource(seat_resource);
struct wl_resource *resource = wl_resource_create(client,
&org_kde_kwin_idle_timeout_interface,
wl_resource_get_version(idle_resource), id);
if (resource == NULL) {
wl_resource_post_no_memory(idle_resource);
return;
}
wl_resource_set_implementation(resource, &idle_timeout_impl,
NULL, handle_timer_resource_destroy);
if (client_seat == NULL) {
return;
}
if (!create_timer(idle, client_seat->seat, timeout, resource)) {
wl_resource_post_no_memory(resource);
}
}
static const struct org_kde_kwin_idle_interface idle_impl = {
.get_idle_timeout = create_idle_timer,
};
void wlr_idle_set_enabled(struct wlr_idle *idle, struct wlr_seat *seat,
bool enabled) {
if (idle->enabled == enabled) {
return;
}
wlr_log(WLR_DEBUG, "%s idle timers for %s",
enabled ? "Enabling" : "Disabling",
seat ? seat->name : "all seats");
idle->enabled = enabled;
struct wlr_idle_timeout *timer;
wl_list_for_each(timer, &idle->idle_timers, link) {
if (seat != NULL && timer->seat != seat) {
continue;
}
int timeout = enabled ? timer->timeout : 0;
wl_event_source_timer_update(timer->idle_source, timeout);
timer->enabled = enabled;
}
}
static void idle_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) {
struct wlr_idle *idle = data;
assert(wl_client && idle);
struct wl_resource *wl_resource = wl_resource_create(wl_client,
&org_kde_kwin_idle_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource, &idle_impl, idle, NULL);
}
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_idle *idle = wl_container_of(listener, idle, display_destroy);
wl_signal_emit_mutable(&idle->events.destroy, idle);
wl_list_remove(&idle->display_destroy.link);
wl_global_destroy(idle->global);
free(idle);
}
struct wlr_idle *wlr_idle_create(struct wl_display *display) {
struct wlr_idle *idle = calloc(1, sizeof(*idle));
if (!idle) {
return NULL;
}
wl_list_init(&idle->idle_timers);
wl_signal_init(&idle->events.activity_notify);
wl_signal_init(&idle->events.destroy);
idle->enabled = true;
idle->event_loop = wl_display_get_event_loop(display);
if (idle->event_loop == NULL) {
free(idle);
return NULL;
}
idle->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &idle->display_destroy);
idle->global = wl_global_create(display, &org_kde_kwin_idle_interface,
1, idle, idle_bind);
if (idle->global == NULL) {
wl_list_remove(&idle->display_destroy.link);
free(idle);
return NULL;
}
wlr_log(WLR_DEBUG, "idle manager created");
return idle;
}
void wlr_idle_notify_activity(struct wlr_idle *idle, struct wlr_seat *seat) {
wl_signal_emit_mutable(&idle->events.activity_notify, seat);
}
struct wlr_idle_timeout *wlr_idle_timeout_create(struct wlr_idle *idle,
struct wlr_seat *seat, uint32_t timeout) {
return create_timer(idle, seat, timeout, NULL);
}
void wlr_idle_timeout_destroy(struct wlr_idle_timeout *timer) {
wl_signal_emit_mutable(&timer->events.destroy, NULL);
wl_list_remove(&timer->input_listener.link);
wl_list_remove(&timer->seat_destroy.link);
wl_event_source_remove(timer->idle_source);
wl_list_remove(&timer->link);
if (timer->resource) {
wl_resource_set_user_data(timer->resource, NULL);
}
free(timer);
}