summaryrefslogtreecommitdiff
path: root/dwl.c
diff options
context:
space:
mode:
authorLeonardo Hernández Hernández <leohdz172@proton.me>2024-06-20 22:44:50 -0600
committerLeonardo Hernández Hernández <leohdz172@proton.me>2024-06-20 22:44:50 -0600
commit4cf1d604b8912fdd5854f4a1d981cdfc5955b890 (patch)
tree2840a38f59f3d84025658023e81fcb819da3aefe /dwl.c
parenta8403d7b4d54e30699424586784cc0265b29d08d (diff)
parent650a918010ac5769787d461812392cff786e4d3b (diff)
Merge remote-tracking branch 'upstream/main' into wlroots-next
Diffstat (limited to 'dwl.c')
-rw-r--r--dwl.c84
1 files changed, 62 insertions, 22 deletions
diff --git a/dwl.c b/dwl.c
index 7b61ba2..32eaba6 100644
--- a/dwl.c
+++ b/dwl.c
@@ -35,6 +35,7 @@
#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_output_power_management_v1.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/types/wlr_presentation_time.h>
@@ -207,6 +208,7 @@ struct Monitor {
int gamma_lut_changed;
int nmaster;
char ltsymbol[16];
+ int asleep;
};
typedef struct {
@@ -314,6 +316,7 @@ static void outputmgrtest(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
static void printstatus(void);
+static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
static void requestdecorationmode(struct wl_listener *listener, void *data);
@@ -386,6 +389,7 @@ static struct wlr_gamma_control_manager_v1 *gamma_control_mgr;
static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
static struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr;
+static struct wlr_output_power_manager_v1 *power_mgr;
static struct wlr_pointer_constraints_v1 *pointer_constraints;
static struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr;
@@ -402,7 +406,6 @@ static struct wl_listener lock_listener = {.notify = locksession};
static struct wlr_seat *seat;
static KeyboardGroup *kb_group;
-static struct wlr_surface *held_grab;
static unsigned int cursor_mode;
static Client *grabc;
static int grabcx, grabcy; /* client-relative */
@@ -608,7 +611,6 @@ buttonpress(struct wl_listener *listener, void *data)
switch (event->state) {
case WL_POINTER_BUTTON_STATE_PRESSED:
cursor_mode = CurPressed;
- held_grab = seat->pointer_state.focused_surface;
if (locked)
break;
@@ -628,7 +630,6 @@ buttonpress(struct wl_listener *listener, void *data)
}
break;
case WL_POINTER_BUTTON_STATE_RELEASED:
- held_grab = NULL;
/* If you released any buttons, we exit interactive move/resize mode. */
/* TODO should reset to the pointer focus's current setcursor */
if (!locked && cursor_mode != CurNormal && cursor_mode != CurPressed) {
@@ -682,7 +683,7 @@ cleanup(void)
#endif
wl_display_destroy_clients(dpy);
if (child_pid > 0) {
- kill(child_pid, SIGTERM);
+ kill(-child_pid, SIGTERM);
waitpid(child_pid, NULL, 0);
}
wlr_xcursor_manager_destroy(cursor_mgr);
@@ -738,6 +739,9 @@ closemon(Monitor *m)
do /* don't switch to disabled mons */
selmon = wl_container_of(mons.next, selmon, link);
while (!selmon->wlr_output->enabled && i++ < nmons);
+
+ if (!selmon->wlr_output->enabled)
+ selmon = NULL;
}
wl_list_for_each(c, &clients, link) {
@@ -1807,6 +1811,18 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
struct wlr_surface *surface = NULL;
struct wlr_pointer_constraint_v1 *constraint;
+ /* Find the client under the pointer and send the event along. */
+ xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
+
+ if (cursor_mode == CurPressed && !seat->drag
+ && surface != seat->pointer_state.focused_surface
+ && toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >= 0) {
+ c = w;
+ surface = seat->pointer_state.focused_surface;
+ sx = cursor->x - (l ? l->geom.x : w->geom.x);
+ sy = cursor->y - (l ? l->geom.y : w->geom.y);
+ }
+
/* time is 0 in internal calls meant to restore pointer focus. */
if (time) {
wlr_relative_pointer_manager_v1_send_relative_motion(
@@ -1855,17 +1871,6 @@ motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double d
return;
}
- /* Find the client under the pointer and send the event along. */
- xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
-
- if (cursor_mode == CurPressed && !seat->drag && surface != held_grab
- && toplevel_from_wlr_surface(held_grab, &w, &l) >= 0) {
- c = w;
- surface = held_grab;
- sx = cursor->x - (l ? l->geom.x : w->geom.x);
- sy = cursor->y - (l ? l->geom.y : w->geom.y);
- }
-
/* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it
* off of a client or over its border. */
@@ -1942,6 +1947,10 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
Monitor *m = wlr_output->data;
struct wlr_output_state state;
+ /* Ensure displays previously disabled by wlr-output-power-management-v1
+ * are properly handled*/
+ m->asleep = 0;
+
wlr_output_state_init(&state);
wlr_output_state_set_enabled(&state, config_head->state.enabled);
if (!config_head->state.enabled)
@@ -1955,11 +1964,6 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test)
config_head->state.custom_mode.height,
config_head->state.custom_mode.refresh);
- /* Don't move monitors if position wouldn't change, this to avoid
- * wlroots marking the output as manually configured */
- if (m->m.x != config_head->state.x || m->m.y != config_head->state.y)
- wlr_output_layout_add(output_layout, wlr_output,
- config_head->state.x, config_head->state.y);
wlr_output_state_set_transform(&state, config_head->state.transform);
wlr_output_state_set_scale(&state, config_head->state.scale);
wlr_output_state_set_adaptive_sync_enabled(&state,
@@ -1969,6 +1973,13 @@ apply_or_test:
ok &= test ? wlr_output_test_state(wlr_output, &state)
: wlr_output_commit_state(wlr_output, &state);
+ /* Don't move monitors if position wouldn't change, this to avoid
+ * wlroots marking the output as manually configured.
+ * wlr_output_layout_add does not like disabled outputs */
+ if (!test && wlr_output->enabled && (m->m.x != config_head->state.x || m->m.y != config_head->state.y))
+ wlr_output_layout_add(output_layout, wlr_output,
+ config_head->state.x, config_head->state.y);
+
wlr_output_state_finish(&state);
}
@@ -2059,6 +2070,21 @@ printstatus(void)
}
void
+powermgrsetmode(struct wl_listener *listener, void *data)
+{
+ struct wlr_output_power_v1_set_mode_event *event = data;
+ struct wlr_output_state state = {0};
+
+ if (!event->output->data)
+ return;
+
+ wlr_output_state_set_enabled(&state, event->mode);
+ wlr_output_commit_state(event->output, &state);
+
+ ((Monitor *)(event->output->data))->asleep = !event->mode;
+}
+
+void
quit(const Arg *arg)
{
wl_display_terminate(dpy);
@@ -2148,8 +2174,14 @@ requestmonstate(struct wl_listener *listener, void *data)
void
resize(Client *c, struct wlr_box geo, int interact)
{
- struct wlr_box *bbox = interact ? &sgeom : &c->mon->w;
+ struct wlr_box *bbox;
struct wlr_box clip;
+
+ if (!c->mon)
+ return;
+
+ bbox = interact ? &sgeom : &c->mon->w;
+
client_set_bounds(c, geo.width, geo.height);
c->geom = geo;
applybounds(c, bbox);
@@ -2194,6 +2226,7 @@ run(char *startup_cmd)
if ((child_pid = fork()) < 0)
die("startup: fork:");
if (child_pid == 0) {
+ setsid();
dup2(piperw[0], STDIN_FILENO);
close(piperw[0]);
close(piperw[1]);
@@ -2467,6 +2500,9 @@ setup(void)
gamma_control_mgr = wlr_gamma_control_manager_v1_create(dpy);
LISTEN_STATIC(&gamma_control_mgr->events.set_gamma, setgamma);
+ power_mgr = wlr_output_power_manager_v1_create(dpy);
+ LISTEN_STATIC(&power_mgr->events.set_mode, powermgrsetmode);
+
/* Creates an output layout, which a wlroots utility for working with an
* arrangement of screens in a physical layout. */
output_layout = wlr_output_layout_create(dpy);
@@ -2785,7 +2821,7 @@ updatemons(struct wl_listener *listener, void *data)
/* First remove from the layout the disabled monitors */
wl_list_for_each(m, &mons, link) {
- if (m->wlr_output->enabled)
+ if (m->wlr_output->enabled || m->asleep)
continue;
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
config_head->state.enabled = 0;
@@ -2844,6 +2880,10 @@ updatemons(struct wl_listener *listener, void *data)
config_head->state.x = m->m.x;
config_head->state.y = m->m.y;
+
+ if (!selmon) {
+ selmon = m;
+ }
}
if (selmon && selmon->wlr_output->enabled) {