mirror of
https://github.com/swaywm/sway.git
synced 2025-11-18 06:59:48 -05:00
Idle handling for dpms/lockscreen et al
Swayidle handles idle events and allows for dpms and lockscreen handling. It also handles systemd sleep events, and can raise a lockscreen on sleep Fixes #541
This commit is contained in:
parent
9d607b7253
commit
8fbafbfab5
16 changed files with 703 additions and 2 deletions
|
|
@ -20,6 +20,25 @@ static char *bg_options[] = {
|
|||
"tile",
|
||||
};
|
||||
|
||||
static struct cmd_results *cmd_output_dpms(struct output_config *output,
|
||||
int *i, int argc, char **argv) {
|
||||
|
||||
if (++*i >= argc) {
|
||||
return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument.");
|
||||
}
|
||||
|
||||
char *value = argv[*i];
|
||||
if (strcmp(value, "on") == 0) {
|
||||
output->dpms_state = DPMS_ON;
|
||||
} else if (strcmp(value, "off") == 0) {
|
||||
output->dpms_state = DPMS_OFF;
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "output",
|
||||
"Invalid dpms state, valid states are on/off.");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct cmd_results *cmd_output_mode(struct output_config *output,
|
||||
int *i, int argc, char **argv) {
|
||||
if (++*i >= argc) {
|
||||
|
|
@ -263,6 +282,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
|||
} else if (strcasecmp(command, "background") == 0 ||
|
||||
strcasecmp(command, "bg") == 0) {
|
||||
error = cmd_output_background(output, &i, argc, argv);
|
||||
} else if (strcasecmp(command, "dpms") == 0) {
|
||||
error = cmd_output_dpms(output, &i, argc, argv);
|
||||
} else {
|
||||
error = cmd_results_new(CMD_INVALID, "output",
|
||||
"Invalid output subcommand: %s.", command);
|
||||
|
|
@ -285,10 +306,10 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
|||
}
|
||||
|
||||
wlr_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
|
||||
"position %d,%d scale %f transform %d) (bg %s %s)",
|
||||
"position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)",
|
||||
output->name, output->enabled, output->width, output->height,
|
||||
output->refresh_rate, output->x, output->y, output->scale,
|
||||
output->transform, output->background, output->background_option);
|
||||
output->transform, output->background, output->background_option, output->dpms_state);
|
||||
|
||||
// Try to find the output container and apply configuration now. If
|
||||
// this is during startup then there will be no container and config
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ static void config_defaults(struct sway_config *config) {
|
|||
config->floating_mod = 0;
|
||||
config->dragging_key = BTN_LEFT;
|
||||
config->resizing_key = BTN_RIGHT;
|
||||
|
||||
if (!(config->floating_scroll_up_cmd = strdup(""))) goto cleanup;
|
||||
if (!(config->floating_scroll_down_cmd = strdup(""))) goto cleanup;
|
||||
if (!(config->floating_scroll_left_cmd = strdup(""))) goto cleanup;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
|
|||
free(dst->background_option);
|
||||
dst->background_option = strdup(src->background_option);
|
||||
}
|
||||
if (src->dpms_state != 0) {
|
||||
dst->dpms_state = src->dpms_state;
|
||||
}
|
||||
}
|
||||
|
||||
static void set_mode(struct wlr_output *output, int width, int height,
|
||||
|
|
@ -204,6 +207,20 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
|
|||
execvp(cmd[0], cmd);
|
||||
}
|
||||
}
|
||||
if (oc && oc->dpms_state != DPMS_IGNORE) {
|
||||
switch (oc->dpms_state) {
|
||||
case DPMS_ON:
|
||||
wlr_log(L_DEBUG, "Turning on screen");
|
||||
wlr_output_enable(wlr_output, true);
|
||||
break;
|
||||
case DPMS_OFF:
|
||||
wlr_log(L_DEBUG, "Turning off screen");
|
||||
wlr_output_enable(wlr_output, false);
|
||||
break;
|
||||
case DPMS_IGNORE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void free_output_config(struct output_config *oc) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#endif
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
#include <wlr/types/wlr_idle.h>
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "sway/input/cursor.h"
|
||||
|
|
@ -172,6 +173,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec)
|
|||
|
||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_motion *event = data;
|
||||
wlr_cursor_move(cursor->cursor, event->device,
|
||||
event->delta_x, event->delta_y);
|
||||
|
|
@ -182,6 +184,7 @@ static void handle_cursor_motion_absolute(
|
|||
struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor =
|
||||
wl_container_of(listener, cursor, motion_absolute);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_motion_absolute *event = data;
|
||||
wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
|
||||
cursor_send_pointer_motion(cursor, event->time_msec);
|
||||
|
|
@ -231,6 +234,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
|
|||
|
||||
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_button *event = data;
|
||||
dispatch_cursor_button(cursor,
|
||||
event->time_msec, event->button, event->state);
|
||||
|
|
@ -238,6 +242,7 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_axis *event = data;
|
||||
wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec,
|
||||
event->orientation, event->delta, event->delta_discrete, event->source);
|
||||
|
|
@ -245,6 +250,7 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_touch_down *event = data;
|
||||
|
||||
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
||||
|
|
@ -271,6 +277,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_touch_up(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_touch_up *event = data;
|
||||
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
||||
// TODO: fall back to cursor simulation if client has not bound to touch
|
||||
|
|
@ -280,6 +287,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) {
|
|||
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor =
|
||||
wl_container_of(listener, cursor, touch_motion);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_touch_motion *event = data;
|
||||
|
||||
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
||||
|
|
@ -331,6 +339,7 @@ static void apply_mapping_from_region(struct wlr_input_device *device,
|
|||
|
||||
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_tablet_tool_axis *event = data;
|
||||
struct sway_input_device *input_device = event->device->data;
|
||||
|
||||
|
|
@ -353,6 +362,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_tablet_tool_tip *event = data;
|
||||
dispatch_cursor_button(cursor, event->time_msec,
|
||||
BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ?
|
||||
|
|
@ -361,6 +371,7 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_tool_button(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_tablet_tool_button *event = data;
|
||||
// TODO: the user may want to configure which tool buttons are mapped to
|
||||
// which simulated pointer buttons
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <limits.h>
|
||||
#include <wlr/backend/multi.h>
|
||||
#include <wlr/backend/session.h>
|
||||
#include <wlr/types/wlr_idle.h>
|
||||
#include "sway/input/seat.h"
|
||||
#include "sway/input/keyboard.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
|
|
@ -330,6 +331,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
|||
struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat;
|
||||
struct wlr_input_device *wlr_device =
|
||||
keyboard->seat_device->input_device->wlr_device;
|
||||
wlr_idle_notify_activity(keyboard->seat_device->sway_seat->input->server->idle, wlr_seat);
|
||||
struct wlr_event_keyboard_key *event = data;
|
||||
|
||||
xkb_keycode_t keycode = event->keycode + 8;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
#include <wlr/types/wlr_xdg_output.h>
|
||||
#include <wlr/types/wlr_wl_shell.h>
|
||||
#include <wlr/types/wlr_idle.h>
|
||||
#include <wlr/util/log.h>
|
||||
// TODO WLR: make Xwayland optional
|
||||
#include <wlr/xwayland.h>
|
||||
|
|
@ -61,6 +62,7 @@ bool server_init(struct sway_server *server) {
|
|||
server->data_device_manager =
|
||||
wlr_data_device_manager_create(server->wl_display);
|
||||
|
||||
server->idle = wlr_idle_create(server->wl_display);
|
||||
wlr_screenshooter_create(server->wl_display);
|
||||
wlr_gamma_control_manager_create(server->wl_display);
|
||||
wlr_primary_selection_device_manager_create(server->wl_display);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue