-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgwwm.c
185 lines (172 loc) · 6.1 KB
/
gwwm.c
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* See LICENSE file for copyright and license details.
*/
#define _POSIX_C_SOURCE 200809L
#include "wlr-layer-shell-unstable-v1-protocol.h"
#include "wlr/util/box.h"
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <getopt.h>
#include <libinput.h>
#include <limits.h>
#include <libguile.h>
#include <linux/input-event-codes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
#include <wlr/backend/wayland.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_activation_v1.h>
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
#include "util.h"
#include "gwwm.h"
/* configuration, allows nested code to access above variables */
struct wlr_output_layout*
gwwm_output_layout(struct wlr_output_layout *o) {
SCM d;
if (o) {
d = REF_CALL_1("gwwm", "gwwm-output-layout", WRAP_WLR_OUTPUT_LAYOUT(o));
return o;
} else {
d = REF_CALL_0("gwwm", "gwwm-output-layout");
return scm_is_false(d) ? NULL : UNWRAP_WLR_OUTPUT_LAYOUT(d);
}
}
SCM_DEFINE (gwwm_focusmon ,"focusmon",1,0,0,(SCM a),"" )
#define FUNC_NAME s_gwwm_focusmon
{
PRINT_FUNCTION;
int i = 0, nmons = scm_to_int(scm_length((REF_CALL_0("gwwm monitor", "monitor-list"))));
if (nmons)
do /* don't switch to disabled mons */
scm_call_1(REFP("gwwm monitor","set-current-monitor"),
REF_CALL_1("gwwm monitor" ,"dirtomon",a));
while (!((struct wlr_output *)
(UNWRAP_WLR_OUTPUT(scm_call_1
(REFP("gwwm monitor", "monitor-output"),
(REF_CALL_0("gwwm monitor", "current-monitor"))))))->enabled
&& i++ < nmons);
REF_CALL_2("gwwm","focusclient",
REF_CALL_1("gwwm commands", "focustop",
(REF_CALL_0("gwwm monitor", "current-monitor"))),
SCM_BOOL_T);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
SCM_DEFINE(gwwm_outputmgrapplyortest,"output-manager-apply-or-test",2,0,0,
(SCM sconfig,SCM test_p),"")
{
PRINT_FUNCTION;
/*
* Called when a client such as wlr-randr requests a change in output
* configuration. This is only one way that the layout can be changed,
* so any Monitor information should be updated by updatemons() after an
* gwwm_output_layout(NULL).change event, not here.
*/
struct wlr_output_configuration_v1 *config=UNWRAP_WLR_OUTPUT_CONFIGURATION_V1(sconfig);
bool test=scm_to_bool(test_p);
struct wlr_output_configuration_head_v1 *config_head;
int ok = 1;
/* First disable outputs we need to disable */
wl_list_for_each(config_head, &config->heads, link) {
struct wlr_output *wlr_output = config_head->state.output;
if (!wlr_output->enabled || config_head->state.enabled)
continue;
wlr_output_enable(wlr_output, 0);
if (test) {
ok &= wlr_output_test(wlr_output);
wlr_output_rollback(wlr_output);
} else {
ok &= wlr_output_commit(wlr_output);
}
}
/* Then enable outputs that need to */
wl_list_for_each(config_head, &config->heads, link) {
struct wlr_output *wlr_output = config_head->state.output;
if (!config_head->state.enabled)
continue;
wlr_output_enable(wlr_output, 1);
if (config_head->state.mode)
wlr_output_set_mode(wlr_output, config_head->state.mode);
else
wlr_output_set_custom_mode(wlr_output,
config_head->state.custom_mode.width,
config_head->state.custom_mode.height,
config_head->state.custom_mode.refresh);
wlr_output_layout_add(gwwm_output_layout(NULL), wlr_output,
config_head->state.x, config_head->state.y);
wlr_output_set_transform(wlr_output, config_head->state.transform);
wlr_output_set_scale(wlr_output, config_head->state.scale);
if (test) {
ok &= wlr_output_test(wlr_output);
wlr_output_rollback(wlr_output);
} else {
int output_ok = 1;
/* If it's a custom mode to avoid an assertion failed in wlr_output_commit()
* we test if that mode does not fail rather than just call wlr_output_commit().
* We do not test normal modes because (at least in my hardware (@sevz17))
* wlr_output_test() fails even if that mode can actually be set */
if (!config_head->state.mode)
ok &= (output_ok = wlr_output_test(wlr_output)
&& wlr_output_commit(wlr_output));
else
ok &= wlr_output_commit(wlr_output);
/* In custom modes we call wlr_output_test(), it it fails
* we need to rollback, and normal modes seems to does not cause
* assertions failed in wlr_output_commit() which rollback
* the output on failure */
if (!output_ok)
wlr_output_rollback(wlr_output);
}
}
if (ok)
wlr_output_configuration_v1_send_succeeded(config);
else
wlr_output_configuration_v1_send_failed(config);
wlr_output_configuration_v1_destroy(config);
return SCM_UNSPECIFIED;
}
void
scm_init_gwwm(void)
{
#ifndef SCM_MAGIC_SNARFER
#include "gwwm.x"
#endif
}