aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Mattias Eriksson <snaggen@mayam.com>2018-04-17 09:54:02 +0200
committerLibravatar Mattias Eriksson <snaggen@mayam.com>2018-05-13 00:30:09 +0200
commit8fbafbfab5671d56dd469f2205b7906c4a7f7c7c (patch)
treeab4eab0020d97dc5091b72479c383989ccc84729 /sway
parentMerge pull request #1967 from emersion/remove-xdg-popup-unmap (diff)
downloadsway-8fbafbfab5671d56dd469f2205b7906c4a7f7c7c.tar.gz
sway-8fbafbfab5671d56dd469f2205b7906c4a7f7c7c.tar.zst
sway-8fbafbfab5671d56dd469f2205b7906c4a7f7c7c.zip
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
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/output.c25
-rw-r--r--sway/config.c1
-rw-r--r--sway/config/output.c17
-rw-r--r--sway/input/cursor.c11
-rw-r--r--sway/input/keyboard.c2
-rw-r--r--sway/server.c2
6 files changed, 56 insertions, 2 deletions
diff --git a/sway/commands/output.c b/sway/commands/output.c
index f7e3372c..e8881f77 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -20,6 +20,25 @@ static char *bg_options[] = {
20 "tile", 20 "tile",
21}; 21};
22 22
23static struct cmd_results *cmd_output_dpms(struct output_config *output,
24 int *i, int argc, char **argv) {
25
26 if (++*i >= argc) {
27 return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument.");
28 }
29
30 char *value = argv[*i];
31 if (strcmp(value, "on") == 0) {
32 output->dpms_state = DPMS_ON;
33 } else if (strcmp(value, "off") == 0) {
34 output->dpms_state = DPMS_OFF;
35 } else {
36 return cmd_results_new(CMD_INVALID, "output",
37 "Invalid dpms state, valid states are on/off.");
38 }
39 return NULL;
40}
41
23static struct cmd_results *cmd_output_mode(struct output_config *output, 42static struct cmd_results *cmd_output_mode(struct output_config *output,
24 int *i, int argc, char **argv) { 43 int *i, int argc, char **argv) {
25 if (++*i >= argc) { 44 if (++*i >= argc) {
@@ -263,6 +282,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
263 } else if (strcasecmp(command, "background") == 0 || 282 } else if (strcasecmp(command, "background") == 0 ||
264 strcasecmp(command, "bg") == 0) { 283 strcasecmp(command, "bg") == 0) {
265 error = cmd_output_background(output, &i, argc, argv); 284 error = cmd_output_background(output, &i, argc, argv);
285 } else if (strcasecmp(command, "dpms") == 0) {
286 error = cmd_output_dpms(output, &i, argc, argv);
266 } else { 287 } else {
267 error = cmd_results_new(CMD_INVALID, "output", 288 error = cmd_results_new(CMD_INVALID, "output",
268 "Invalid output subcommand: %s.", command); 289 "Invalid output subcommand: %s.", command);
@@ -285,10 +306,10 @@ struct cmd_results *cmd_output(int argc, char **argv) {
285 } 306 }
286 307
287 wlr_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz " 308 wlr_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
288 "position %d,%d scale %f transform %d) (bg %s %s)", 309 "position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)",
289 output->name, output->enabled, output->width, output->height, 310 output->name, output->enabled, output->width, output->height,
290 output->refresh_rate, output->x, output->y, output->scale, 311 output->refresh_rate, output->x, output->y, output->scale,
291 output->transform, output->background, output->background_option); 312 output->transform, output->background, output->background_option, output->dpms_state);
292 313
293 // Try to find the output container and apply configuration now. If 314 // Try to find the output container and apply configuration now. If
294 // this is during startup then there will be no container and config 315 // this is during startup then there will be no container and config
diff --git a/sway/config.c b/sway/config.c
index 270c1d86..34c8a280 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -165,6 +165,7 @@ static void config_defaults(struct sway_config *config) {
165 config->floating_mod = 0; 165 config->floating_mod = 0;
166 config->dragging_key = BTN_LEFT; 166 config->dragging_key = BTN_LEFT;
167 config->resizing_key = BTN_RIGHT; 167 config->resizing_key = BTN_RIGHT;
168
168 if (!(config->floating_scroll_up_cmd = strdup(""))) goto cleanup; 169 if (!(config->floating_scroll_up_cmd = strdup(""))) goto cleanup;
169 if (!(config->floating_scroll_down_cmd = strdup(""))) goto cleanup; 170 if (!(config->floating_scroll_down_cmd = strdup(""))) goto cleanup;
170 if (!(config->floating_scroll_left_cmd = strdup(""))) goto cleanup; 171 if (!(config->floating_scroll_left_cmd = strdup(""))) goto cleanup;
diff --git a/sway/config/output.c b/sway/config/output.c
index 68022278..ee2440ea 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -81,6 +81,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
81 free(dst->background_option); 81 free(dst->background_option);
82 dst->background_option = strdup(src->background_option); 82 dst->background_option = strdup(src->background_option);
83 } 83 }
84 if (src->dpms_state != 0) {
85 dst->dpms_state = src->dpms_state;
86 }
84} 87}
85 88
86static void set_mode(struct wlr_output *output, int width, int height, 89static 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
204 execvp(cmd[0], cmd); 207 execvp(cmd[0], cmd);
205 } 208 }
206 } 209 }
210 if (oc && oc->dpms_state != DPMS_IGNORE) {
211 switch (oc->dpms_state) {
212 case DPMS_ON:
213 wlr_log(L_DEBUG, "Turning on screen");
214 wlr_output_enable(wlr_output, true);
215 break;
216 case DPMS_OFF:
217 wlr_log(L_DEBUG, "Turning off screen");
218 wlr_output_enable(wlr_output, false);
219 break;
220 case DPMS_IGNORE:
221 break;
222 }
223 }
207} 224}
208 225
209void free_output_config(struct output_config *oc) { 226void free_output_config(struct output_config *oc) {
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 51ce86e1..9259c475 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -7,6 +7,7 @@
7#endif 7#endif
8#include <wlr/types/wlr_cursor.h> 8#include <wlr/types/wlr_cursor.h>
9#include <wlr/types/wlr_xcursor_manager.h> 9#include <wlr/types/wlr_xcursor_manager.h>
10#include <wlr/types/wlr_idle.h>
10#include "list.h" 11#include "list.h"
11#include "log.h" 12#include "log.h"
12#include "sway/input/cursor.h" 13#include "sway/input/cursor.h"
@@ -172,6 +173,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec)
172 173
173static void handle_cursor_motion(struct wl_listener *listener, void *data) { 174static void handle_cursor_motion(struct wl_listener *listener, void *data) {
174 struct sway_cursor *cursor = wl_container_of(listener, cursor, motion); 175 struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
176 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
175 struct wlr_event_pointer_motion *event = data; 177 struct wlr_event_pointer_motion *event = data;
176 wlr_cursor_move(cursor->cursor, event->device, 178 wlr_cursor_move(cursor->cursor, event->device,
177 event->delta_x, event->delta_y); 179 event->delta_x, event->delta_y);
@@ -182,6 +184,7 @@ static void handle_cursor_motion_absolute(
182 struct wl_listener *listener, void *data) { 184 struct wl_listener *listener, void *data) {
183 struct sway_cursor *cursor = 185 struct sway_cursor *cursor =
184 wl_container_of(listener, cursor, motion_absolute); 186 wl_container_of(listener, cursor, motion_absolute);
187 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
185 struct wlr_event_pointer_motion_absolute *event = data; 188 struct wlr_event_pointer_motion_absolute *event = data;
186 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); 189 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
187 cursor_send_pointer_motion(cursor, event->time_msec); 190 cursor_send_pointer_motion(cursor, event->time_msec);
@@ -231,6 +234,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
231 234
232static void handle_cursor_button(struct wl_listener *listener, void *data) { 235static void handle_cursor_button(struct wl_listener *listener, void *data) {
233 struct sway_cursor *cursor = wl_container_of(listener, cursor, button); 236 struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
237 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
234 struct wlr_event_pointer_button *event = data; 238 struct wlr_event_pointer_button *event = data;
235 dispatch_cursor_button(cursor, 239 dispatch_cursor_button(cursor,
236 event->time_msec, event->button, event->state); 240 event->time_msec, event->button, event->state);
@@ -238,6 +242,7 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
238 242
239static void handle_cursor_axis(struct wl_listener *listener, void *data) { 243static void handle_cursor_axis(struct wl_listener *listener, void *data) {
240 struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); 244 struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
245 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
241 struct wlr_event_pointer_axis *event = data; 246 struct wlr_event_pointer_axis *event = data;
242 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, 247 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec,
243 event->orientation, event->delta, event->delta_discrete, event->source); 248 event->orientation, event->delta, event->delta_discrete, event->source);
@@ -245,6 +250,7 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
245 250
246static void handle_touch_down(struct wl_listener *listener, void *data) { 251static void handle_touch_down(struct wl_listener *listener, void *data) {
247 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); 252 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
253 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
248 struct wlr_event_touch_down *event = data; 254 struct wlr_event_touch_down *event = data;
249 255
250 struct wlr_seat *seat = cursor->seat->wlr_seat; 256 struct wlr_seat *seat = cursor->seat->wlr_seat;
@@ -271,6 +277,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
271 277
272static void handle_touch_up(struct wl_listener *listener, void *data) { 278static void handle_touch_up(struct wl_listener *listener, void *data) {
273 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); 279 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
280 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
274 struct wlr_event_touch_up *event = data; 281 struct wlr_event_touch_up *event = data;
275 struct wlr_seat *seat = cursor->seat->wlr_seat; 282 struct wlr_seat *seat = cursor->seat->wlr_seat;
276 // TODO: fall back to cursor simulation if client has not bound to touch 283 // 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) {
280static void handle_touch_motion(struct wl_listener *listener, void *data) { 287static void handle_touch_motion(struct wl_listener *listener, void *data) {
281 struct sway_cursor *cursor = 288 struct sway_cursor *cursor =
282 wl_container_of(listener, cursor, touch_motion); 289 wl_container_of(listener, cursor, touch_motion);
290 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
283 struct wlr_event_touch_motion *event = data; 291 struct wlr_event_touch_motion *event = data;
284 292
285 struct wlr_seat *seat = cursor->seat->wlr_seat; 293 struct wlr_seat *seat = cursor->seat->wlr_seat;
@@ -331,6 +339,7 @@ static void apply_mapping_from_region(struct wlr_input_device *device,
331 339
332static void handle_tool_axis(struct wl_listener *listener, void *data) { 340static void handle_tool_axis(struct wl_listener *listener, void *data) {
333 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); 341 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
342 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
334 struct wlr_event_tablet_tool_axis *event = data; 343 struct wlr_event_tablet_tool_axis *event = data;
335 struct sway_input_device *input_device = event->device->data; 344 struct sway_input_device *input_device = event->device->data;
336 345
@@ -353,6 +362,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
353 362
354static void handle_tool_tip(struct wl_listener *listener, void *data) { 363static void handle_tool_tip(struct wl_listener *listener, void *data) {
355 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); 364 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
365 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
356 struct wlr_event_tablet_tool_tip *event = data; 366 struct wlr_event_tablet_tool_tip *event = data;
357 dispatch_cursor_button(cursor, event->time_msec, 367 dispatch_cursor_button(cursor, event->time_msec,
358 BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ? 368 BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ?
@@ -361,6 +371,7 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) {
361 371
362static void handle_tool_button(struct wl_listener *listener, void *data) { 372static void handle_tool_button(struct wl_listener *listener, void *data) {
363 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button); 373 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button);
374 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
364 struct wlr_event_tablet_tool_button *event = data; 375 struct wlr_event_tablet_tool_button *event = data;
365 // TODO: the user may want to configure which tool buttons are mapped to 376 // TODO: the user may want to configure which tool buttons are mapped to
366 // which simulated pointer buttons 377 // which simulated pointer buttons
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index dbf2ce01..c07557db 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -2,6 +2,7 @@
2#include <limits.h> 2#include <limits.h>
3#include <wlr/backend/multi.h> 3#include <wlr/backend/multi.h>
4#include <wlr/backend/session.h> 4#include <wlr/backend/session.h>
5#include <wlr/types/wlr_idle.h>
5#include "sway/input/seat.h" 6#include "sway/input/seat.h"
6#include "sway/input/keyboard.h" 7#include "sway/input/keyboard.h"
7#include "sway/input/input-manager.h" 8#include "sway/input/input-manager.h"
@@ -330,6 +331,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) {
330 struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat; 331 struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat;
331 struct wlr_input_device *wlr_device = 332 struct wlr_input_device *wlr_device =
332 keyboard->seat_device->input_device->wlr_device; 333 keyboard->seat_device->input_device->wlr_device;
334 wlr_idle_notify_activity(keyboard->seat_device->sway_seat->input->server->idle, wlr_seat);
333 struct wlr_event_keyboard_key *event = data; 335 struct wlr_event_keyboard_key *event = data;
334 336
335 xkb_keycode_t keycode = event->keycode + 8; 337 xkb_keycode_t keycode = event->keycode + 8;
diff --git a/sway/server.c b/sway/server.c
index 8c41ee87..ccc215eb 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -16,6 +16,7 @@
16#include <wlr/types/wlr_xcursor_manager.h> 16#include <wlr/types/wlr_xcursor_manager.h>
17#include <wlr/types/wlr_xdg_output.h> 17#include <wlr/types/wlr_xdg_output.h>
18#include <wlr/types/wlr_wl_shell.h> 18#include <wlr/types/wlr_wl_shell.h>
19#include <wlr/types/wlr_idle.h>
19#include <wlr/util/log.h> 20#include <wlr/util/log.h>
20// TODO WLR: make Xwayland optional 21// TODO WLR: make Xwayland optional
21#include <wlr/xwayland.h> 22#include <wlr/xwayland.h>
@@ -61,6 +62,7 @@ bool server_init(struct sway_server *server) {
61 server->data_device_manager = 62 server->data_device_manager =
62 wlr_data_device_manager_create(server->wl_display); 63 wlr_data_device_manager_create(server->wl_display);
63 64
65 server->idle = wlr_idle_create(server->wl_display);
64 wlr_screenshooter_create(server->wl_display); 66 wlr_screenshooter_create(server->wl_display);
65 wlr_gamma_control_manager_create(server->wl_display); 67 wlr_gamma_control_manager_create(server->wl_display);
66 wlr_primary_selection_device_manager_create(server->wl_display); 68 wlr_primary_selection_device_manager_create(server->wl_display);