aboutsummaryrefslogtreecommitdiff
path: root/sway/handlers.c
blob: 59e67f59ca20bf005e0f2124e98a97b73d819467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <xkbcommon/xkbcommon.h>
#include <stdlib.h>
#include <stdbool.h>
#include <wlc/wlc.h>
#include <ctype.h>
#include "layout.h"
#include "log.h"
#include "config.h"
#include "commands.h"
#include "handlers.h"

bool handle_output_created(wlc_handle output) {
	add_output(output);
	return true;
}

void handle_output_destroyed(wlc_handle output) {
	destroy_output(output);
}

void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) {
	sway_log(L_DEBUG, "Output %d resolution changed to %d x %d", output, to->w, to->h);
	swayc_t *c = get_swayc_for_handle(output, &root_container);
	if (!c) return;
	c->width = to->w;
	c->height = to->h;
	arrange_windows(&root_container, -1, -1);
}

bool handle_view_created(wlc_handle view) {
	add_view(view);
	return true;
}

void handle_view_destroyed(wlc_handle view) {
	destroy_view(get_swayc_for_handle(view, &root_container));
	return true;
}

void handle_view_focus(wlc_handle view, bool focus) {
	wlc_view_set_state(view, WLC_BIT_ACTIVATED, focus);
	focus_view(get_swayc_for_handle(view, &root_container));
}

void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* geometry) {
	// deny that shit
}

bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers
		*modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) {
	// TODO: handle keybindings with more than 1 non-modifier key involved
	// Note: reminder to check conflicts with mod+q+a versus mod+q
	
	bool ret = true;
	struct sway_mode *mode = config->current_mode;
	sway_log(L_DEBUG, "key pressed: %d %d", sym, modifiers->mods);

	// Lowercase if necessary
	sym = tolower(sym);

	if (state == WLC_KEY_STATE_PRESSED) {
		int i;
		for (i = 0; i < mode->bindings->length; ++i) {
			struct sway_binding *binding = mode->bindings->items[i];

			if ((modifiers->mods & binding->modifiers) == binding->modifiers) {
				bool match = true;
				int j;
				for (j = 0; j < binding->keys->length; ++j) {
					xkb_keysym_t *k = binding->keys->items[j];
					if (sym != *k) {
						match = false;
						break;
					}
				}

				if (match) {
					ret = false;
					handle_command(config, binding->command);
				}
			}
		}
	}
	return ret;
}