From 269e00bf21f97829a6c107a31915be0c28607794 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sun, 30 Jan 2022 23:33:56 +0100 Subject: [PATCH 01/93] fix stuff --- src/tagset.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tagset.c b/src/tagset.c index bc533e20..1f284913 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -19,6 +19,7 @@ #include "list_sets/container_stack_set.h" #include "root.h" #include "server.h" +#include "layer_shell.h" static void tagset_assign_tag(struct tag *sel_tag, struct tag *tag, bool active); static void tagset_unset_tag(struct tag *sel_tag, struct tag *tag); @@ -80,7 +81,7 @@ void tagset_set_tags(struct tag *sel_tag, BitSet *tags) tag_damage(sel_tag); tagset_load_tags(sel_tag, sel_tag->tags); update_reduced_focus_stack(sel_tag); - arrange(); + arrange_layers(server_get_selected_monitor()); tag_focus_most_recent_container(sel_tag); bitset_destroy(tags_copy); @@ -320,7 +321,7 @@ void focus_tagset(struct tag *tag, BitSet *tags) ipc_event_tag(); tagset_move_sticky_containers(tag); - arrange(); + arrange_layers(server_get_selected_monitor()); tag_focus_most_recent_container(tag); root_damage_whole(m->root); From cafb42d90a67a73f26568489d6331666a5996ea3 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 2 Feb 2022 19:12:28 +0100 Subject: [PATCH 02/93] fix segfault --- src/popup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/popup.c b/src/popup.c index 23537ccd..62fc5863 100644 --- a/src/popup.c +++ b/src/popup.c @@ -142,6 +142,10 @@ struct wlr_surface *get_popup_surface_under_cursor(struct cursor *cursor, double struct wlr_surface *surface = NULL; struct wlr_box *con_geom = container_get_current_geom(con); + // when the container is on the tag -1 it won't have a geometry + if (!con_geom) + return NULL; + switch (con->client->type) { case XDG_SHELL: surface = wlr_xdg_surface_surface_at( From 0851743a28289f11ee92afa30a3b942a7389fa0e Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 2 Feb 2022 19:24:17 +0100 Subject: [PATCH 03/93] improve performance of subsurfaces --- src/subsurface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subsurface.c b/src/subsurface.c index cb2a0511..f407c2c8 100644 --- a/src/subsurface.c +++ b/src/subsurface.c @@ -22,7 +22,7 @@ static void handle_subsurface_commit(struct wl_listener *listener, void *data) // TODO: We should damage the subsurface directly and render the damage // directly instead of leaving this job to the parent surface. This should // save us cpu cycles - container_damage_whole(xdg_subsurface->parent); + container_damage_part(xdg_subsurface->parent); } static void handle_subsurface_destroy(struct wl_listener *listener, void *data) From 31169209e98182f1836c276935cb0f5679b45f94 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 2 Feb 2022 19:40:32 +0100 Subject: [PATCH 04/93] feat: improve performance of tagset_contains_sticky_client --- include/server.h | 4 ++++ src/server.c | 7 +++++++ src/tagset.c | 8 ++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/server.h b/include/server.h index e256cae9..860aa01f 100644 --- a/include/server.h +++ b/include/server.h @@ -74,6 +74,8 @@ struct server { int previous_tag; BitSet *previous_bitset; + // a global bitset to hold temporary values useful to improve performance + struct BitSet *tmp_bitset; struct monitor *selected_monitor; @@ -152,6 +154,8 @@ void server_set_selected_monitor(struct monitor *m); void server_center_default_cursor_in_monitor(struct monitor *m); +BitSet *server_get_tmp_bitset(); + struct tag *server_get_selected_tag(); struct layout *server_get_selected_layout(); #endif /* SERVER_H */ diff --git a/src/server.c b/src/server.c index 1c3d7232..be7f0af1 100644 --- a/src/server.c +++ b/src/server.c @@ -214,6 +214,7 @@ void init_server() server.previous_tag = 0; server.previous_bitset = bitset_create(); + server.tmp_bitset = bitset_create(); server_prohibit_reloading_config(); @@ -233,6 +234,7 @@ void finalize_server() finalize_lists(&server); + bitset_destroy(server.tmp_bitset); bitset_destroy(server.previous_bitset); g_ptr_array_unref(server.mons); @@ -546,6 +548,11 @@ void server_center_default_cursor_in_monitor(struct monitor *m) center_cursor_in_monitor(cursor, m); } +BitSet *server_get_tmp_bitset() +{ + return server.tmp_bitset; +} + struct tag *server_get_selected_tag() { struct monitor *m = server_get_selected_monitor(); diff --git a/src/tagset.c b/src/tagset.c index 1f284913..697cc7cf 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -556,10 +556,10 @@ void tag_id_to_tag(BitSet *dest, int tag_id) bool tagset_contains_sticky_client(BitSet *tagset_tags, struct client *c) { - BitSet *bitset = bitset_copy(c->sticky_tags); - bitset_and(bitset, tagset_tags); - bool contains = bitset_any(bitset); - bitset_destroy(bitset); + BitSet *tmp = server_get_tmp_bitset(); + bitset_assign_bitset(&tmp, tagset_tags); + bitset_and(tmp, tagset_tags); + bool contains = bitset_any(tmp); return contains; } From 274fd5f41409bdd876768191a63af804de2abe99 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 2 Feb 2022 20:00:28 +0100 Subject: [PATCH 05/93] feat: improve overall performance by removing thousands of unneeded calls per minute for free/malloc --- include/server.h | 15 ++++++++++++++- src/bitset/bitset.c | 6 +++--- src/lib/lib_action.c | 4 ++-- src/server.c | 23 ++++++++++++++++++++++- src/tagset.c | 28 ++++++++++------------------ 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/include/server.h b/include/server.h index 860aa01f..ef9dd6a5 100644 --- a/include/server.h +++ b/include/server.h @@ -76,6 +76,11 @@ struct server { BitSet *previous_bitset; // a global bitset to hold temporary values useful to improve performance struct BitSet *tmp_bitset; + // this variable ought to be only used by bitset.c everything other is + // UB so be careful. + // We have this to avoid calling malloc/free too often thus improving + // performance. + struct BitSet *local_tmp_bitset; struct monitor *selected_monitor; @@ -154,7 +159,15 @@ void server_set_selected_monitor(struct monitor *m); void server_center_default_cursor_in_monitor(struct monitor *m); -BitSet *server_get_tmp_bitset(); +/* This set of functions can be used everywhere except for bitset.c. If you do + * it is UB */ +BitSet *server_bitset_get_tmp(); +BitSet *server_bitset_get_tmp_copy(BitSet *bitset); + +/* The functions are only allowed to be called from bitset.c and offer a slight + * performance boost */ +BitSet *server_bitset_get_local_tmp(); +BitSet *server_bitset_get_local_tmp_copy(BitSet *bitset); struct tag *server_get_selected_tag(); struct layout *server_get_selected_layout(); diff --git a/src/bitset/bitset.c b/src/bitset/bitset.c index bb7d715a..fd100fac 100644 --- a/src/bitset/bitset.c +++ b/src/bitset/bitset.c @@ -7,6 +7,7 @@ #include "stringop.h" #include "utils/stringUtils.h" #include "utils/coreUtils.h" +#include "server.h" /****************** INTERFACE ******************/ @@ -61,14 +62,13 @@ void bitset_assign_bitset(BitSet** dest, BitSet* source) void bitset_reverse(BitSet *bitset, int start, int end) { - BitSet *bitset_tmp = bitset_copy(bitset); + BitSet *bitset_tmp = server_bitset_get_local_tmp_copy(bitset); for (int i = start; i < end; i++) { int high = end - 1; int reverse_i = high - i; bool b = bitset_test(bitset_tmp, reverse_i); bitset_assign(bitset, i, b); } - bitset_destroy(bitset_tmp); } int bitset_swap(BitSet* destination, BitSet* source) @@ -80,7 +80,7 @@ int bitset_swap(BitSet* destination, BitSet* source) if (destination == NULL) return BITSET_ERROR; if (source == NULL) return BITSET_ERROR; - BitSet *tmp = bitset_copy(destination); + BitSet *tmp = server_bitset_get_local_tmp_copy(destination); bitset_assign_bitset(&destination, source); bitset_assign_bitset(&source, tmp); diff --git a/src/lib/lib_action.c b/src/lib/lib_action.c index 45564074..a4f7ce47 100644 --- a/src/lib/lib_action.c +++ b/src/lib/lib_action.c @@ -401,8 +401,8 @@ int lib_toggle_tags(lua_State *L) { struct monitor *m = server_get_selected_monitor(); struct tag *tag = monitor_get_active_tag(m); - BitSet *bitset = bitset_copy(tag->prev_tags); - tagset_set_tags(tag, bitset); + BitSet *prev_tags_copy = server_bitset_get_tmp_copy(tag->prev_tags); + tagset_set_tags(tag, prev_tags_copy); return 0; } diff --git a/src/server.c b/src/server.c index be7f0af1..ed9c2329 100644 --- a/src/server.c +++ b/src/server.c @@ -215,6 +215,7 @@ void init_server() server.previous_tag = 0; server.previous_bitset = bitset_create(); server.tmp_bitset = bitset_create(); + server.local_tmp_bitset = bitset_create(); server_prohibit_reloading_config(); @@ -236,6 +237,7 @@ void finalize_server() bitset_destroy(server.tmp_bitset); bitset_destroy(server.previous_bitset); + bitset_destroy(server.local_tmp_bitset); g_ptr_array_unref(server.mons); g_ptr_array_unref(server.popups); @@ -548,11 +550,30 @@ void server_center_default_cursor_in_monitor(struct monitor *m) center_cursor_in_monitor(cursor, m); } -BitSet *server_get_tmp_bitset() +BitSet *server_bitset_get_tmp() { return server.tmp_bitset; } +BitSet *server_bitset_get_tmp_copy(BitSet *bitset) +{ + BitSet *tmp = server.tmp_bitset; + bitset_assign_bitset(&tmp, bitset); + return tmp; +} + +BitSet *server_bitset_get_local_tmp() +{ + return server.local_tmp_bitset; +} + +BitSet *server_bitset_get_local_tmp_copy(BitSet *bitset) +{ + BitSet *tmp = server.local_tmp_bitset; + bitset_assign_bitset(&tmp, bitset); + return tmp; +} + struct tag *server_get_selected_tag() { struct monitor *m = server_get_selected_monitor(); diff --git a/src/tagset.c b/src/tagset.c index 697cc7cf..c21a5bc3 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -71,12 +71,12 @@ void tagset_set_tags(struct tag *sel_tag, BitSet *tags) { // we need to copy to not accidentially destroy the same thing we are // working with which can happen through assign_bitset - BitSet *tags_copy = bitset_copy(tags); + BitSet *tmp = server_bitset_get_tmp_copy(sel_tag->tags); tag_set_prev_tags(sel_tag, sel_tag->tags); tagset_tags_disconnect(sel_tag); - tagset_assign_tags(sel_tag, tags_copy); + tagset_assign_tags(sel_tag, tmp); tagset_tags_connect(sel_tag); tag_damage(sel_tag); tagset_load_tags(sel_tag, sel_tag->tags); @@ -84,7 +84,6 @@ void tagset_set_tags(struct tag *sel_tag, BitSet *tags) arrange_layers(server_get_selected_monitor()); tag_focus_most_recent_container(sel_tag); - bitset_destroy(tags_copy); ipc_event_tag(); } @@ -298,8 +297,7 @@ void focus_tagset(struct tag *tag, BitSet *tags) if(!tag) return; - BitSet *tags_copy = bitset_copy(tags); - + BitSet *tags_copy = server_bitset_get_tmp_copy(tags); tagset_assign_tags(tag, tags_copy); struct monitor *prev_m = server_get_selected_monitor(); @@ -327,8 +325,6 @@ void focus_tagset(struct tag *tag, BitSet *tags) struct seat *seat = input_manager_get_default_seat(); cursor_rebase(seat->cursor); - - bitset_destroy(tags_copy); } void tag_write_to_tags(struct tag *tag) @@ -363,9 +359,8 @@ void push_tagset(struct tag *sel_tag, BitSet *tags) void tagset_focus_tag(struct tag *tag) { - BitSet *tags = bitset_copy(tag->tags); + BitSet *tags = server_bitset_get_tmp_copy(tag->tags); tagset_focus_tags(tag, tags); - bitset_destroy(tags); } void tagset_toggle_add(struct monitor *m, BitSet *bitset) @@ -373,13 +368,11 @@ void tagset_toggle_add(struct monitor *m, BitSet *bitset) if (!m) return; - BitSet *new_bitset = bitset_copy(bitset); - bitset_xor(new_bitset, monitor_get_tags(m)); + BitSet *bitset_copy = server_bitset_get_tmp_copy(bitset); + bitset_xor(bitset_copy, monitor_get_tags(m)); struct tag *tag = monitor_get_active_tag(m); - tagset_set_tags(tag, new_bitset); - - bitset_destroy(new_bitset); + tagset_set_tags(tag, bitset_copy); } void tagset_focus_tags(struct tag *tag, struct BitSet *bitset) @@ -556,10 +549,9 @@ void tag_id_to_tag(BitSet *dest, int tag_id) bool tagset_contains_sticky_client(BitSet *tagset_tags, struct client *c) { - BitSet *tmp = server_get_tmp_bitset(); - bitset_assign_bitset(&tmp, tagset_tags); - bitset_and(tmp, tagset_tags); - bool contains = bitset_any(tmp); + BitSet *tagset_tags_copy = server_bitset_get_tmp_copy(tagset_tags); + bitset_and(tagset_tags_copy, tagset_tags); + bool contains = bitset_any(tagset_tags_copy); return contains; } From 4b00f93e8a430fd2e2827905039384319f49f1a6 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 2 Feb 2022 20:14:26 +0100 Subject: [PATCH 06/93] test/refactor: refactor code so that tests work --- src/bitset/bitset.c | 2 ++ src/server.c | 18 +++++++++++++----- src/tagset.c | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/bitset/bitset.c b/src/bitset/bitset.c index fd100fac..01680ca4 100644 --- a/src/bitset/bitset.c +++ b/src/bitset/bitset.c @@ -88,6 +88,8 @@ int bitset_swap(BitSet* destination, BitSet* source) } void bitset_destroy(BitSet* bitset) { + if (!bitset) + return; g_hash_table_unref(bitset->bytes); free(bitset); } diff --git a/src/server.c b/src/server.c index ed9c2329..1ec2dce2 100644 --- a/src/server.c +++ b/src/server.c @@ -214,8 +214,6 @@ void init_server() server.previous_tag = 0; server.previous_bitset = bitset_create(); - server.tmp_bitset = bitset_create(); - server.local_tmp_bitset = bitset_create(); server_prohibit_reloading_config(); @@ -235,8 +233,11 @@ void finalize_server() finalize_lists(&server); - bitset_destroy(server.tmp_bitset); bitset_destroy(server.previous_bitset); + + // NOTE: these bitsets are created lazily, so they may be NULL but that is + // ok since bitset_destroy handles this case. + bitset_destroy(server.tmp_bitset); bitset_destroy(server.local_tmp_bitset); g_ptr_array_unref(server.mons); @@ -552,24 +553,31 @@ void server_center_default_cursor_in_monitor(struct monitor *m) BitSet *server_bitset_get_tmp() { + if (!server.tmp_bitset) { + server.tmp_bitset = bitset_create(); + } return server.tmp_bitset; } BitSet *server_bitset_get_tmp_copy(BitSet *bitset) { - BitSet *tmp = server.tmp_bitset; + BitSet *tmp = server_bitset_get_tmp(); bitset_assign_bitset(&tmp, bitset); return tmp; } BitSet *server_bitset_get_local_tmp() { + if (!server.local_tmp_bitset) { + server.local_tmp_bitset = bitset_create(); + } + return server.local_tmp_bitset; } BitSet *server_bitset_get_local_tmp_copy(BitSet *bitset) { - BitSet *tmp = server.local_tmp_bitset; + BitSet *tmp = server_bitset_get_local_tmp(); bitset_assign_bitset(&tmp, bitset); return tmp; } diff --git a/src/tagset.c b/src/tagset.c index c21a5bc3..c90c0e80 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -549,7 +549,7 @@ void tag_id_to_tag(BitSet *dest, int tag_id) bool tagset_contains_sticky_client(BitSet *tagset_tags, struct client *c) { - BitSet *tagset_tags_copy = server_bitset_get_tmp_copy(tagset_tags); + BitSet *tagset_tags_copy = server_bitset_get_tmp_copy(c->sticky_tags); bitset_and(tagset_tags_copy, tagset_tags); bool contains = bitset_any(tagset_tags_copy); return contains; From beb0a80eb6153b20f7d94b4c0fc9b6256871b6e5 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 2 Feb 2022 21:11:43 +0100 Subject: [PATCH 07/93] improve performance --- src/container.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/container.c b/src/container.c index 2dd98d2e..40fca28b 100644 --- a/src/container.c +++ b/src/container.c @@ -1038,7 +1038,7 @@ int get_position_in_container_stack(struct container *con) struct tag *container_get_current_tag(struct container *con) { - // why prioritize the selected monitor/therefore the selected tag + // we prioritize the selected monitor/therefore the selected tag struct monitor *sel_m = server_get_selected_monitor(); struct tag *sel_tag = monitor_get_active_tag(sel_m); if (tagset_exist_on(sel_m, con)) { @@ -1047,8 +1047,8 @@ struct tag *container_get_current_tag(struct container *con) for (int i = 0; i < server.mons->len; i++) { struct monitor *m = g_ptr_array_index(server.mons, i); - // this prevents the selected monitor from being checked twice the it is - // just for optimization + // this prevents the selected monitor from being checked twice to + // improve performance if (m == sel_m) { continue; } From 428e9bf0d66f5435310508e88f5789a26e6ca544 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 2 Feb 2022 21:18:04 +0100 Subject: [PATCH 08/93] fix: fix regression --- src/tagset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tagset.c b/src/tagset.c index c90c0e80..522bf726 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -71,12 +71,12 @@ void tagset_set_tags(struct tag *sel_tag, BitSet *tags) { // we need to copy to not accidentially destroy the same thing we are // working with which can happen through assign_bitset - BitSet *tmp = server_bitset_get_tmp_copy(sel_tag->tags); + BitSet *tags_copy = server_bitset_get_tmp_copy(tags); tag_set_prev_tags(sel_tag, sel_tag->tags); tagset_tags_disconnect(sel_tag); - tagset_assign_tags(sel_tag, tmp); + tagset_assign_tags(sel_tag, tags_copy); tagset_tags_connect(sel_tag); tag_damage(sel_tag); tagset_load_tags(sel_tag, sel_tag->tags); From 1f99595085250038c82c8b71c1cc7e77380bff34 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 00:46:55 +0100 Subject: [PATCH 09/93] add container borders --- include/container.h | 25 +++++++++++++++++++---- meson.build | 2 +- src/client.c | 2 +- src/container.c | 48 +++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/include/container.h b/include/container.h index 9d72bcd6..a6317378 100644 --- a/include/container.h +++ b/include/container.h @@ -10,12 +10,19 @@ struct monitor; struct resize_constraints; struct tag; +struct direction_value { + int top; + int bottom; + int left; + int right; +}; + struct container_property { // geometry on each layout struct wlr_box geom; struct wlr_box floating_geom; /* layout-relative, includes border */ - int border_width; + struct direction_value border_width; bool floating; bool hidden; struct container *con; @@ -38,7 +45,10 @@ struct container { bool has_border; bool on_scratchpad; bool on_top; - bool is_unmanaged; + + struct direction_value border_width; + struct direction_value padding; + struct direction_value margin; // height = ratio * width float ratio; @@ -110,11 +120,18 @@ struct wlr_box *container_get_tiled_geom(struct container *con); struct wlr_box *container_get_floating_geom(struct container *con); struct wlr_box *container_get_current_geom(struct container *con); +struct wlr_box container_content_geometry_to_box(struct container *con, + struct wlr_box geom); +struct wlr_box container_box_to_content_geometry(struct container *con, + struct wlr_box geom); + bool container_get_hidden(struct container *con); bool container_get_hidden_at_tag(struct container *con, struct tag *tag); -void container_set_border_width(struct container *con, int border_width); -int container_get_border_width(struct container *con); +struct direction_value direction_value_uniform(int value); + +void container_set_border_width(struct container *con, struct direction_value border_width); +struct direction_value container_get_border_width(struct container *con); void container_set_just_tag_id(struct container *con, int tag_id); void container_set_tag_id(struct container *con, int tag_id); diff --git a/meson.build b/meson.build index 43a5e87e..5ddad56b 100644 --- a/meson.build +++ b/meson.build @@ -163,7 +163,7 @@ deps = [\ wayland_client, wayland_protos, dependency('pixman-1'), - dependency('wlroots', version: ['>=0.15' ,'< 0.16']), + dependency('wlroots', version: ['>=0.15' ,'<0.17']), dependency('x11'), dependency('json-c'), dependency('libnotify'), diff --git a/src/client.c b/src/client.c index c0a65d8b..87d6415e 100644 --- a/src/client.c +++ b/src/client.c @@ -319,7 +319,7 @@ void reset_floating_client_borders(int border_px) if (!tagset_exist_on(m, con)) { continue; } - container_set_border_width(con, border_px); + container_set_border_width(con, direction_value_uniform(border_px)); container_damage_whole(con); } } diff --git a/src/container.c b/src/container.c index 40fca28b..42fa823e 100644 --- a/src/container.c +++ b/src/container.c @@ -756,7 +756,7 @@ void move_container(struct container *con, struct wlr_cursor *cursor, int offset struct monitor *m = server_get_selected_monitor(); struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); - container_set_border_width(con, lt->options->float_border_px); + container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); container_damage(con, true); } @@ -864,6 +864,16 @@ void container_set_floating_geom(struct container *con, struct wlr_box *geom) container_set_floating_geom_at_tag(con, geom, tag); } +struct direction_value direction_value_uniform(int value) +{ + return (struct direction_value){ + .bottom = value, + .top = value, + .left = value, + .right = value, + }; +} + struct wlr_box *container_get_tiled_geom_at_tag(struct container *con, struct tag *tag) { struct container_property *property = @@ -936,6 +946,32 @@ struct wlr_box *container_get_current_geom(struct container *con) return geom; } +struct wlr_box container_content_geometry_to_box(struct container *con, + struct wlr_box geom) +{ + struct direction_value borders = container_get_border_width(con); + struct wlr_box box_geom = { + .x = geom.x + borders.left, + .y = geom.y + borders.top, + .width = geom.width - borders.left - borders.right, + .height = geom.height - borders.top - borders.bottom, + }; + return box_geom; +} + +struct wlr_box container_box_to_content_geometry(struct container *con, + struct wlr_box geom) +{ + struct direction_value borders = container_get_border_width(con); + struct wlr_box content_geom = { + .x = geom.x + borders.left, + .y = geom.y + borders.top, + .width = geom.width - borders.left - borders.right, + .height = geom.height - borders.top - borders.bottom, + }; + return content_geom; +} + bool container_get_hidden(struct container *con) { struct container_property *property = container_get_property(con); @@ -944,19 +980,23 @@ bool container_get_hidden(struct container *con) return property->hidden; } -void container_set_border_width(struct container *con, int border_width) +void container_set_border_width(struct container *con, struct direction_value border_width) { + if (!con) + return; + struct container_property *property = container_get_property(con); if (!property) return; + property->border_width = border_width; } -int container_get_border_width(struct container *con) +struct direction_value container_get_border_width(struct container *con) { struct container_property *property = container_get_property(con); if (!property) - return 0; + return direction_value_uniform(0); return property->border_width; } From b86a9ff380f07a6220531826f1701797aaa39500 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 01:27:17 +0100 Subject: [PATCH 10/93] feat add simple border logic --- include/container.h | 33 ++--- include/lib/lib_geom.h | 4 +- include/popup.h | 2 +- src/client.c | 4 +- src/container.c | 224 +++++++++++++++---------------- src/cursor.c | 30 ++--- src/ipc-json.c | 3 +- src/layer_shell.c | 2 +- src/lib/lib_container_property.c | 2 +- src/lib/lib_geom.c | 78 +++++------ src/lib/lib_root.c | 2 +- src/popup.c | 21 +-- src/render/render.c | 94 ++++++------- src/scratchpad.c | 4 +- src/tagset.c | 6 +- src/tile/tileUtils.c | 18 ++- src/xwayland.c | 4 +- 17 files changed, 256 insertions(+), 275 deletions(-) diff --git a/include/container.h b/include/container.h index a6317378..8839f090 100644 --- a/include/container.h +++ b/include/container.h @@ -38,6 +38,7 @@ struct container { int tag_id; + bool is_unmanaged; bool is_exclusive; bool is_on_tile; bool is_xwayland_popup; @@ -60,8 +61,8 @@ struct container *create_container(struct client *c, struct monitor *m, bool has void destroy_container(struct container *con); bool container_property_is_floating(struct container_property *property); -struct wlr_box *container_property_get_floating_geom(struct container_property *property); -void container_property_set_floating_geom(struct container_property *property, struct wlr_box *geom); +struct wlr_box container_property_get_floating_geom(struct container_property *property); +void container_property_set_floating_geom(struct container_property *property, struct wlr_box geom); void container_property_set_floating(struct container_property *property, bool floating); void add_container_to_tile(struct container *con); @@ -82,7 +83,7 @@ void ack_configure(struct wl_listener *listener, void *data); void apply_bounds(struct container *con, struct wlr_box bbox); void commit_notify(struct wl_listener *listener, void *data); void configure_notify(struct wl_listener *listener, void *data); -void container_damage_borders(struct container *con, struct monitor *m, struct wlr_box *geom); +void container_damage_borders(struct container *con, struct monitor *m, struct wlr_box geom); void container_damage_part(struct container *con); void container_damage_whole(struct container *con); void container_fix_position_to_begin(struct container *con); @@ -108,17 +109,17 @@ struct container_property *container_get_property_at_tag( struct tag *tag); void container_set_floating_geom_at_tag(struct container *con, - struct wlr_box *geom, struct tag *tag); -void container_set_current_geom(struct container *con, struct wlr_box *geom); -void container_set_tiled_geom(struct container *con, struct wlr_box *geom); -void container_set_floating_geom(struct container *con, struct wlr_box *geom); - -struct wlr_box *container_get_tiled_geom_at_tag(struct container *con, struct tag *tag); -struct wlr_box *container_get_floating_geom_at_tag(struct container *con, struct tag *tag); -struct wlr_box *container_get_current_geom_at_tag(struct container *con, struct tag *tag); -struct wlr_box *container_get_tiled_geom(struct container *con); -struct wlr_box *container_get_floating_geom(struct container *con); -struct wlr_box *container_get_current_geom(struct container *con); + struct wlr_box geom, struct tag *tag); +void container_set_current_geom(struct container *con, struct wlr_box geom); +void container_set_tiled_geom(struct container *con, struct wlr_box geom); +void container_set_floating_geom(struct container *con, struct wlr_box geom); + +struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag *tag); +struct wlr_box container_get_floating_geom_at_tag(struct container *con, struct tag *tag); +struct wlr_box container_get_current_geom_at_tag(struct container *con, struct tag *tag); +struct wlr_box container_get_tiled_geom(struct container *con); +struct wlr_box container_get_floating_geom(struct container *con); +struct wlr_box container_get_current_geom(struct container *con); struct wlr_box container_content_geometry_to_box(struct container *con, struct wlr_box geom); @@ -140,8 +141,8 @@ void move_container_to_tag(struct container *con, struct tag *tag); struct monitor *container_get_monitor(struct container *con); -int absolute_x_to_container_relative(struct wlr_box *geom, int x); -int absolute_y_to_container_relative(struct wlr_box *geom, int y); +int absolute_x_to_container_relative(struct wlr_box geom, int x); +int absolute_y_to_container_relative(struct wlr_box geom, int y); int get_position_in_container_focus_stack(struct container *con); int get_position_in_container_stack(struct container *con); diff --git a/include/lib/lib_geom.h b/include/lib/lib_geom.h index 707f3068..4d4367bd 100644 --- a/include/lib/lib_geom.h +++ b/include/lib/lib_geom.h @@ -5,9 +5,9 @@ #include #include -void create_lua_geometry(lua_State *L, struct wlr_box *geom); +void create_lua_geometry(lua_State *L, struct wlr_box geom); void lua_load_geom(lua_State *L); -struct wlr_box *check_geometry(lua_State *L, int argn); +struct wlr_box check_geometry(lua_State *L, int argn); // static methods // methods diff --git a/include/popup.h b/include/popup.h index 7142263f..03975fc6 100644 --- a/include/popup.h +++ b/include/popup.h @@ -19,7 +19,7 @@ struct xdg_popup { }; struct xdg_popup *create_popup(struct monitor *m, struct wlr_xdg_popup *xdg_popup, - struct wlr_box *parent_geom, struct container* toplevel); + struct wlr_box parent_geom, struct container* toplevel); void popup_handle_destroy(struct wl_listener *listener, void *data); void destroy_popups(); struct wlr_surface *get_popup_surface_under_cursor(struct cursor *cursor, double *sx, double *sy); diff --git a/src/client.c b/src/client.c index 87d6415e..eb96f867 100644 --- a/src/client.c +++ b/src/client.c @@ -132,7 +132,7 @@ void focus_client(struct seat *seat, struct client *old, struct client *c) cursor_constrain(seat->cursor, NULL); unfocus_client(old); struct container *old_con = old->con; - struct wlr_box *geom = container_get_current_geom(old_con); + struct wlr_box geom = container_get_current_geom(old_con); struct monitor *m = container_get_monitor(old_con); container_damage_borders(old_con, m, geom); } @@ -156,7 +156,7 @@ void focus_client(struct seat *seat, struct client *old, struct client *c) struct container *con = c->con; struct monitor *m = container_get_monitor(con); - struct wlr_box *geom = container_get_current_geom(con); + struct wlr_box geom = container_get_current_geom(con); container_damage_borders(con, m, geom); /* Activate the new client */ diff --git a/src/container.c b/src/container.c index 42fa823e..a6de009f 100644 --- a/src/container.c +++ b/src/container.c @@ -48,19 +48,19 @@ bool container_property_is_floating(struct container_property *property) return property->floating; } -struct wlr_box *container_property_get_floating_geom(struct container_property *property) +struct wlr_box container_property_get_floating_geom(struct container_property *property) { struct container *con = property->con; - struct wlr_box *geom = &property->floating_geom; + struct wlr_box geom = property->floating_geom; if (con->client->type == LAYER_SHELL) { - geom = &con->global_geom; + geom = con->global_geom; } return geom; } void container_property_set_floating_geom(struct container_property *property, - struct wlr_box *geom) + struct wlr_box geom) { struct container *con = property->con; struct wlr_box *old_geom = &property->floating_geom; @@ -69,7 +69,7 @@ void container_property_set_floating_geom(struct container_property *property, old_geom = &con->global_geom; } - *old_geom = *geom; + *old_geom = geom; } void container_property_set_floating(struct container_property *property, bool floating) @@ -176,45 +176,43 @@ void remove_container_from_tile(struct container *con) ipc_event_tag(); } -void container_damage_borders(struct container *con, struct monitor *m, struct wlr_box *geom) -{ - if (!con) - return; - if (!geom) - return; - - if (!m) - return; - - int border_width = container_get_border_width(con); - double ox = geom->x - border_width; - double oy = geom->y - border_width; - wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); - int w = geom->width; - int h = geom->height; - - struct wlr_box *borders; - borders = (struct wlr_box[4]) { - {ox, oy, w + 2 * border_width, border_width}, /* top */ - {ox, oy + border_width, border_width, h}, /* left */ - {ox + border_width + w, oy + border_width, border_width, h}, /* right */ - {ox, oy + border_width + h, w + 2 * border_width, border_width}, /* bottom */ - }; - - pthread_mutex_lock(&lock_rendering_action); - for (int i = 0; i < 4; i++) { - scale_box(&borders[i], m->wlr_output->scale); - wlr_output_damage_add_box(m->damage, &borders[i]); - } - pthread_mutex_unlock(&lock_rendering_action); -} - -static void damage_container_area(struct container *con, struct wlr_box *geom, +void container_damage_borders(struct container *con, struct monitor *m, struct wlr_box geom) +{ + // TODO: rewrite this function + // if (!con) + // return; + // if (!m) + // return; + // + // int border_width = container_get_border_width(con); + // double ox = geom->x - border_width; + // double oy = geom->y - border_width; + // wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); + // int w = geom->width; + // int h = geom->height; + // + // struct wlr_box *borders; + // borders = (struct wlr_box[4]) { + // {ox, oy, w + 2 * border_width, border_width}, /* top */ + // {ox, oy + border_width, border_width, h}, /* left */ + // {ox + border_width + w, oy + border_width, border_width, h}, /* right */ + // {ox, oy + border_width + h, w + 2 * border_width, border_width}, /* bottom */ + // }; + // + // pthread_mutex_lock(&lock_rendering_action); + // for (int i = 0; i < 4; i++) { + // scale_box(&borders[i], m->wlr_output->scale); + // wlr_output_damage_add_box(m->damage, &borders[i]); + // } + // pthread_mutex_unlock(&lock_rendering_action); +} + +static void damage_container_area(struct container *con, struct wlr_box geom, bool whole) { for (int i = 0; i < server.mons->len; i++) { struct monitor *m = g_ptr_array_index(server.mons, i); - output_damage_surface(m, get_wlrsurface(con->client), geom, whole); + output_damage_surface(m, get_wlrsurface(con->client), &geom, whole); container_damage_borders(con, m, geom); } } @@ -222,17 +220,13 @@ static void damage_container_area(struct container *con, struct wlr_box *geom, static void container_damage(struct container *con, bool whole) { for (int i = 0; i < server.mons->len; i++) { - struct wlr_box *con_geom = container_get_current_geom(con); - - if (!con_geom) - continue; - + struct wlr_box con_geom = container_get_current_geom(con); damage_container_area(con, con_geom, whole); } struct client *c = con->client; if (c->resized || c->moved_tag) { - damage_container_area(con, &con->prev_geom, whole); + damage_container_area(con, con->prev_geom, whole); c->resized = false; c->moved_tag = false; } @@ -272,7 +266,8 @@ struct container *xy_to_container(double x, double y) continue; if (!container_viewable_on_monitor(m, con)) continue; - if (!wlr_box_contains_point(container_get_current_geom(con), x, y)) + struct wlr_box geom = container_get_current_geom(con); + if (!wlr_box_contains_point(&geom, x, y)) continue; g_ptr_array_unref(stack_set); @@ -392,22 +387,23 @@ struct wlr_fbox lua_togeometry(lua_State *L) void apply_bounds(struct container *con, struct wlr_box box) { /* set minimum possible */ - struct wlr_box *con_geom = container_get_current_geom(con); - if (!con_geom) - return; - con_geom->width = MAX(MIN_CONTAINER_WIDTH, con_geom->width); - con_geom->height = MAX(MIN_CONTAINER_HEIGHT, con_geom->height); + struct wlr_box con_geom = container_get_current_geom(con); + con_geom.width = MAX(MIN_CONTAINER_WIDTH, con_geom.width); + con_geom.height = MAX(MIN_CONTAINER_HEIGHT, con_geom.height); - int border_width = container_get_border_width(con); + // TODO: fix this part + // int border_width = container_get_border_width(con); + // + // if (con_geom->x >= box.x + box.width) + // con_geom->x = box.x + box.width - con_geom->width; + // if (con_geom->y >= box.y + box.height) + // con_geom->y = box.y + box.height - con_geom->height; + // if (con_geom->x + con_geom->width + 2 * border_width <= box.x) + // con_geom->x = box.x; + // if (con_geom->y + con_geom->height + 2 * border_width <= box.y) + // con_geom->y = box.y; - if (con_geom->x >= box.x + box.width) - con_geom->x = box.x + box.width - con_geom->width; - if (con_geom->y >= box.y + box.height) - con_geom->y = box.y + box.height - con_geom->height; - if (con_geom->x + con_geom->width + 2 * border_width <= box.x) - con_geom->x = box.x; - if (con_geom->y + con_geom->height + 2 * border_width <= box.y) - con_geom->y = box.y; + container_set_current_geom(con, con_geom); } void commit_notify(struct wl_listener *listener, void *data) @@ -487,7 +483,7 @@ void focus_on_hidden_stack(struct monitor *m, int i) container_set_floating(con, NULL, true); container_set_floating(sel, NULL, false); - struct wlr_box *sel_geom = container_get_floating_geom(sel); + struct wlr_box sel_geom = container_get_floating_geom(sel); container_set_floating_geom(con, sel_geom); } @@ -548,7 +544,7 @@ void swap_on_hidden_stack(struct monitor *m, int i) container_set_floating(con, NULL, true); container_set_floating(sel, NULL, false); - struct wlr_box *sel_geom = container_get_floating_geom(sel); + struct wlr_box sel_geom = container_get_floating_geom(sel); container_set_floating_geom(con, sel_geom); } @@ -740,8 +736,7 @@ void move_container(struct container *con, struct wlr_cursor *cursor, int offset return; struct tag *con_tag = container_get_current_tag(server.grab_c); - struct wlr_box *con_geom = container_get_current_geom_at_tag(server.grab_c, con_tag); - struct wlr_box geom = *con_geom; + struct wlr_box geom = container_get_current_geom_at_tag(server.grab_c, con_tag); geom.x = cursor->x - offsetx; geom.y = cursor->y - offsety; @@ -752,7 +747,7 @@ void move_container(struct container *con, struct wlr_cursor *cursor, int offset container_set_floating(con, container_fix_position, true); arrange(); } - container_set_floating_geom_at_tag(con, &geom, con_tag); + container_set_floating_geom_at_tag(con, geom, con_tag); struct monitor *m = server_get_selected_monitor(); struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); @@ -783,7 +778,7 @@ struct container_property *container_get_property_at_tag( return property; } -void container_set_current_geom(struct container *con, struct wlr_box *geom) +void container_set_current_geom(struct container *con, struct wlr_box geom) { struct tag *tag = container_get_current_tag(con); struct layout *lt = tag_get_layout(tag); @@ -794,12 +789,12 @@ void container_set_current_geom(struct container *con, struct wlr_box *geom) } } -void container_set_tiled_geom(struct container *con, struct wlr_box *geom) +void container_set_tiled_geom(struct container *con, struct wlr_box geom) { - struct wlr_box *con_geom = container_get_tiled_geom(con); + struct wlr_box con_geom = container_get_tiled_geom(con); if (con->client->type == LAYER_SHELL) { - con_geom = &con->global_geom; + con_geom = con->global_geom; } bool preserve_ratio = con->ratio != 0; @@ -808,39 +803,41 @@ void container_set_tiled_geom(struct container *con, struct wlr_box *geom) * con->geom.height = con->geom.width * con->ratio is inside geom.width * and geom.height * */ - int available_height = geom->height; - int available_width = geom->width; + int available_height = geom.height; + int available_width = geom.width; if (con->ratio <= 1) { // use geom->width - int proposed_height = geom->width * con->ratio; + int proposed_height = geom.width * con->ratio; if (proposed_height > available_height) { float anti_ratio = 1/con->ratio; - int proposed_width = geom->height * anti_ratio; - geom->width = MIN(proposed_width, available_width); + int proposed_width = geom.height * anti_ratio; + geom.width = MIN(proposed_width, available_width); } else { - geom->height = MIN(proposed_height, available_height); + geom.height = MIN(proposed_height, available_height); } } else { float anti_ratio = 1/con->ratio; - int proposed_width = geom->height * anti_ratio; + int proposed_width = geom.height * anti_ratio; if (proposed_width > available_width) { - int proposed_height = geom->width * con->ratio; - geom->height = MIN(proposed_height, available_height); + int proposed_height = geom.width * con->ratio; + geom.height = MIN(proposed_height, available_height); } else { - geom->width = MIN(proposed_width, available_width); + geom.width = MIN(proposed_width, available_width); } } - geom->y += available_height/2 - geom->height/2; - geom->x += available_width/2 - geom->width/2; + geom.y += available_height/2 - geom.height/2; + geom.x += available_width/2 - geom.width/2; } - - con->prev_geom = *con_geom; - *con_geom = *geom; + con->prev_geom = con_geom; + struct container_property *property = container_get_property(con); + if (!property) + return; + property->geom = geom; } void container_set_floating_geom_at_tag(struct container *con, - struct wlr_box *geom, struct tag *tag) + struct wlr_box geom, struct tag *tag) { struct container_property *property = container_get_property_at_tag(con, tag); @@ -854,11 +851,11 @@ void container_set_floating_geom_at_tag(struct container *con, } con->prev_geom = *con_geom; - *con_geom = *geom; + *con_geom = geom; container_update_size(con); } -void container_set_floating_geom(struct container *con, struct wlr_box *geom) +void container_set_floating_geom(struct container *con, struct wlr_box geom) { struct tag *tag = container_get_current_tag(con); container_set_floating_geom_at_tag(con, geom, tag); @@ -874,30 +871,30 @@ struct direction_value direction_value_uniform(int value) }; } -struct wlr_box *container_get_tiled_geom_at_tag(struct container *con, struct tag *tag) +struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag *tag) { struct container_property *property = g_ptr_array_index(con->properties, tag->id); - struct wlr_box *geom = &property->geom; + struct wlr_box geom = property->geom; if (con->client->type == LAYER_SHELL) { - geom = &con->global_geom; + geom = con->global_geom; } return geom; } -struct wlr_box *container_get_tiled_geom(struct container *con) +struct wlr_box container_get_tiled_geom(struct container *con) { struct tag *tag = container_get_current_tag(con); if (!tag) - return NULL; + return (struct wlr_box){0}; - struct wlr_box *geom = container_get_tiled_geom_at_tag(con, tag); + struct wlr_box geom = container_get_tiled_geom_at_tag(con, tag); return geom; } -struct wlr_box *container_get_floating_geom_at_tag(struct container *con, struct tag *tag) +struct wlr_box container_get_floating_geom_at_tag(struct container *con, struct tag *tag) { struct container_property *property = g_ptr_array_index(con->properties, tag->id); @@ -905,27 +902,27 @@ struct wlr_box *container_get_floating_geom_at_tag(struct container *con, struct return container_property_get_floating_geom(property); } -struct wlr_box *container_get_floating_geom(struct container *con) +struct wlr_box container_get_floating_geom(struct container *con) { if (!con) - return NULL; + return (struct wlr_box){0}; struct tag *tag = container_get_current_tag(con); if (!tag) { - return NULL; + return (struct wlr_box){0}; } return container_get_floating_geom_at_tag(con, tag); } -struct wlr_box *container_get_current_geom_at_tag(struct container *con, struct tag *tag) +struct wlr_box container_get_current_geom_at_tag(struct container *con, struct tag *tag) { if (!con) - return NULL; + return (struct wlr_box){0}; if (!tag) - return NULL; + return (struct wlr_box){0}; - struct wlr_box *geom = NULL; + struct wlr_box geom; struct layout *lt = tag_get_layout(tag); if (container_is_unmanaged(con)) { geom = container_get_floating_geom(con); @@ -939,10 +936,10 @@ struct wlr_box *container_get_current_geom_at_tag(struct container *con, struct return geom; } -struct wlr_box *container_get_current_geom(struct container *con) +struct wlr_box container_get_current_geom(struct container *con) { struct tag *tag = container_get_current_tag(con); - struct wlr_box *geom = container_get_current_geom_at_tag(con, tag); + struct wlr_box geom = container_get_current_geom_at_tag(con, tag); return geom; } @@ -1005,11 +1002,10 @@ void resize_container(struct container *con, struct wlr_cursor *cursor, int offs if (!con) return; - struct wlr_box *con_geom = container_get_current_geom(con); - struct wlr_box geom = *con_geom; + struct wlr_box geom = container_get_current_geom(con); - geom.width = absolute_x_to_container_relative(con_geom, cursor->x - offsetx); - geom.height = absolute_y_to_container_relative(con_geom, cursor->y - offsety); + geom.width = absolute_x_to_container_relative(geom, cursor->x - offsetx); + geom.height = absolute_y_to_container_relative(geom, cursor->y - offsety); if (con->on_scratchpad) { remove_container_from_scratchpad(con); @@ -1018,11 +1014,11 @@ void resize_container(struct container *con, struct wlr_cursor *cursor, int offs container_set_floating(con, container_fix_position, true); arrange(); } - container_set_floating_geom(con, &geom); + container_set_floating_geom(con, geom); struct tag *tag = container_get_current_tag(con); struct layout *lt = tag_get_layout(tag); - container_set_border_width(con, lt->options->float_border_px); + container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); container_damage(con, true); } @@ -1043,14 +1039,14 @@ struct monitor *container_get_monitor(struct container *con) return m; } -inline int absolute_x_to_container_relative(struct wlr_box *geom, int x) +inline int absolute_x_to_container_relative(struct wlr_box geom, int x) { - return x - geom->x; + return x - geom.x; } -inline int absolute_y_to_container_relative(struct wlr_box *geom, int y) +inline int absolute_y_to_container_relative(struct wlr_box geom, int y) { - return y - geom->y; + return y - geom.y; } int get_position_in_container_focus_stack(struct container *con) diff --git a/src/cursor.c b/src/cursor.c index 3310a4dc..2eaf7e77 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -367,12 +367,12 @@ void motion_notify(struct cursor *cursor, uint32_t time_msec, // Only apply pointer constraints to real pointer input. if (cursor->active_constraint && device->type == WLR_INPUT_DEVICE_POINTER) { struct container *con = xy_to_container(cursor->wlr_cursor->x, cursor->wlr_cursor->y); - struct wlr_box *con_geom = container_get_current_geom(con); + struct wlr_box con_geom = container_get_current_geom(con); double sx; double sy; - if (con && con_geom) { - sx = cursor->wlr_cursor->x - con_geom->x; - sy = cursor->wlr_cursor->y - con_geom->y; + if (con) { + sx = cursor->wlr_cursor->x - con_geom.x; + sy = cursor->wlr_cursor->y - con_geom.y; } else { sx = cursor->wlr_cursor->x; sy = cursor->wlr_cursor->y; @@ -462,7 +462,7 @@ void move_resize(struct cursor *cursor, int ui) container_set_floating(server.grab_c, container_fix_position, true); struct tag *con_tag = container_get_current_tag(server.grab_c); - struct wlr_box *grabc_geom = container_get_current_geom_at_tag(server.grab_c, con_tag); + struct wlr_box grabc_geom = container_get_current_geom_at_tag(server.grab_c, con_tag); struct wlr_cursor *wlr_cursor = cursor->wlr_cursor; switch (cursor->cursor_mode = ui) { case CURSOR_MOVE: @@ -474,8 +474,8 @@ void move_resize(struct cursor *cursor, int ui) /* Doesn't work for X11 output - the next absolute motion event * returns the cursor to where it started */ wlr_cursor_warp_closest(wlr_cursor, NULL, - grabc_geom->x + grabc_geom->width, - grabc_geom->y + grabc_geom->height); + grabc_geom.x + grabc_geom.width, + grabc_geom.y + grabc_geom.height); wlr_xcursor_manager_set_cursor_image(cursor->xcursor_mgr, "bottom_right_corner", wlr_cursor); break; @@ -547,9 +547,9 @@ static void warp_to_constraint_cursor_hint(struct cursor *cursor) struct monitor *m = server_get_selected_monitor(); struct container *con = monitor_get_focused_container(m); - struct wlr_box *con_geom = container_get_current_geom(con); - double lx = sx + con_geom->x - m->geom.x; - double ly = sy + con_geom->x - m->geom.y; + struct wlr_box con_geom = container_get_current_geom(con); + double lx = sx + con_geom.x - m->geom.x; + double ly = sy + con_geom.x - m->geom.y; wlr_cursor_warp(cursor->wlr_cursor, NULL, lx, ly); @@ -588,10 +588,10 @@ static void check_constraint_region(struct cursor *cursor) { struct container *con = monitor_get_focused_container(m); if (cursor->active_confine_requires_warp && con) { cursor->active_confine_requires_warp = false; - struct wlr_box *con_geom = container_get_current_geom(con); + struct wlr_box con_geom = container_get_current_geom(con); - double sx = cursor->wlr_cursor->x - con_geom->x; - double sy = cursor->wlr_cursor->y - con_geom->x; + double sx = cursor->wlr_cursor->x - con_geom.x; + double sy = cursor->wlr_cursor->y - con_geom.x; if (!pixman_region32_contains_point(region, floor(sx), floor(sy), NULL)) { @@ -602,8 +602,8 @@ static void check_constraint_region(struct cursor *cursor) { double sy = (boxes[0].y1 + boxes[0].y2) / 2.; wlr_cursor_warp_closest(cursor->wlr_cursor, NULL, - sx + con_geom->x, - sy + con_geom->x); + sx + con_geom.x, + sy + con_geom.x); cursor_rebase(cursor); } diff --git a/src/ipc-json.c b/src/ipc-json.c index a06d5410..8bc134fd 100644 --- a/src/ipc-json.c +++ b/src/ipc-json.c @@ -369,9 +369,10 @@ json_object *ipc_json_describe_monitor(struct monitor *m) json_object *ipc_json_describe_container(struct container *con) { + struct wlr_box geom = container_get_current_geom(con); json_object *object = ipc_json_create_node( 5, con ? con->client->title : NULL, true, NULL, - con ? container_get_current_geom(con) : NULL); + con ? &geom : NULL); json_object_object_add(object, "type", json_object_new_string("con")); diff --git a/src/layer_shell.c b/src/layer_shell.c index 1c598fb8..8be274ac 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -275,7 +275,7 @@ void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_ar continue; } // TODO: is that correct? - container_set_current_geom(con, &box); + container_set_current_geom(con, box); if (state->exclusive_zone > 0) apply_exclusive(usable_area, state->anchor, state->exclusive_zone, diff --git a/src/lib/lib_container_property.c b/src/lib/lib_container_property.c index 786ab6d4..312a3bb4 100644 --- a/src/lib/lib_container_property.c +++ b/src/lib/lib_container_property.c @@ -102,7 +102,7 @@ int lib_container_property_set_floating(lua_State *L) int lib_container_property_set_geom(lua_State *L) { - struct wlr_box *geom = check_geometry(L, -1); + struct wlr_box geom = check_geometry(L, -1); lua_pop(L, 1); struct container_property *property = check_container_property(L, 1); diff --git a/src/lib/lib_geom.c b/src/lib/lib_geom.c index 01d39072..310f67e6 100644 --- a/src/lib/lib_geom.c +++ b/src/lib/lib_geom.c @@ -33,13 +33,9 @@ static const struct luaL_Reg geom_setter[] = { {NULL, NULL}, }; -void create_lua_geometry(lua_State *L, struct wlr_box *geom) +void create_lua_geometry(lua_State *L, struct wlr_box geom) { - if (!geom) { - lua_pushnil(L); - return; - } - struct wlr_box **user_con = lua_newuserdata(L, sizeof(struct wlr_box*)); + struct wlr_box *user_con = lua_newuserdata(L, sizeof(struct wlr_box)); *user_con = geom; luaL_setmetatable(L, CONFIG_GEOMETRY); @@ -59,11 +55,11 @@ void lua_load_geom(lua_State *L) lua_setglobal(L, "Geom"); } -struct wlr_box *check_geometry(lua_State *L, int argn) +struct wlr_box check_geometry(lua_State *L, int argn) { - void **ud = luaL_checkudata(L, argn, CONFIG_GEOMETRY); + void *ud = luaL_checkudata(L, argn, CONFIG_GEOMETRY); luaL_argcheck(L, ud != NULL, argn, "`geometry' expected"); - return (struct wlr_box *)*ud; + return *(struct wlr_box *)ud; } // static methods @@ -71,81 +67,81 @@ struct wlr_box *check_geometry(lua_State *L, int argn) // getter int lib_geometry_get_x(lua_State *L) { - struct wlr_box *geom = check_geometry(L, 1); + struct wlr_box geom = check_geometry(L, 1); lua_pop(L, 1); - lua_pushinteger(L, geom->x); + lua_pushinteger(L, geom.x); return 1; } int lib_geometry_get_y(lua_State *L) { - struct wlr_box *geom = check_geometry(L, 1); + struct wlr_box geom = check_geometry(L, 1); lua_pop(L, 1); - lua_pushinteger(L, geom->y); + lua_pushinteger(L, geom.y); return 1; } int lib_geometry_get_width(lua_State *L) { - struct wlr_box *geom = check_geometry(L, 1); + struct wlr_box geom = check_geometry(L, 1); lua_pop(L, 1); - lua_pushinteger(L, geom->width); + lua_pushinteger(L, geom.width); return 1; } int lib_geometry_get_height(lua_State *L) { - struct wlr_box *geom = check_geometry(L, 1); + struct wlr_box geom = check_geometry(L, 1); lua_pop(L, 1); - lua_pushinteger(L, geom->height); + lua_pushinteger(L, geom.height); return 1; } // setter int lib_geometry_set_x(lua_State *L) { - int x = luaL_checkinteger(L, -1); - lua_pop(L, 1); - struct wlr_box *geom = check_geometry(L, 1); - lua_pop(L, 1); - - geom->x = x; + // int x = luaL_checkinteger(L, -1); + // lua_pop(L, 1); + // struct wlr_box geom = check_geometry(L, 1); + // lua_pop(L, 1); + // + // geom.x = x; return 0; } int lib_geometry_set_y(lua_State *L) { - int y = luaL_checkinteger(L, -1); - lua_pop(L, 1); - struct wlr_box *geom = check_geometry(L, 1); - lua_pop(L, 1); - - geom->y = y; + // int y = luaL_checkinteger(L, -1); + // lua_pop(L, 1); + // struct wlr_box geom = check_geometry(L, 1); + // lua_pop(L, 1); + // + // geom.y = y; return 0; } int lib_geometry_set_width(lua_State *L) { - int width = luaL_checkinteger(L, -1); - lua_pop(L, 1); - struct wlr_box *geom = check_geometry(L, 1); - lua_pop(L, 1); - - geom->width = width; + // int width = luaL_checkinteger(L, -1); + // lua_pop(L, 1); + // struct wlr_box geom = check_geometry(L, 1); + // lua_pop(L, 1); + // + // geom.width = width; return 0; } int lib_geometry_set_height(lua_State *L) { - int height = luaL_checkinteger(L, -1); - lua_pop(L, 1); - struct wlr_box *geom = check_geometry(L, 1); - lua_pop(L, 1); - - geom->height = height; + // int height = luaL_checkinteger(L, -1); + // lua_pop(L, 1); + // struct wlr_box geom = check_geometry(L, 1); + // lua_pop(L, 1); + // + // geom.height = height; return 0; } diff --git a/src/lib/lib_root.c b/src/lib/lib_root.c index a4859b3d..12e2a192 100644 --- a/src/lib/lib_root.c +++ b/src/lib/lib_root.c @@ -66,6 +66,6 @@ int lib_root_get_area(lua_State *L) { struct root *root = check_root(L, 1); lua_pop(L, 1); - create_lua_geometry(L, &root->geom); + create_lua_geometry(L, root->geom); return 1; } diff --git a/src/popup.c b/src/popup.c index 62fc5863..3159226a 100644 --- a/src/popup.c +++ b/src/popup.c @@ -17,8 +17,6 @@ static void popup_handle_new_popup(struct wl_listener *listener, void *data); static void popup_handle_new_subpopup(struct wl_listener *listener, void *data); -struct xdg_popup *create_popup(struct monitor *m, struct wlr_xdg_popup *xdg_popup, - struct wlr_box *parent_geom, struct container* toplevel); static void destroy_popup(struct xdg_popup *xdg_popup); static void popup_handle_commit(struct wl_listener *listener, void *data); static void popup_handle_map(struct wl_listener *listener, void *data); @@ -26,14 +24,8 @@ static void popup_handle_unmap(struct wl_listener *listener, void *data); static void popup_damage(struct xdg_popup *xdg_popup, bool whole); struct xdg_popup *create_popup(struct monitor *m, struct wlr_xdg_popup *xdg_popup, - struct wlr_box *parent_geom, struct container* toplevel) + struct wlr_box parent_geom, struct container* toplevel) { - // the parent geometry may not exist we just ignore this request in that - // case - // Else we might encounter UB - if (!parent_geom) { - return NULL; - } struct xdg_popup *popup = xdg_popup->base->data = calloc(1, sizeof(*popup)); popup->xdg = xdg_popup; @@ -47,8 +39,8 @@ struct xdg_popup *create_popup(struct monitor *m, struct wlr_xdg_popup *xdg_popu wlr_xdg_popup_unconstrain_from_box(popup->xdg, &box); // the root window may be resized. This must be adjusted - popup->geom.x = popup->xdg->geometry.x + parent_geom->x; - popup->geom.y = popup->xdg->geometry.y + parent_geom->y; + popup->geom.x = popup->xdg->geometry.x + parent_geom.x; + popup->geom.y = popup->xdg->geometry.y + parent_geom.y; popup->geom.width = popup->xdg->geometry.width; popup->geom.height = popup->xdg->geometry.height; popup->m = m; @@ -114,7 +106,7 @@ static void popup_handle_new_popup(struct wl_listener *listener, void *data) struct wlr_xdg_popup *xdg_popup = data; create_popup(parent_popup->m, xdg_popup, - &parent_popup->geom, parent_popup->toplevel); + parent_popup->geom, parent_popup->toplevel); } void popup_handle_destroy(struct wl_listener *listener, void *data) @@ -141,10 +133,7 @@ struct wlr_surface *get_popup_surface_under_cursor(struct cursor *cursor, double return NULL; struct wlr_surface *surface = NULL; - struct wlr_box *con_geom = container_get_current_geom(con); - // when the container is on the tag -1 it won't have a geometry - if (!con_geom) - return NULL; + struct wlr_box con_geom = container_get_current_geom(con); switch (con->client->type) { case XDG_SHELL: diff --git a/src/render/render.c b/src/render/render.c index 99494d51..345c4fec 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -227,26 +227,26 @@ static enum wlr_edges get_hidden_edges(struct container *con, struct wlr_box *bo struct monitor *m = container_get_monitor(con); enum wlr_edges containers_hidden_edges = WLR_EDGE_NONE; - struct wlr_box *con_geom = container_get_current_geom(con); + struct wlr_box con_geom = container_get_current_geom(con); // int border_width = container_get_border_width(con); // hide edges if needed if (hidden_edges & WLR_EDGE_LEFT) { - if (con_geom->x == m->root->geom.x) { + if (con_geom.x == m->root->geom.x) { containers_hidden_edges |= WLR_EDGE_LEFT; } } if (hidden_edges & WLR_EDGE_RIGHT) { - if (is_approx_equal(con_geom->x + con_geom->width, m->root->geom.x + m->root->geom.width, 3)) { + if (is_approx_equal(con_geom.x + con_geom.width, m->root->geom.x + m->root->geom.width, 3)) { containers_hidden_edges |= WLR_EDGE_RIGHT; } } if (hidden_edges & WLR_EDGE_TOP) { - if (con_geom->y == m->root->geom.y) { + if (con_geom.y == m->root->geom.y) { containers_hidden_edges |= WLR_EDGE_TOP; } } if (hidden_edges & WLR_EDGE_BOTTOM) { - if (is_approx_equal(con_geom->y + con_geom->height, m->root->geom.y + m->root->geom.height, 3)) { + if (is_approx_equal(con_geom.y + con_geom.height, m->root->geom.y + m->root->geom.height, 3)) { containers_hidden_edges |= WLR_EDGE_BOTTOM; } } @@ -256,46 +256,47 @@ static enum wlr_edges get_hidden_edges(struct container *con, struct wlr_box *bo static void render_borders(struct container *con, struct monitor *m, pixman_region32_t *output_damage) { - if (!con->has_border) - return; - - double ox, oy; - int w, h; - struct wlr_box *con_geom = container_get_current_geom(con); - int border_width = container_get_border_width(con); - ox = con_geom->x - border_width; - oy = con_geom->y - border_width; - wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); - w = con_geom->width; - h = con_geom->height; - - struct wlr_box *borders = (struct wlr_box[4]) { - {ox, oy, w + 2 * border_width, border_width}, /* top */ - {ox, oy + border_width + h, w + 2 * border_width, border_width}, /* bottom */ - {ox, oy + border_width, border_width, h}, /* left */ - {ox + border_width + w, oy + border_width, border_width, h}, /* right */ - }; - - enum wlr_edges hidden_edges = WLR_EDGE_NONE; - struct tag *tag = monitor_get_active_tag(m); - struct layout *lt = tag_get_layout(tag); - if (lt->options->smart_hidden_edges) { - if (tag->visible_con_set->tiled_containers->len <= 1) { - hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - } - } else { - hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - } - - /* Draw window borders */ - struct container *sel = monitor_get_focused_container(m); - const struct color color = (con == sel) ? lt->options->focus_color : lt->options->border_color; - for (int i = 0; i < 4; i++) { - if ((hidden_edges & (1 << i)) == 0) { - scale_box(&borders[i], m->wlr_output->scale); - render_rect(m, output_damage, &borders[i], color); - } - } + // TODO: reimplement me + // if (!con->has_border) + // return; + // + // double ox, oy; + // int w, h; + // struct wlr_box con_geom = container_get_current_geom(con); + // int border_width = container_get_border_width(con); + // ox = con_geom->x - border_width; + // oy = con_geom->y - border_width; + // wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); + // w = con_geom->width; + // h = con_geom->height; + // + // struct wlr_box *borders = (struct wlr_box[4]) { + // {ox, oy, w + 2 * border_width, border_width}, /* top */ + // {ox, oy + border_width + h, w + 2 * border_width, border_width}, /* bottom */ + // {ox, oy + border_width, border_width, h}, /* left */ + // {ox + border_width + w, oy + border_width, border_width, h}, /* right */ + // }; + // + // enum wlr_edges hidden_edges = WLR_EDGE_NONE; + // struct tag *tag = monitor_get_active_tag(m); + // struct layout *lt = tag_get_layout(tag); + // if (lt->options->smart_hidden_edges) { + // if (tag->visible_con_set->tiled_containers->len <= 1) { + // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); + // } + // } else { + // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); + // } + // + // /* Draw window borders */ + // struct container *sel = monitor_get_focused_container(m); + // const struct color color = (con == sel) ? lt->options->focus_color : lt->options->border_color; + // for (int i = 0; i < 4; i++) { + // if ((hidden_edges & (1 << i)) == 0) { + // scale_box(&borders[i], m->wlr_output->scale); + // render_rect(m, output_damage, &borders[i], color); + // } + // } } void output_surface_for_each_surface(struct monitor *m, @@ -337,8 +338,7 @@ static void render_stack(struct monitor *m, pixman_region32_t *output_damage) * xdg_surface's toplevel and popups. */ struct wlr_surface *surface = get_wlrsurface(con->client); - struct wlr_box *con_geom = container_get_current_geom(con); - struct wlr_box obox = *con_geom; + struct wlr_box obox = container_get_current_geom(con); struct render_texture_data render_data; render_data.alpha = con->alpha; diff --git a/src/scratchpad.c b/src/scratchpad.c index e9077a5b..79567d5b 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -68,7 +68,7 @@ static void show_container(struct container *con) container_set_tag_id(con, tag->id); container_set_floating(con, container_fix_position, true); struct wlr_box center_box = get_center_box(m->geom); - container_set_current_geom(con, ¢er_box); + container_set_current_geom(con, center_box); tag_this_focus_container(con); lift_container(con); @@ -88,7 +88,7 @@ void show_scratchpad() container_set_tag_id(con, tag->id); container_set_floating(con, container_fix_position, true); struct wlr_box center_box = get_center_box(m->geom); - container_set_current_geom(con, ¢er_box); + container_set_current_geom(con, center_box); tag_this_focus_container(con); lift_container(con); diff --git a/src/tagset.c b/src/tagset.c index 522bf726..c5af4562 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -287,7 +287,7 @@ static void restore_floating_containers(struct tag *tag) return; for (int i = 0; i < floating_list->len; i++) { struct container *con = g_ptr_array_index(floating_list, i); - struct wlr_box *con_geom = container_get_current_geom(con); + struct wlr_box con_geom = container_get_current_geom(con); container_set_current_geom(con, con_geom); } } @@ -398,8 +398,8 @@ bool container_intersects_with_monitor(struct container *con, struct monitor *m) return false; struct wlr_box tmp_geom; - struct wlr_box *geom = container_get_current_geom(con); - return wlr_box_intersection(&tmp_geom, geom, &m->geom); + struct wlr_box geom = container_get_current_geom(con); + return wlr_box_intersection(&tmp_geom, &geom, &m->geom); } GPtrArray *tagset_get_global_floating_copy(struct tag *tag) diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index be92ff28..0fcd33f0 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -44,7 +44,7 @@ void arrange() struct monitor *m = server_get_selected_monitor(); struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); - container_set_border_width(con, lt->options->float_border_px); + container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); container_update_size(con); container_set_hidden(con, false); } @@ -297,16 +297,16 @@ static void arrange_container(struct container *con, struct monitor *m, container_surround_gaps(&geom, inner_gap); if (container_is_floating(con)) { - container_set_border_width(con, lt->options->float_border_px); + container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); } else { - container_set_border_width(con, lt->options->tile_border_px); + container_set_border_width(con, direction_value_uniform(lt->options->tile_border_px)); } // since gaps are halfed we need to multiply it by 2 // int border_width = container_get_border_width(con); container_surround_gaps(&geom, 2*lt->options->tile_border_px); - container_set_tiled_geom(con, &geom); + container_set_tiled_geom(con, geom); container_update_size(con); } @@ -314,9 +314,7 @@ void container_update_size(struct container *con) { con->client->resized = true; - struct wlr_box *con_geom = container_get_current_geom(con); - if (!con_geom) - return; + struct wlr_box con_geom = container_get_current_geom(con); apply_bounds(con, *wlr_output_layout_get_box(server.output_layout, NULL)); /* wlroots makes this a no-op if size hasn't changed */ @@ -324,7 +322,7 @@ void container_update_size(struct container *con) case XDG_SHELL: if (con->client->surface.xdg->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { wlr_xdg_toplevel_set_size(con->client->surface.xdg, - con_geom->width, con_geom->height); + con_geom.width, con_geom.height); } break; case LAYER_SHELL: @@ -344,8 +342,8 @@ void container_update_size(struct container *con) case X11_UNMANAGED: case X11_MANAGED: wlr_xwayland_surface_configure(con->client->surface.xwayland, - con_geom->x, con_geom->y, con_geom->width, - con_geom->height); + con_geom.x, con_geom.y, con_geom.width, + con_geom.height); } } diff --git a/src/xwayland.c b/src/xwayland.c index b3430270..1538df73 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -186,7 +186,7 @@ void maprequestx11(struct wl_listener *listener, void *data) con->on_top = false; if (x11_wants_floating(con->client)) { container_set_floating(con, container_fix_position, true); - container_set_floating_geom(con, &prefered_geom); + container_set_floating_geom(con, prefered_geom); } break; } @@ -211,7 +211,7 @@ void maprequestx11(struct wl_listener *listener, void *data) con->has_border = false; lift_container(con); container_set_floating(con, NULL, true); - container_set_floating_geom(con, &prefered_geom); + container_set_floating_geom(con, prefered_geom); break; } default: From 96eacbb2bff8bcaada41e41eaa84d7b08bb7cfbd Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 02:09:51 +0100 Subject: [PATCH 11/93] add useful functions --- include/container.h | 7 ++++ src/container.c | 100 ++++++++++++++++++++++++++++++-------------- 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/include/container.h b/include/container.h index 8839f090..104c7e9f 100644 --- a/include/container.h +++ b/include/container.h @@ -121,6 +121,13 @@ struct wlr_box container_get_tiled_geom(struct container *con); struct wlr_box container_get_floating_geom(struct container *con); struct wlr_box container_get_current_geom(struct container *con); +struct wlr_box container_get_tiled_content_geom_at_tag(struct container *con, struct tag *tag); +struct wlr_box container_get_floating_content_geom_at_tag(struct container *con, struct tag *tag); +struct wlr_box container_get_current_content_geom_at_tag(struct container *con, struct tag *tag); +struct wlr_box container_get_tiled_content_geom(struct container *con); +struct wlr_box container_get_floating_content_geom(struct container *con); +struct wlr_box container_get_current_content_geom(struct container *con); + struct wlr_box container_content_geometry_to_box(struct container *con, struct wlr_box geom); struct wlr_box container_box_to_content_geometry(struct container *con, diff --git a/src/container.c b/src/container.c index a6de009f..4be6d630 100644 --- a/src/container.c +++ b/src/container.c @@ -873,49 +873,69 @@ struct direction_value direction_value_uniform(int value) struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag *tag) { - struct container_property *property = - g_ptr_array_index(con->properties, tag->id); - - struct wlr_box geom = property->geom; - - if (con->client->type == LAYER_SHELL) { - geom = con->global_geom; - } + struct wlr_box content_geom = container_get_tiled_content_geom_at_tag(con, tag); + struct wlr_box geom = container_content_geometry_to_box(con, content_geom); return geom; } struct wlr_box container_get_tiled_geom(struct container *con) { - struct tag *tag = container_get_current_tag(con); - if (!tag) - return (struct wlr_box){0}; - - struct wlr_box geom = container_get_tiled_geom_at_tag(con, tag); + struct wlr_box content_geom = container_get_tiled_content_geom(con); + struct wlr_box geom = container_content_geometry_to_box(con, content_geom); return geom; } struct wlr_box container_get_floating_geom_at_tag(struct container *con, struct tag *tag) { - struct container_property *property = - g_ptr_array_index(con->properties, tag->id); - - return container_property_get_floating_geom(property); + struct wlr_box content_geom = container_get_floating_content_geom_at_tag(con, tag); + struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + return geom; } struct wlr_box container_get_floating_geom(struct container *con) { - if (!con) - return (struct wlr_box){0}; + struct wlr_box content_geom = container_get_floating_content_geom(con); + struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + return geom; +} - struct tag *tag = container_get_current_tag(con); - if (!tag) { - return (struct wlr_box){0}; +struct wlr_box container_get_current_geom_at_tag(struct container *con, struct tag *tag) +{ + struct wlr_box content_geom = container_get_current_content_geom_at_tag(con, tag); + struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + return geom; +} + +struct wlr_box container_get_current_geom(struct container *con) +{ + struct wlr_box content_geom = container_get_current_content_geom(con); + struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + return geom; +} + +struct wlr_box container_get_tiled_content_geom_at_tag(struct container *con, struct tag *tag) +{ + struct container_property *property = + g_ptr_array_index(con->properties, tag->id); + + struct wlr_box geom = property->geom; + + if (con->client->type == LAYER_SHELL) { + geom = con->global_geom; } - return container_get_floating_geom_at_tag(con, tag); + return geom; } -struct wlr_box container_get_current_geom_at_tag(struct container *con, struct tag *tag) +struct wlr_box container_get_floating_content_geom_at_tag(struct container *con, struct tag *tag) +{ + struct container_property *property = + g_ptr_array_index(con->properties, tag->id); + + return container_property_get_floating_geom(property); +} + +struct wlr_box container_get_current_content_geom_at_tag(struct container *con, struct tag *tag) { if (!con) return (struct wlr_box){0}; @@ -925,21 +945,39 @@ struct wlr_box container_get_current_geom_at_tag(struct container *con, struct t struct wlr_box geom; struct layout *lt = tag_get_layout(tag); if (container_is_unmanaged(con)) { - geom = container_get_floating_geom(con); - // TODO: lt may be NULL maybe we should wrap lt->options->arrange_by_focus - // in a funciton? + geom = container_get_floating_content_geom_at_tag(con, tag); } else if (container_is_tiled(con) || (lt && lt->options->arrange_by_focus)) { - geom = container_get_tiled_geom(con); + geom = container_get_tiled_content_geom_at_tag(con, tag); } else { - geom = container_get_floating_geom(con); + geom = container_get_floating_content_geom_at_tag(con, tag); } return geom; } -struct wlr_box container_get_current_geom(struct container *con) +struct wlr_box container_get_tiled_content_geom(struct container *con) +{ + struct tag *tag = container_get_current_tag(con); + if (!tag) + return (struct wlr_box){0}; + + struct wlr_box geom = container_get_tiled_content_geom_at_tag(con, tag); + return geom; +} + +struct wlr_box container_get_floating_content_geom(struct container *con) +{ + struct tag *tag = container_get_current_tag(con); + if (!tag) + return (struct wlr_box){0}; + + struct wlr_box geom = container_get_floating_content_geom_at_tag(con, tag); + return geom; +} + +struct wlr_box container_get_current_content_geom(struct container *con) { struct tag *tag = container_get_current_tag(con); - struct wlr_box geom = container_get_current_geom_at_tag(con, tag); + struct wlr_box geom = container_get_current_content_geom_at_tag(con, tag); return geom; } From ef9c3534017c223bae658ee17eb28c85a518c95a Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 02:29:00 +0100 Subject: [PATCH 12/93] feat: add borders back --- include/container.h | 3 ++ src/container.c | 41 ++++++++++++++++++++++++++ src/render/render.c | 70 +++++++++++++++++++------------------------- src/tile/tileUtils.c | 4 --- 4 files changed, 74 insertions(+), 44 deletions(-) diff --git a/include/container.h b/include/container.h index 104c7e9f..bf8ce7bd 100644 --- a/include/container.h +++ b/include/container.h @@ -4,6 +4,7 @@ #include #include #include +#include #include struct monitor; @@ -128,6 +129,8 @@ struct wlr_box container_get_tiled_content_geom(struct container *con); struct wlr_box container_get_floating_content_geom(struct container *con); struct wlr_box container_get_current_content_geom(struct container *con); +struct wlr_box container_get_current_border_geom(struct container *con, enum wlr_edges dir); + struct wlr_box container_content_geometry_to_box(struct container *con, struct wlr_box geom); struct wlr_box container_box_to_content_geometry(struct container *con, diff --git a/src/container.c b/src/container.c index 4be6d630..82163ff8 100644 --- a/src/container.c +++ b/src/container.c @@ -981,6 +981,47 @@ struct wlr_box container_get_current_content_geom(struct container *con) return geom; } +struct wlr_box container_get_current_border_geom(struct container *con, enum wlr_edges dir) +{ + struct wlr_box geom = container_get_current_geom(con); + switch (dir) { + case WLR_EDGE_TOP: + { + struct direction_value d = container_get_border_width(con); + geom.y = geom.y - d.top; + geom.height = d.top; + break; + } + case WLR_EDGE_BOTTOM: + { + struct direction_value d = container_get_border_width(con); + geom.y += geom.height; + geom.height = d.bottom; + break; + } + break; + case WLR_EDGE_LEFT: + { + struct direction_value d = container_get_border_width(con); + geom.x = geom.x - d.left; + geom.width = d.left; + break; + } + break; + case WLR_EDGE_RIGHT: + { + struct direction_value d = container_get_border_width(con); + geom.x += geom.width; + geom.width = d.right; + break; + } + break; + default: + break; + } + return geom; +} + struct wlr_box container_content_geometry_to_box(struct container *con, struct wlr_box geom) { diff --git a/src/render/render.c b/src/render/render.c index 345c4fec..295c473a 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -257,46 +257,36 @@ static enum wlr_edges get_hidden_edges(struct container *con, struct wlr_box *bo static void render_borders(struct container *con, struct monitor *m, pixman_region32_t *output_damage) { // TODO: reimplement me - // if (!con->has_border) - // return; - // - // double ox, oy; - // int w, h; - // struct wlr_box con_geom = container_get_current_geom(con); - // int border_width = container_get_border_width(con); - // ox = con_geom->x - border_width; - // oy = con_geom->y - border_width; - // wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); - // w = con_geom->width; - // h = con_geom->height; - // - // struct wlr_box *borders = (struct wlr_box[4]) { - // {ox, oy, w + 2 * border_width, border_width}, /* top */ - // {ox, oy + border_width + h, w + 2 * border_width, border_width}, /* bottom */ - // {ox, oy + border_width, border_width, h}, /* left */ - // {ox + border_width + w, oy + border_width, border_width, h}, /* right */ - // }; - // - // enum wlr_edges hidden_edges = WLR_EDGE_NONE; - // struct tag *tag = monitor_get_active_tag(m); - // struct layout *lt = tag_get_layout(tag); - // if (lt->options->smart_hidden_edges) { - // if (tag->visible_con_set->tiled_containers->len <= 1) { - // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - // } - // } else { - // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - // } - // - // /* Draw window borders */ - // struct container *sel = monitor_get_focused_container(m); - // const struct color color = (con == sel) ? lt->options->focus_color : lt->options->border_color; - // for (int i = 0; i < 4; i++) { - // if ((hidden_edges & (1 << i)) == 0) { - // scale_box(&borders[i], m->wlr_output->scale); - // render_rect(m, output_damage, &borders[i], color); - // } - // } + if (!con->has_border) + return; + + struct wlr_box *borders = (struct wlr_box[4]) { + container_get_current_border_geom(con, WLR_EDGE_TOP), + container_get_current_border_geom(con, WLR_EDGE_BOTTOM), + container_get_current_border_geom(con, WLR_EDGE_LEFT), + container_get_current_border_geom(con, WLR_EDGE_RIGHT), + }; + + enum wlr_edges hidden_edges = WLR_EDGE_NONE; + struct tag *tag = monitor_get_active_tag(m); + struct layout *lt = tag_get_layout(tag); + if (lt->options->smart_hidden_edges) { + if (tag->visible_con_set->tiled_containers->len <= 1) { + hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); + } + } else { + hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); + } + + /* Draw window borders */ + struct container *sel = monitor_get_focused_container(m); + const struct color color = (con == sel) ? lt->options->focus_color : lt->options->border_color; + for (int i = 0; i < 4; i++) { + if ((hidden_edges & (1 << i)) == 0) { + scale_box(&borders[i], m->wlr_output->scale); + render_rect(m, output_damage, &borders[i], color); + } + } } void output_surface_for_each_surface(struct monitor *m, diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index 0fcd33f0..7f3ed44c 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -302,10 +302,6 @@ static void arrange_container(struct container *con, struct monitor *m, container_set_border_width(con, direction_value_uniform(lt->options->tile_border_px)); } - // since gaps are halfed we need to multiply it by 2 - // int border_width = container_get_border_width(con); - container_surround_gaps(&geom, 2*lt->options->tile_border_px); - container_set_tiled_geom(con, geom); container_update_size(con); } From 9b29428d7e367cd60a5b34e4fd1ad65af682d1a0 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 02:32:36 +0100 Subject: [PATCH 13/93] feat: add container damage back --- src/container.c | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/container.c b/src/container.c index 82163ff8..13e8b1cc 100644 --- a/src/container.c +++ b/src/container.c @@ -178,33 +178,25 @@ void remove_container_from_tile(struct container *con) void container_damage_borders(struct container *con, struct monitor *m, struct wlr_box geom) { - // TODO: rewrite this function - // if (!con) - // return; - // if (!m) - // return; - // - // int border_width = container_get_border_width(con); - // double ox = geom->x - border_width; - // double oy = geom->y - border_width; - // wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); - // int w = geom->width; - // int h = geom->height; - // - // struct wlr_box *borders; - // borders = (struct wlr_box[4]) { - // {ox, oy, w + 2 * border_width, border_width}, /* top */ - // {ox, oy + border_width, border_width, h}, /* left */ - // {ox + border_width + w, oy + border_width, border_width, h}, /* right */ - // {ox, oy + border_width + h, w + 2 * border_width, border_width}, /* bottom */ - // }; - // - // pthread_mutex_lock(&lock_rendering_action); - // for (int i = 0; i < 4; i++) { - // scale_box(&borders[i], m->wlr_output->scale); - // wlr_output_damage_add_box(m->damage, &borders[i]); - // } - // pthread_mutex_unlock(&lock_rendering_action); + if (!con) + return; + if (!m) + return; + + struct wlr_box *borders; + borders = (struct wlr_box[4]) { + container_get_current_border_geom(con, WLR_EDGE_TOP), + container_get_current_border_geom(con, WLR_EDGE_LEFT), + container_get_current_border_geom(con, WLR_EDGE_RIGHT), + container_get_current_border_geom(con, WLR_EDGE_BOTTOM), + }; + + pthread_mutex_lock(&lock_rendering_action); + for (int i = 0; i < 4; i++) { + scale_box(&borders[i], m->wlr_output->scale); + wlr_output_damage_add_box(m->damage, &borders[i]); + } + pthread_mutex_unlock(&lock_rendering_action); } static void damage_container_area(struct container *con, struct wlr_box geom, From 1d44e9be93f7c48a99d6bf11350b756ed29dea9e Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 02:50:59 +0100 Subject: [PATCH 14/93] feat add layers --- include/container.h | 6 ++++ src/container.c | 77 ++++++++++++++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/include/container.h b/include/container.h index bf8ce7bd..86fbb60c 100644 --- a/include/container.h +++ b/include/container.h @@ -115,6 +115,12 @@ void container_set_current_geom(struct container *con, struct wlr_box geom); void container_set_tiled_geom(struct container *con, struct wlr_box geom); void container_set_floating_geom(struct container *con, struct wlr_box geom); +void container_set_floating_content_geom_at_tag(struct container *con, + struct wlr_box geom, struct tag *tag); +void container_set_current_content_geom(struct container *con, struct wlr_box geom); +void container_set_tiled_content_geom(struct container *con, struct wlr_box geom); +void container_set_floating_content_geom(struct container *con, struct wlr_box geom); + struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag *tag); struct wlr_box container_get_floating_geom_at_tag(struct container *con, struct tag *tag); struct wlr_box container_get_current_geom_at_tag(struct container *con, struct tag *tag); diff --git a/src/container.c b/src/container.c index 13e8b1cc..d5dac581 100644 --- a/src/container.c +++ b/src/container.c @@ -379,7 +379,7 @@ struct wlr_fbox lua_togeometry(lua_State *L) void apply_bounds(struct container *con, struct wlr_box box) { /* set minimum possible */ - struct wlr_box con_geom = container_get_current_geom(con); + struct wlr_box con_geom = container_get_current_content_geom(con); con_geom.width = MAX(MIN_CONTAINER_WIDTH, con_geom.width); con_geom.height = MAX(MIN_CONTAINER_HEIGHT, con_geom.height); @@ -771,19 +771,63 @@ struct container_property *container_get_property_at_tag( } void container_set_current_geom(struct container *con, struct wlr_box geom) +{ + struct wlr_box content_geom = container_box_to_content_geometry(con, geom); + container_set_current_content_geom(con, content_geom); +} + +void container_set_tiled_geom(struct container *con, struct wlr_box geom) +{ + struct wlr_box content_geom = container_box_to_content_geometry(con, geom); + container_set_tiled_content_geom(con, content_geom); +} + +void container_set_floating_geom_at_tag(struct container *con, + struct wlr_box geom, struct tag *tag) +{ + struct wlr_box content_geom = container_box_to_content_geometry(con, geom); + container_set_floating_content_geom_at_tag(con, content_geom, tag); +} + +void container_set_floating_geom(struct container *con, struct wlr_box geom) +{ + struct wlr_box content_geom = container_box_to_content_geometry(con, geom); + container_set_floating_content_geom(con, content_geom); +} + +void container_set_floating_content_geom_at_tag(struct container *con, + struct wlr_box geom, struct tag *tag) +{ + struct container_property *property = + container_get_property_at_tag(con, tag); + + if (!property) + return; + + struct wlr_box *con_geom = &property->floating_geom; + if (con->client->type == LAYER_SHELL) { + con_geom = &con->global_geom; + } + + con->prev_geom = *con_geom; + *con_geom = geom; + container_update_size(con); +} + +void container_set_current_content_geom(struct container *con, struct wlr_box geom) { struct tag *tag = container_get_current_tag(con); struct layout *lt = tag_get_layout(tag); if (container_is_tiled(con) || lt->options->arrange_by_focus) { - container_set_tiled_geom(con, geom); + container_set_tiled_content_geom(con, geom); } else { - container_set_floating_geom(con, geom); + container_set_floating_content_geom(con, geom); } } -void container_set_tiled_geom(struct container *con, struct wlr_box geom) +void container_set_tiled_content_geom(struct container *con, struct wlr_box geom) { - struct wlr_box con_geom = container_get_tiled_geom(con); + struct wlr_box con_geom = container_get_tiled_content_geom(con); if (con->client->type == LAYER_SHELL) { con_geom = con->global_geom; @@ -828,29 +872,10 @@ void container_set_tiled_geom(struct container *con, struct wlr_box geom) property->geom = geom; } -void container_set_floating_geom_at_tag(struct container *con, - struct wlr_box geom, struct tag *tag) -{ - struct container_property *property = - container_get_property_at_tag(con, tag); - - if (!property) - return; - - struct wlr_box *con_geom = &property->floating_geom; - if (con->client->type == LAYER_SHELL) { - con_geom = &con->global_geom; - } - - con->prev_geom = *con_geom; - *con_geom = geom; - container_update_size(con); -} - -void container_set_floating_geom(struct container *con, struct wlr_box geom) +void container_set_floating_content_geom(struct container *con, struct wlr_box geom) { struct tag *tag = container_get_current_tag(con); - container_set_floating_geom_at_tag(con, geom, tag); + container_set_floating_content_geom_at_tag(con, geom, tag); } struct direction_value direction_value_uniform(int value) From 92196640f33f22a3565f555856ebdebfff141f2d Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 02:54:03 +0100 Subject: [PATCH 15/93] fix apply bounds --- src/container.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/container.c b/src/container.c index d5dac581..a8d6a6f8 100644 --- a/src/container.c +++ b/src/container.c @@ -383,17 +383,16 @@ void apply_bounds(struct container *con, struct wlr_box box) con_geom.width = MAX(MIN_CONTAINER_WIDTH, con_geom.width); con_geom.height = MAX(MIN_CONTAINER_HEIGHT, con_geom.height); - // TODO: fix this part - // int border_width = container_get_border_width(con); - // - // if (con_geom->x >= box.x + box.width) - // con_geom->x = box.x + box.width - con_geom->width; - // if (con_geom->y >= box.y + box.height) - // con_geom->y = box.y + box.height - con_geom->height; - // if (con_geom->x + con_geom->width + 2 * border_width <= box.x) - // con_geom->x = box.x; - // if (con_geom->y + con_geom->height + 2 * border_width <= box.y) - // con_geom->y = box.y; + struct direction_value bw = container_get_border_width(con); + + if (con_geom.x >= box.x + box.width) + con_geom.x = box.x + box.width - con_geom.width; + if (con_geom.y >= box.y + box.height) + con_geom.y = box.y + box.height - con_geom.height; + if (con_geom.x + con_geom.width + bw.left + bw.right <= box.x) + con_geom.x = box.x; + if (con_geom.y + con_geom.height + bw.top + bw.bottom <= box.y) + con_geom.y = box.y; container_set_current_geom(con, con_geom); } From f33195bc39360b335bd3ade5e1140ee3d58123a3 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 02:56:36 +0100 Subject: [PATCH 16/93] fix some errors --- src/container.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/container.c b/src/container.c index a8d6a6f8..2bc696a2 100644 --- a/src/container.c +++ b/src/container.c @@ -394,7 +394,7 @@ void apply_bounds(struct container *con, struct wlr_box box) if (con_geom.y + con_geom.height + bw.top + bw.bottom <= box.y) con_geom.y = box.y; - container_set_current_geom(con, con_geom); + container_set_current_content_geom(con, con_geom); } void commit_notify(struct wl_listener *listener, void *data) From f627eafbaa543307f2840d677a94c86fd45b3728 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 16:19:56 +0100 Subject: [PATCH 17/93] fix some functions --- src/container.c | 11 +++++---- src/tile/tileUtils.c | 8 +++--- test/container_test.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/container.c b/src/container.c index 2bc696a2..3a8bfb06 100644 --- a/src/container.c +++ b/src/container.c @@ -1043,10 +1043,10 @@ struct wlr_box container_content_geometry_to_box(struct container *con, { struct direction_value borders = container_get_border_width(con); struct wlr_box box_geom = { - .x = geom.x + borders.left, - .y = geom.y + borders.top, - .width = geom.width - borders.left - borders.right, - .height = geom.height - borders.top - borders.bottom, + .x = geom.x - borders.left, + .y = geom.y - borders.top, + .width = geom.width + borders.left + borders.right, + .height = geom.height + borders.top + borders.bottom, }; return box_geom; } @@ -1190,7 +1190,8 @@ struct tag *container_get_current_tag(struct container *con) } } - return NULL; + struct tag *tag = container_get_tag(con); + return tag; } struct container *get_container_from_container_stack_position(int i) diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index 7f3ed44c..9d5a8bea 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -264,12 +264,12 @@ void arrange_containers( if (lt->options->smart_hidden_edges) { if (tiled_containers->len <= 1) { - container_add_gaps(&root_geom, -lt->options->tile_border_px, - lt->options->hidden_edges); + // container_add_gaps(&root_geom, -lt->options->tile_border_px, + // lt->options->hidden_edges); } } else { - container_add_gaps(&root_geom, -lt->options->tile_border_px, - lt->options->hidden_edges); + // container_add_gaps(&root_geom, -lt->options->tile_border_px, + // lt->options->hidden_edges); } // debug_print("tiled containers len: %i\n", tiled_containers->len); diff --git a/test/container_test.c b/test/container_test.c index 72179327..e7ef23af 100644 --- a/test/container_test.c +++ b/test/container_test.c @@ -5,6 +5,61 @@ #include "tag.h" #include "utils/coreUtils.h" #include "server.h" +#include "client.h" + +void test_container_box_to_content_geometry() +{ + init_server(); + struct wlr_box box = { + .x = 0, + .y = 0, + .width = 100, + .height = 100, + }; + struct wlr_box content_box = { + .x = 10, + .y = 10, + .width = 80, + .height = 80, + }; + struct monitor m; + struct client c; + c.sticky_tags = bitset_create(); + struct container *con = create_container(&c, &m, true); + container_set_border_width(con, direction_value_uniform(10)); + struct wlr_box result = container_box_to_content_geometry(con, box); + g_assert_cmpint(result.x, ==, content_box.x); + g_assert_cmpint(result.y, ==, content_box.y); + g_assert_cmpint(result.width, ==, content_box.width); + g_assert_cmpint(result.height, ==, content_box.height); +} + +void test_container_content_geometry_to_box() +{ + init_server(); + struct wlr_box box = { + .x = 0, + .y = 0, + .width = 100, + .height = 100, + }; + struct wlr_box content_box = { + .x = 10, + .y = 10, + .width = 80, + .height = 80, + }; + struct monitor m; + struct client c; + c.sticky_tags = bitset_create(); + struct container *con = create_container(&c, &m, true); + container_set_border_width(con, direction_value_uniform(10)); + struct wlr_box result = container_content_geometry_to_box(con, content_box); + g_assert_cmpint(result.x, ==, box.x); + g_assert_cmpint(result.y, ==, box.y); + g_assert_cmpint(result.width, ==, box.width); + g_assert_cmpint(result.height, ==, box.height); +} void test_visible_on() { @@ -136,6 +191,8 @@ int main(int argc, char **argv) setbuf(stdout, NULL); g_test_init(&argc, &argv, NULL); + add_test(test_container_box_to_content_geometry); + add_test(test_container_content_geometry_to_box); add_test(test_visible_on); return g_test_run(); From 7c0e0072a0e7c94a2a4f2ec7c390804537e8bf28 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 16:24:03 +0100 Subject: [PATCH 18/93] fix stuff --- test/container_test.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/container_test.c b/test/container_test.c index e7ef23af..5a450bf9 100644 --- a/test/container_test.c +++ b/test/container_test.c @@ -23,8 +23,10 @@ void test_container_box_to_content_geometry() .height = 80, }; struct monitor m; - struct client c; - c.sticky_tags = bitset_create(); + struct client c = { + .sticky_tags = bitset_create(), + }; + struct container *con = create_container(&c, &m, true); container_set_border_width(con, direction_value_uniform(10)); struct wlr_box result = container_box_to_content_geometry(con, box); @@ -32,6 +34,8 @@ void test_container_box_to_content_geometry() g_assert_cmpint(result.y, ==, content_box.y); g_assert_cmpint(result.width, ==, content_box.width); g_assert_cmpint(result.height, ==, content_box.height); + + bitset_destroy(c.sticky_tags); } void test_container_content_geometry_to_box() @@ -50,8 +54,9 @@ void test_container_content_geometry_to_box() .height = 80, }; struct monitor m; - struct client c; - c.sticky_tags = bitset_create(); + struct client c = { + .sticky_tags = bitset_create(), + }; struct container *con = create_container(&c, &m, true); container_set_border_width(con, direction_value_uniform(10)); struct wlr_box result = container_content_geometry_to_box(con, content_box); From 30ffeb2d3fb819eb4d25325b6357f628b154af62 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 17:46:26 +0100 Subject: [PATCH 19/93] fix stuff --- include/container.h | 2 - src/container.c | 144 ++++++++++++++++++++---------------------- src/server.c | 21 +++--- test/container_test.c | 92 +++++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 87 deletions(-) diff --git a/include/container.h b/include/container.h index 86fbb60c..d3e6673a 100644 --- a/include/container.h +++ b/include/container.h @@ -115,8 +115,6 @@ void container_set_current_geom(struct container *con, struct wlr_box geom); void container_set_tiled_geom(struct container *con, struct wlr_box geom); void container_set_floating_geom(struct container *con, struct wlr_box geom); -void container_set_floating_content_geom_at_tag(struct container *con, - struct wlr_box geom, struct tag *tag); void container_set_current_content_geom(struct container *con, struct wlr_box geom); void container_set_tiled_content_geom(struct container *con, struct wlr_box geom); void container_set_floating_content_geom(struct container *con, struct wlr_box geom); diff --git a/src/container.c b/src/container.c index 3a8bfb06..89422fb9 100644 --- a/src/container.c +++ b/src/container.c @@ -770,63 +770,19 @@ struct container_property *container_get_property_at_tag( } void container_set_current_geom(struct container *con, struct wlr_box geom) -{ - struct wlr_box content_geom = container_box_to_content_geometry(con, geom); - container_set_current_content_geom(con, content_geom); -} - -void container_set_tiled_geom(struct container *con, struct wlr_box geom) -{ - struct wlr_box content_geom = container_box_to_content_geometry(con, geom); - container_set_tiled_content_geom(con, content_geom); -} - -void container_set_floating_geom_at_tag(struct container *con, - struct wlr_box geom, struct tag *tag) -{ - struct wlr_box content_geom = container_box_to_content_geometry(con, geom); - container_set_floating_content_geom_at_tag(con, content_geom, tag); -} - -void container_set_floating_geom(struct container *con, struct wlr_box geom) -{ - struct wlr_box content_geom = container_box_to_content_geometry(con, geom); - container_set_floating_content_geom(con, content_geom); -} - -void container_set_floating_content_geom_at_tag(struct container *con, - struct wlr_box geom, struct tag *tag) -{ - struct container_property *property = - container_get_property_at_tag(con, tag); - - if (!property) - return; - - struct wlr_box *con_geom = &property->floating_geom; - if (con->client->type == LAYER_SHELL) { - con_geom = &con->global_geom; - } - - con->prev_geom = *con_geom; - *con_geom = geom; - container_update_size(con); -} - -void container_set_current_content_geom(struct container *con, struct wlr_box geom) { struct tag *tag = container_get_current_tag(con); struct layout *lt = tag_get_layout(tag); if (container_is_tiled(con) || lt->options->arrange_by_focus) { - container_set_tiled_content_geom(con, geom); + container_set_tiled_geom(con, geom); } else { - container_set_floating_content_geom(con, geom); + container_set_floating_geom(con, geom); } } -void container_set_tiled_content_geom(struct container *con, struct wlr_box geom) +void container_set_tiled_geom(struct container *con, struct wlr_box geom) { - struct wlr_box con_geom = container_get_tiled_content_geom(con); + struct wlr_box con_geom = container_get_tiled_geom(con); if (con->client->type == LAYER_SHELL) { con_geom = con->global_geom; @@ -871,10 +827,48 @@ void container_set_tiled_content_geom(struct container *con, struct wlr_box geom property->geom = geom; } -void container_set_floating_content_geom(struct container *con, struct wlr_box geom) +void container_set_floating_geom_at_tag(struct container *con, + struct wlr_box geom, struct tag *tag) +{ + struct container_property *property = + container_get_property_at_tag(con, tag); + + if (!property) + return; + + struct wlr_box *con_geom = &property->floating_geom; + if (con->client->type == LAYER_SHELL) { + con_geom = &con->global_geom; + } + + con->prev_geom = *con_geom; + *con_geom = geom; + // TODO: do we need that? + // container_update_size(con); +} + +void container_set_floating_geom(struct container *con, struct wlr_box geom) { struct tag *tag = container_get_current_tag(con); - container_set_floating_content_geom_at_tag(con, geom, tag); + container_set_floating_geom_at_tag(con, geom, tag); +} + +void container_set_current_content_geom(struct container *con, struct wlr_box geom) +{ + struct wlr_box box_geom = container_content_geometry_to_box(con, geom); + container_set_current_geom(con, box_geom); +} + +void container_set_tiled_content_geom(struct container *con, struct wlr_box geom) +{ + struct wlr_box box_geom = container_content_geometry_to_box(con, geom); + container_set_tiled_geom(con, box_geom); +} + +void container_set_floating_content_geom(struct container *con, struct wlr_box geom) +{ + struct wlr_box box_geom = container_content_geometry_to_box(con, geom); + container_set_floating_geom(con, box_geom); } struct direction_value direction_value_uniform(int value) @@ -889,8 +883,15 @@ struct direction_value direction_value_uniform(int value) struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag *tag) { - struct wlr_box content_geom = container_get_tiled_content_geom_at_tag(con, tag); - struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + struct container_property *property = + g_ptr_array_index(con->properties, tag->id); + + struct wlr_box geom = property->geom; + + if (con->client->type == LAYER_SHELL) { + geom = con->global_geom; + } + return geom; } @@ -903,15 +904,19 @@ struct wlr_box container_get_tiled_geom(struct container *con) struct wlr_box container_get_floating_geom_at_tag(struct container *con, struct tag *tag) { - struct wlr_box content_geom = container_get_floating_content_geom_at_tag(con, tag); - struct wlr_box geom = container_content_geometry_to_box(con, content_geom); - return geom; + struct container_property *property = + g_ptr_array_index(con->properties, tag->id); + + return container_property_get_floating_geom(property); } struct wlr_box container_get_floating_geom(struct container *con) { - struct wlr_box content_geom = container_get_floating_content_geom(con); - struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + struct tag *tag = container_get_current_tag(con); + if (!tag) + return (struct wlr_box){0}; + + struct wlr_box geom = container_get_floating_geom_at_tag(con, tag); return geom; } @@ -931,24 +936,16 @@ struct wlr_box container_get_current_geom(struct container *con) struct wlr_box container_get_tiled_content_geom_at_tag(struct container *con, struct tag *tag) { - struct container_property *property = - g_ptr_array_index(con->properties, tag->id); - - struct wlr_box geom = property->geom; - - if (con->client->type == LAYER_SHELL) { - geom = con->global_geom; - } - + struct wlr_box box_geom = container_get_tiled_geom_at_tag(con, tag); + struct wlr_box geom = container_box_to_content_geometry(con, box_geom); return geom; } struct wlr_box container_get_floating_content_geom_at_tag(struct container *con, struct tag *tag) { - struct container_property *property = - g_ptr_array_index(con->properties, tag->id); - - return container_property_get_floating_geom(property); + struct wlr_box box_geom = container_get_floating_geom_at_tag(con, tag); + struct wlr_box geom = container_content_geometry_to_box(con, box_geom); + return geom; } struct wlr_box container_get_current_content_geom_at_tag(struct container *con, struct tag *tag) @@ -982,11 +979,8 @@ struct wlr_box container_get_tiled_content_geom(struct container *con) struct wlr_box container_get_floating_content_geom(struct container *con) { - struct tag *tag = container_get_current_tag(con); - if (!tag) - return (struct wlr_box){0}; - - struct wlr_box geom = container_get_floating_content_geom_at_tag(con, tag); + struct wlr_box content_geom = container_get_floating_geom(con); + struct wlr_box geom = container_box_to_content_geometry(con, content_geom); return geom; } diff --git a/src/server.c b/src/server.c index 1ec2dce2..d26e6949 100644 --- a/src/server.c +++ b/src/server.c @@ -224,6 +224,17 @@ void init_server() server_reset_layout_ring(server.default_layout_ring); server.default_layout = create_layout(L); + + load_lua_api(L); + if (init_backend(&server) != EXIT_SUCCESS) { + return; + } + + ipc_init(server.wl_event_loop); + + /* Creates an output layout, which a wlroots utility for working with an + * arrangement of screens in a physical layout. */ + server.output_layout = wlr_output_layout_create(); } void finalize_server() @@ -386,13 +397,6 @@ int setup(struct server *server) uv_async_init(uv_default_loop(), &server->async_handler, _async_handler_function); - load_lua_api(L); - if (init_backend(server) != EXIT_SUCCESS) { - return EXIT_FAILURE; - } - - ipc_init(server->wl_event_loop); - /* If we don't provide a renderer, autocreate makes a GLES2 renderer for us. * The renderer is responsible for defining the various pixel formats it * supports for shared memory, this configures that for clients. */ @@ -419,9 +423,6 @@ int setup(struct server *server) wlr_idle_create(server->wl_display); wlr_idle_inhibit_v1_create(server->wl_display); - /* Creates an output layout, which a wlroots utility for working with an - * arrangement of screens in a physical layout. */ - server->output_layout = wlr_output_layout_create(); wlr_xdg_output_manager_v1_create(server->wl_display, server->output_layout); /* Set up the xdg-shell. The xdg-shell is a diff --git a/test/container_test.c b/test/container_test.c index 5a450bf9..fad63f65 100644 --- a/test/container_test.c +++ b/test/container_test.c @@ -64,6 +64,96 @@ void test_container_content_geometry_to_box() g_assert_cmpint(result.y, ==, box.y); g_assert_cmpint(result.width, ==, box.width); g_assert_cmpint(result.height, ==, box.height); + + free(con); + bitset_destroy(c.sticky_tags); +} + +void test_container_current_geom() +{ + init_server(); + + struct wlr_box box = { + .x = 0, + .y = 0, + .width = 100, + .height = 100, + }; + struct wlr_box content_box = { + .x = 10, + .y = 10, + .width = 80, + .height = 80, + }; + + struct client c = { + .sticky_tags = bitset_create(), + }; + + struct monitor m; + struct container *con = create_container(&c, &m, true); + + container_set_current_geom(con, box); + + container_set_border_width(con, direction_value_uniform(10)); + + struct wlr_box result = container_get_current_geom(con); + g_assert_cmpint(result.x, ==, box.x); + g_assert_cmpint(result.y, ==, box.y); + g_assert_cmpint(result.width, ==, box.width); + g_assert_cmpint(result.height, ==, box.height); + struct wlr_box content_result = container_get_current_content_geom(con); + g_assert_cmpint(content_result.x, ==, content_box.x); + g_assert_cmpint(content_result.y, ==, content_box.y); + g_assert_cmpint(content_result.width, ==, content_box.width); + g_assert_cmpint(content_result.height, ==, content_box.height); + + free(con); + bitset_destroy(c.sticky_tags); +} + +void test_container_floating_content_geom() +{ + init_server(); + + struct wlr_box box = { + .x = 0, + .y = 0, + .width = 100, + .height = 100, + }; + struct wlr_box content_box = { + .x = 10, + .y = 10, + .width = 80, + .height = 80, + }; + + struct client c = { + .sticky_tags = bitset_create(), + }; + + struct monitor m; + struct container *con = create_container(&c, &m, true); + + container_set_floating_geom(con, box); + + container_set_border_width(con, direction_value_uniform(10)); + + struct wlr_box result = container_get_floating_geom(con); + g_assert_cmpint(result.x, ==, box.x); + g_assert_cmpint(result.y, ==, box.y); + g_assert_cmpint(result.width, ==, box.width); + g_assert_cmpint(result.height, ==, box.height); + + result = container_get_floating_content_geom(con); + g_assert_cmpint(result.x, ==, content_box.x); + g_assert_cmpint(result.y, ==, content_box.y); + g_assert_cmpint(result.width, ==, content_box.width); + g_assert_cmpint(result.height, ==, content_box.height); + + free(con); + bitset_destroy(c.sticky_tags); } void test_visible_on() @@ -198,6 +288,8 @@ int main(int argc, char **argv) add_test(test_container_box_to_content_geometry); add_test(test_container_content_geometry_to_box); + add_test(test_container_current_geom); + add_test(test_container_floating_content_geom); add_test(test_visible_on); return g_test_run(); From 9a60881a11d6de0865d858c53cf19180e5ba6910 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 17:54:31 +0100 Subject: [PATCH 20/93] fix render position --- src/container.c | 32 ++++++++++++++++---------------- src/render/render.c | 2 +- src/tile/tileUtils.c | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/container.c b/src/container.c index 89422fb9..cdfc3e8a 100644 --- a/src/container.c +++ b/src/container.c @@ -922,8 +922,20 @@ struct wlr_box container_get_floating_geom(struct container *con) struct wlr_box container_get_current_geom_at_tag(struct container *con, struct tag *tag) { - struct wlr_box content_geom = container_get_current_content_geom_at_tag(con, tag); - struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + if (!con) + return (struct wlr_box){0}; + if (!tag) + return (struct wlr_box){0}; + + struct wlr_box geom; + struct layout *lt = tag_get_layout(tag); + if (container_is_unmanaged(con)) { + geom = container_get_floating_geom_at_tag(con, tag); + } else if (container_is_tiled(con) || (lt && lt->options->arrange_by_focus)) { + geom = container_get_tiled_geom_at_tag(con, tag); + } else { + geom = container_get_floating_geom_at_tag(con, tag); + } return geom; } @@ -950,20 +962,8 @@ struct wlr_box container_get_floating_content_geom_at_tag(struct container *con, struct wlr_box container_get_current_content_geom_at_tag(struct container *con, struct tag *tag) { - if (!con) - return (struct wlr_box){0}; - if (!tag) - return (struct wlr_box){0}; - - struct wlr_box geom; - struct layout *lt = tag_get_layout(tag); - if (container_is_unmanaged(con)) { - geom = container_get_floating_content_geom_at_tag(con, tag); - } else if (container_is_tiled(con) || (lt && lt->options->arrange_by_focus)) { - geom = container_get_tiled_content_geom_at_tag(con, tag); - } else { - geom = container_get_floating_content_geom_at_tag(con, tag); - } + struct wlr_box box_geom = container_get_current_geom_at_tag(con, tag); + struct wlr_box geom = container_box_to_content_geometry(con, box_geom); return geom; } diff --git a/src/render/render.c b/src/render/render.c index 295c473a..cc5bed4e 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -328,7 +328,7 @@ static void render_stack(struct monitor *m, pixman_region32_t *output_damage) * xdg_surface's toplevel and popups. */ struct wlr_surface *surface = get_wlrsurface(con->client); - struct wlr_box obox = container_get_current_geom(con); + struct wlr_box obox = container_get_current_content_geom(con); struct render_texture_data render_data; render_data.alpha = con->alpha; diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index 9d5a8bea..2e5dd2fd 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -310,7 +310,7 @@ void container_update_size(struct container *con) { con->client->resized = true; - struct wlr_box con_geom = container_get_current_geom(con); + struct wlr_box con_geom = container_get_current_content_geom(con); apply_bounds(con, *wlr_output_layout_get_box(server.output_layout, NULL)); /* wlroots makes this a no-op if size hasn't changed */ From 139fa3f717a665ac5d84f71d1f07a5e5f9371051 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 18:07:55 +0100 Subject: [PATCH 21/93] fix: fix border geometry not being calculated correctly --- src/container.c | 6 ++--- test/container_test.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/container.c b/src/container.c index cdfc3e8a..b2f2f3ab 100644 --- a/src/container.c +++ b/src/container.c @@ -998,14 +998,13 @@ struct wlr_box container_get_current_border_geom(struct container *con, enum wlr case WLR_EDGE_TOP: { struct direction_value d = container_get_border_width(con); - geom.y = geom.y - d.top; geom.height = d.top; break; } case WLR_EDGE_BOTTOM: { struct direction_value d = container_get_border_width(con); - geom.y += geom.height; + geom.y += geom.height - d.bottom; geom.height = d.bottom; break; } @@ -1013,7 +1012,6 @@ struct wlr_box container_get_current_border_geom(struct container *con, enum wlr case WLR_EDGE_LEFT: { struct direction_value d = container_get_border_width(con); - geom.x = geom.x - d.left; geom.width = d.left; break; } @@ -1021,7 +1019,7 @@ struct wlr_box container_get_current_border_geom(struct container *con, enum wlr case WLR_EDGE_RIGHT: { struct direction_value d = container_get_border_width(con); - geom.x += geom.width; + geom.x += geom.width - d.right; geom.width = d.right; break; } diff --git a/test/container_test.c b/test/container_test.c index fad63f65..daacb63e 100644 --- a/test/container_test.c +++ b/test/container_test.c @@ -7,6 +7,13 @@ #include "server.h" #include "client.h" +static void assert_wlr_box_equal(struct wlr_box box1, struct wlr_box box2) { + g_assert_cmpint(box1.x, ==, box2.x); + g_assert_cmpint(box1.y, ==, box2.y); + g_assert_cmpint(box1.width, ==, box2.width); + g_assert_cmpint(box1.height, ==, box2.height); +} + void test_container_box_to_content_geometry() { init_server(); @@ -38,6 +45,59 @@ void test_container_box_to_content_geometry() bitset_destroy(c.sticky_tags); } +void test_container_get_current_border_geom() +{ + init_server(); + struct wlr_box box = { + .x = 0, + .y = 0, + .width = 100, + .height = 100, + }; + struct wlr_box border_left = { + .x = 0, + .y = 0, + .width = 10, + .height = 100, + }; + struct wlr_box border_right = { + .x = 90, + .y = 0, + .width = 10, + .height = 100, + }; + struct wlr_box border_top = { + .x = 0, + .y = 0, + .width = 100, + .height = 10, + }; + struct wlr_box border_bottom = { + .x = 0, + .y = 90, + .width = 100, + .height = 10, + }; + struct monitor m; + struct client c = { + .sticky_tags = bitset_create(), + }; + + struct container *con = create_container(&c, &m, true); + container_set_current_geom(con, box); + container_set_border_width(con, direction_value_uniform(10)); + + struct wlr_box left = container_get_current_border_geom(con, WLR_EDGE_LEFT); + struct wlr_box right = container_get_current_border_geom(con, WLR_EDGE_RIGHT); + struct wlr_box top = container_get_current_border_geom(con, WLR_EDGE_TOP); + struct wlr_box bottom = container_get_current_border_geom(con, WLR_EDGE_BOTTOM); + + assert_wlr_box_equal(left, border_left); + assert_wlr_box_equal(right, border_right); + assert_wlr_box_equal(top, border_top); + assert_wlr_box_equal(bottom, border_bottom); +} + void test_container_content_geometry_to_box() { init_server(); @@ -287,6 +347,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); add_test(test_container_box_to_content_geometry); + add_test(test_container_get_current_border_geom); add_test(test_container_content_geometry_to_box); add_test(test_container_current_geom); add_test(test_container_floating_content_geom); From 31089f96abb8b21d2efbea63badce0bee46a9cb3 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 18:11:16 +0100 Subject: [PATCH 22/93] fix flickering --- src/container.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/container.c b/src/container.c index b2f2f3ab..e529679a 100644 --- a/src/container.c +++ b/src/container.c @@ -212,13 +212,14 @@ static void damage_container_area(struct container *con, struct wlr_box geom, static void container_damage(struct container *con, bool whole) { for (int i = 0; i < server.mons->len; i++) { - struct wlr_box con_geom = container_get_current_geom(con); + struct wlr_box con_geom = container_get_current_content_geom(con); damage_container_area(con, con_geom, whole); } struct client *c = con->client; if (c->resized || c->moved_tag) { - damage_container_area(con, con->prev_geom, whole); + struct wlr_box content_geom = container_box_to_content_geometry(con, con->prev_geom); + damage_container_area(con, content_geom, whole); c->resized = false; c->moved_tag = false; } From 7006ff082ff62978abd9f68e3fcc506a61ae267e Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 20:36:29 +0100 Subject: [PATCH 23/93] fix stuff --- include/container.h | 5 +++-- src/client.c | 7 ++----- src/container.c | 33 ++++++++++++++++++++++++--------- src/render/render.c | 20 ++++++++++---------- src/tile/tileUtils.c | 4 ++-- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/include/container.h b/include/container.h index d3e6673a..42061eb6 100644 --- a/include/container.h +++ b/include/container.h @@ -81,10 +81,11 @@ struct wlr_box get_monitor_local_box(struct wlr_box box, struct monitor *m); struct wlr_fbox lua_togeometry(lua_State *L); void ack_configure(struct wl_listener *listener, void *data); -void apply_bounds(struct container *con, struct wlr_box bbox); +struct wlr_box apply_bounds(struct container *con, struct wlr_box bbox); void commit_notify(struct wl_listener *listener, void *data); void configure_notify(struct wl_listener *listener, void *data); -void container_damage_borders(struct container *con, struct monitor *m, struct wlr_box geom); +void container_damage_borders_at_monitor(struct container *con, struct monitor *m); +void container_damage_borders(struct container *con); void container_damage_part(struct container *con); void container_damage_whole(struct container *con); void container_fix_position_to_begin(struct container *con); diff --git a/src/client.c b/src/client.c index eb96f867..659e9f17 100644 --- a/src/client.c +++ b/src/client.c @@ -132,9 +132,7 @@ void focus_client(struct seat *seat, struct client *old, struct client *c) cursor_constrain(seat->cursor, NULL); unfocus_client(old); struct container *old_con = old->con; - struct wlr_box geom = container_get_current_geom(old_con); - struct monitor *m = container_get_monitor(old_con); - container_damage_borders(old_con, m, geom); + container_damage_borders(old_con); } } @@ -156,8 +154,7 @@ void focus_client(struct seat *seat, struct client *old, struct client *c) struct container *con = c->con; struct monitor *m = container_get_monitor(con); - struct wlr_box geom = container_get_current_geom(con); - container_damage_borders(con, m, geom); + container_damage_borders_at_monitor(con, m); /* Activate the new client */ switch (c->type) { diff --git a/src/container.c b/src/container.c index e529679a..54d3f992 100644 --- a/src/container.c +++ b/src/container.c @@ -96,6 +96,8 @@ void container_property_set_floating(struct container_property *property, bool f lift_container(con); con->client->resized = true; container_damage_whole(con); + + container_update_size(con); } struct container *create_container(struct client *c, struct monitor *m, bool has_border) @@ -176,7 +178,7 @@ void remove_container_from_tile(struct container *con) ipc_event_tag(); } -void container_damage_borders(struct container *con, struct monitor *m, struct wlr_box geom) +void container_damage_borders_at_monitor(struct container *con, struct monitor *m) { if (!con) return; @@ -199,14 +201,25 @@ void container_damage_borders(struct container *con, struct monitor *m, struct w pthread_mutex_unlock(&lock_rendering_action); } +void container_damage_borders(struct container *con) +{ + if (!con) + return; + + for (int i = 0; i < server.mons->len; i++) { + struct monitor *m = g_ptr_array_index(server.mons, i); + container_damage_borders_at_monitor(con, m); + } +} + static void damage_container_area(struct container *con, struct wlr_box geom, bool whole) { for (int i = 0; i < server.mons->len; i++) { struct monitor *m = g_ptr_array_index(server.mons, i); output_damage_surface(m, get_wlrsurface(con->client), &geom, whole); - container_damage_borders(con, m, geom); } + container_damage_borders(con); } static void container_damage(struct container *con, bool whole) @@ -218,8 +231,7 @@ static void container_damage(struct container *con, bool whole) struct client *c = con->client; if (c->resized || c->moved_tag) { - struct wlr_box content_geom = container_box_to_content_geometry(con, con->prev_geom); - damage_container_area(con, content_geom, whole); + damage_container_area(con, con->prev_geom, whole); c->resized = false; c->moved_tag = false; } @@ -377,7 +389,7 @@ struct wlr_fbox lua_togeometry(lua_State *L) return geom; } -void apply_bounds(struct container *con, struct wlr_box box) +struct wlr_box apply_bounds(struct container *con, struct wlr_box box) { /* set minimum possible */ struct wlr_box con_geom = container_get_current_content_geom(con); @@ -396,6 +408,7 @@ void apply_bounds(struct container *con, struct wlr_box box) con_geom.y = box.y; container_set_current_content_geom(con, con_geom); + return con_geom; } void commit_notify(struct wl_listener *listener, void *data) @@ -744,6 +757,8 @@ void move_container(struct container *con, struct wlr_cursor *cursor, int offset struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); + + con->client->resized = true; container_damage(con, true); } @@ -844,8 +859,6 @@ void container_set_floating_geom_at_tag(struct container *con, con->prev_geom = *con_geom; *con_geom = geom; - // TODO: do we need that? - // container_update_size(con); } void container_set_floating_geom(struct container *con, struct wlr_box geom) @@ -1102,13 +1115,15 @@ void resize_container(struct container *con, struct wlr_cursor *cursor, int offs container_set_floating(con, container_fix_position, true); arrange(); } - container_set_floating_geom(con, geom); + container_damage_borders(con); + + container_set_floating_geom(con, geom); struct tag *tag = container_get_current_tag(con); struct layout *lt = tag_get_layout(tag); container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); - container_damage(con, true); + container_update_size(con); } struct monitor *container_get_monitor(struct container *con) diff --git a/src/render/render.c b/src/render/render.c index cc5bed4e..f4b2634b 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -267,25 +267,25 @@ static void render_borders(struct container *con, struct monitor *m, pixman_regi container_get_current_border_geom(con, WLR_EDGE_RIGHT), }; - enum wlr_edges hidden_edges = WLR_EDGE_NONE; + // enum wlr_edges hidden_edges = WLR_EDGE_NONE; struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); - if (lt->options->smart_hidden_edges) { - if (tag->visible_con_set->tiled_containers->len <= 1) { - hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - } - } else { - hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - } + // if (lt->options->smart_hidden_edges) { + // if (tag->visible_con_set->tiled_containers->len <= 1) { + // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); + // } + // } else { + // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); + // } /* Draw window borders */ struct container *sel = monitor_get_focused_container(m); const struct color color = (con == sel) ? lt->options->focus_color : lt->options->border_color; for (int i = 0; i < 4; i++) { - if ((hidden_edges & (1 << i)) == 0) { + // if ((hidden_edges & (1 << i)) == 0) { scale_box(&borders[i], m->wlr_output->scale); render_rect(m, output_damage, &borders[i], color); - } + // } } } diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index 2e5dd2fd..db9c8b3c 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -45,7 +45,7 @@ void arrange() struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); - container_update_size(con); + // container_update_size(con); container_set_hidden(con, false); } @@ -311,7 +311,7 @@ void container_update_size(struct container *con) con->client->resized = true; struct wlr_box con_geom = container_get_current_content_geom(con); - apply_bounds(con, *wlr_output_layout_get_box(server.output_layout, NULL)); + con_geom = apply_bounds(con, *wlr_output_layout_get_box(server.output_layout, NULL)); /* wlroots makes this a no-op if size hasn't changed */ switch (con->client->type) { From 08895e98d61b2d1fb8183b0c714f6237ce73e0fb Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 3 Feb 2022 20:55:44 +0100 Subject: [PATCH 24/93] fix stuff --- include/container.h | 1 - src/container.c | 29 +++++++++++------------------ src/ipc-json.c | 2 ++ src/render/render.c | 22 +++++++++++----------- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/include/container.h b/include/container.h index 42061eb6..911b4cfc 100644 --- a/include/container.h +++ b/include/container.h @@ -129,7 +129,6 @@ struct wlr_box container_get_current_geom(struct container *con); struct wlr_box container_get_tiled_content_geom_at_tag(struct container *con, struct tag *tag); struct wlr_box container_get_floating_content_geom_at_tag(struct container *con, struct tag *tag); -struct wlr_box container_get_current_content_geom_at_tag(struct container *con, struct tag *tag); struct wlr_box container_get_tiled_content_geom(struct container *con); struct wlr_box container_get_floating_content_geom(struct container *con); struct wlr_box container_get_current_content_geom(struct container *con); diff --git a/src/container.c b/src/container.c index 54d3f992..ed42e423 100644 --- a/src/container.c +++ b/src/container.c @@ -911,8 +911,11 @@ struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag struct wlr_box container_get_tiled_geom(struct container *con) { - struct wlr_box content_geom = container_get_tiled_content_geom(con); - struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + struct tag *tag = container_get_current_tag(con); + if (!tag) + return (struct wlr_box){0}; + + struct wlr_box geom = container_get_tiled_geom_at_tag(con, tag); return geom; } @@ -955,8 +958,8 @@ struct wlr_box container_get_current_geom_at_tag(struct container *con, struct t struct wlr_box container_get_current_geom(struct container *con) { - struct wlr_box content_geom = container_get_current_content_geom(con); - struct wlr_box geom = container_content_geometry_to_box(con, content_geom); + struct tag *tag = container_get_current_tag(con); + struct wlr_box geom = container_get_current_geom_at_tag(con, tag); return geom; } @@ -974,20 +977,10 @@ struct wlr_box container_get_floating_content_geom_at_tag(struct container *con, return geom; } -struct wlr_box container_get_current_content_geom_at_tag(struct container *con, struct tag *tag) -{ - struct wlr_box box_geom = container_get_current_geom_at_tag(con, tag); - struct wlr_box geom = container_box_to_content_geometry(con, box_geom); - return geom; -} - struct wlr_box container_get_tiled_content_geom(struct container *con) { - struct tag *tag = container_get_current_tag(con); - if (!tag) - return (struct wlr_box){0}; - - struct wlr_box geom = container_get_tiled_content_geom_at_tag(con, tag); + struct wlr_box box_geom = container_get_tiled_geom(con); + struct wlr_box geom = container_box_to_content_geometry(con, box_geom); return geom; } @@ -1000,8 +993,8 @@ struct wlr_box container_get_floating_content_geom(struct container *con) struct wlr_box container_get_current_content_geom(struct container *con) { - struct tag *tag = container_get_current_tag(con); - struct wlr_box geom = container_get_current_content_geom_at_tag(con, tag); + struct wlr_box content_geom = container_get_current_geom(con); + struct wlr_box geom = container_box_to_content_geometry(con, content_geom); return geom; } diff --git a/src/ipc-json.c b/src/ipc-json.c index 8bc134fd..34909cdf 100644 --- a/src/ipc-json.c +++ b/src/ipc-json.c @@ -369,6 +369,8 @@ json_object *ipc_json_describe_monitor(struct monitor *m) json_object *ipc_json_describe_container(struct container *con) { + if (!con) + return NULL; struct wlr_box geom = container_get_current_geom(con); json_object *object = ipc_json_create_node( 5, con ? con->client->title : NULL, true, NULL, diff --git a/src/render/render.c b/src/render/render.c index f4b2634b..ae0f8bc9 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -222,7 +222,7 @@ static void scissor_output(struct wlr_output *output, pixman_box32_t *rect) } // TODO refactor the name it doesn't represent what this does perfectly -static enum wlr_edges get_hidden_edges(struct container *con, struct wlr_box *borders, enum wlr_edges hidden_edges) +static enum wlr_edges container_get_hidden_edges(struct container *con, struct wlr_box *borders, enum wlr_edges hidden_edges) { struct monitor *m = container_get_monitor(con); @@ -267,25 +267,25 @@ static void render_borders(struct container *con, struct monitor *m, pixman_regi container_get_current_border_geom(con, WLR_EDGE_RIGHT), }; - // enum wlr_edges hidden_edges = WLR_EDGE_NONE; + enum wlr_edges hidden_edges = WLR_EDGE_NONE; struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); - // if (lt->options->smart_hidden_edges) { - // if (tag->visible_con_set->tiled_containers->len <= 1) { - // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - // } - // } else { - // hidden_edges = get_hidden_edges(con, borders, lt->options->hidden_edges); - // } + if (lt->options->smart_hidden_edges) { + if (tag->visible_con_set->tiled_containers->len <= 1) { + hidden_edges = container_get_hidden_edges(con, borders, lt->options->hidden_edges); + } + } else { + hidden_edges = container_get_hidden_edges(con, borders, lt->options->hidden_edges); + } /* Draw window borders */ struct container *sel = monitor_get_focused_container(m); const struct color color = (con == sel) ? lt->options->focus_color : lt->options->border_color; for (int i = 0; i < 4; i++) { - // if ((hidden_edges & (1 << i)) == 0) { + if ((hidden_edges & (1 << i)) == 0) { scale_box(&borders[i], m->wlr_output->scale); render_rect(m, output_damage, &borders[i], color); - // } + } } } From 790f12b359c7f9bea367271ab8b460de348e7ae4 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 00:31:16 +0100 Subject: [PATCH 25/93] fix stuff --- include/container.h | 4 +++ src/container.c | 84 +++++++++++++++++++++++++++++++++------------ src/render/render.c | 8 +++-- 3 files changed, 71 insertions(+), 25 deletions(-) diff --git a/include/container.h b/include/container.h index 911b4cfc..63c63565 100644 --- a/include/container.h +++ b/include/container.h @@ -51,6 +51,7 @@ struct container { struct direction_value border_width; struct direction_value padding; struct direction_value margin; + enum wlr_edges hidden_edges; // height = ratio * width float ratio; @@ -120,6 +121,9 @@ void container_set_current_content_geom(struct container *con, struct wlr_box ge void container_set_tiled_content_geom(struct container *con, struct wlr_box geom); void container_set_floating_content_geom(struct container *con, struct wlr_box geom); +void container_set_hidden_edges(struct container *con, enum wlr_edges edges); +enum wlr_edges container_get_hidden_edges(struct container *con); + struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag *tag); struct wlr_box container_get_floating_geom_at_tag(struct container *con, struct tag *tag); struct wlr_box container_get_current_geom_at_tag(struct container *con, struct tag *tag); diff --git a/src/container.c b/src/container.c index ed42e423..0bb94e08 100644 --- a/src/container.c +++ b/src/container.c @@ -885,6 +885,16 @@ void container_set_floating_content_geom(struct container *con, struct wlr_box g container_set_floating_geom(con, box_geom); } +void container_set_hidden_edges(struct container *con, enum wlr_edges edges) +{ + con->hidden_edges = edges; +} + +enum wlr_edges container_get_hidden_edges(struct container *con) +{ + return con->hidden_edges; +} + struct direction_value direction_value_uniform(int value) { return (struct direction_value){ @@ -1001,33 +1011,43 @@ struct wlr_box container_get_current_content_geom(struct container *con) struct wlr_box container_get_current_border_geom(struct container *con, enum wlr_edges dir) { struct wlr_box geom = container_get_current_geom(con); + enum wlr_edges hidden_edges = container_get_hidden_edges(con); + printf("hidden_edges: %i\n", hidden_edges); switch (dir) { case WLR_EDGE_TOP: { - struct direction_value d = container_get_border_width(con); - geom.height = d.top; + if (!(hidden_edges & WLR_EDGE_TOP)) { + struct direction_value d = container_get_border_width(con); + geom.height = d.top; + } break; } case WLR_EDGE_BOTTOM: { - struct direction_value d = container_get_border_width(con); - geom.y += geom.height - d.bottom; - geom.height = d.bottom; + if (!(hidden_edges & WLR_EDGE_BOTTOM)) { + struct direction_value d = container_get_border_width(con); + geom.y += geom.height - d.bottom; + geom.height = d.bottom; + } break; } break; case WLR_EDGE_LEFT: { - struct direction_value d = container_get_border_width(con); - geom.width = d.left; + if (!(hidden_edges & WLR_EDGE_LEFT)) { + struct direction_value d = container_get_border_width(con); + geom.width = d.left; + } break; } break; case WLR_EDGE_RIGHT: { - struct direction_value d = container_get_border_width(con); - geom.x += geom.width - d.right; - geom.width = d.right; + if (!(hidden_edges & WLR_EDGE_RIGHT)) { + struct direction_value d = container_get_border_width(con); + geom.x += geom.width - d.right; + geom.width = d.right; + } break; } break; @@ -1041,12 +1061,22 @@ struct wlr_box container_content_geometry_to_box(struct container *con, struct wlr_box geom) { struct direction_value borders = container_get_border_width(con); - struct wlr_box box_geom = { - .x = geom.x - borders.left, - .y = geom.y - borders.top, - .width = geom.width + borders.left + borders.right, - .height = geom.height + borders.top + borders.bottom, - }; + enum wlr_edges hidden_edges = container_get_hidden_edges(con); + struct wlr_box box_geom = geom; + if (!(hidden_edges & WLR_EDGE_LEFT)) { + box_geom.x -= borders.left; + box_geom.width += borders.left; + } + if (!(hidden_edges & WLR_EDGE_RIGHT)) { + box_geom.width += borders.right; + } + if (!(hidden_edges & WLR_EDGE_TOP)) { + box_geom.y -= borders.top; + box_geom.height += borders.top; + } + if (!(hidden_edges & WLR_EDGE_BOTTOM)) { + box_geom.height += borders.bottom; + } return box_geom; } @@ -1054,12 +1084,22 @@ struct wlr_box container_box_to_content_geometry(struct container *con, struct wlr_box geom) { struct direction_value borders = container_get_border_width(con); - struct wlr_box content_geom = { - .x = geom.x + borders.left, - .y = geom.y + borders.top, - .width = geom.width - borders.left - borders.right, - .height = geom.height - borders.top - borders.bottom, - }; + enum wlr_edges hidden_edges = container_get_hidden_edges(con); + struct wlr_box content_geom = geom; + if (!(hidden_edges & WLR_EDGE_LEFT)) { + content_geom.x += borders.left; + content_geom.width -= borders.left; + } + if (!(hidden_edges & WLR_EDGE_RIGHT)) { + content_geom.width -= borders.right; + } + if (!(hidden_edges & WLR_EDGE_TOP)) { + content_geom.y += borders.top; + content_geom.height -= borders.top; + } + if (!(hidden_edges & WLR_EDGE_BOTTOM)) { + content_geom.height -= borders.bottom; + } return content_geom; } diff --git a/src/render/render.c b/src/render/render.c index ae0f8bc9..61f57f5c 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -222,7 +222,8 @@ static void scissor_output(struct wlr_output *output, pixman_box32_t *rect) } // TODO refactor the name it doesn't represent what this does perfectly -static enum wlr_edges container_get_hidden_edges(struct container *con, struct wlr_box *borders, enum wlr_edges hidden_edges) +// returns the newly accquired hidden edges +static enum wlr_edges container_update_hidden_edges(struct container *con, struct wlr_box *borders, enum wlr_edges hidden_edges) { struct monitor *m = container_get_monitor(con); @@ -251,6 +252,7 @@ static enum wlr_edges container_get_hidden_edges(struct container *con, struct w } } + container_set_hidden_edges(con, containers_hidden_edges); return containers_hidden_edges; } @@ -272,10 +274,10 @@ static void render_borders(struct container *con, struct monitor *m, pixman_regi struct layout *lt = tag_get_layout(tag); if (lt->options->smart_hidden_edges) { if (tag->visible_con_set->tiled_containers->len <= 1) { - hidden_edges = container_get_hidden_edges(con, borders, lt->options->hidden_edges); + hidden_edges = container_update_hidden_edges(con, borders, lt->options->hidden_edges); } } else { - hidden_edges = container_get_hidden_edges(con, borders, lt->options->hidden_edges); + hidden_edges = container_update_hidden_edges(con, borders, lt->options->hidden_edges); } /* Draw window borders */ From 7b9520b2cb23e76e322c253091a605f52a795f73 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 00:44:13 +0100 Subject: [PATCH 26/93] feat: fix borders --- src/container.c | 9 +++-- test/container_test.c | 85 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/container.c b/src/container.c index 0bb94e08..03a068e9 100644 --- a/src/container.c +++ b/src/container.c @@ -887,7 +887,10 @@ void container_set_floating_content_geom(struct container *con, struct wlr_box g void container_set_hidden_edges(struct container *con, enum wlr_edges edges) { + if (con->hidden_edges == edges) + return; con->hidden_edges = edges; + container_update_size(con); } enum wlr_edges container_get_hidden_edges(struct container *con) @@ -1003,8 +1006,9 @@ struct wlr_box container_get_floating_content_geom(struct container *con) struct wlr_box container_get_current_content_geom(struct container *con) { - struct wlr_box content_geom = container_get_current_geom(con); - struct wlr_box geom = container_box_to_content_geometry(con, content_geom); + struct wlr_box box_geom = container_get_current_geom(con); + struct wlr_box geom = container_box_to_content_geometry(con, box_geom); + printf("con: %p x: %i\n", con, geom.x); return geom; } @@ -1012,7 +1016,6 @@ struct wlr_box container_get_current_border_geom(struct container *con, enum wlr { struct wlr_box geom = container_get_current_geom(con); enum wlr_edges hidden_edges = container_get_hidden_edges(con); - printf("hidden_edges: %i\n", hidden_edges); switch (dir) { case WLR_EDGE_TOP: { diff --git a/test/container_test.c b/test/container_test.c index daacb63e..b94b538d 100644 --- a/test/container_test.c +++ b/test/container_test.c @@ -29,6 +29,30 @@ void test_container_box_to_content_geometry() .width = 80, .height = 80, }; + struct wlr_box left_border_hidden_content_box = { + .x = 0, + .y = 10, + .width = 90, + .height = 80, + }; + struct wlr_box right_border_hidden_content_box = { + .x = 10, + .y = 10, + .width = 90, + .height = 80, + }; + struct wlr_box top_border_hidden_content_box = { + .x = 10, + .y = 0, + .width = 80, + .height = 90, + }; + struct wlr_box bottom_border_hidden_content_box = { + .x = 10, + .y = 10, + .width = 80, + .height = 90, + }; struct monitor m; struct client c = { .sticky_tags = bitset_create(), @@ -37,10 +61,23 @@ void test_container_box_to_content_geometry() struct container *con = create_container(&c, &m, true); container_set_border_width(con, direction_value_uniform(10)); struct wlr_box result = container_box_to_content_geometry(con, box); - g_assert_cmpint(result.x, ==, content_box.x); - g_assert_cmpint(result.y, ==, content_box.y); - g_assert_cmpint(result.width, ==, content_box.width); - g_assert_cmpint(result.height, ==, content_box.height); + assert_wlr_box_equal(result, content_box); + + con->hidden_edges = WLR_EDGE_LEFT; + result = container_box_to_content_geometry(con, box); + assert_wlr_box_equal(result, left_border_hidden_content_box); + + con->hidden_edges = WLR_EDGE_RIGHT; + result = container_box_to_content_geometry(con, box); + assert_wlr_box_equal(result, right_border_hidden_content_box); + + con->hidden_edges = WLR_EDGE_TOP; + result = container_box_to_content_geometry(con, box); + assert_wlr_box_equal(result, top_border_hidden_content_box); + + con->hidden_edges = WLR_EDGE_BOTTOM; + result = container_box_to_content_geometry(con, box); + assert_wlr_box_equal(result, bottom_border_hidden_content_box); bitset_destroy(c.sticky_tags); } @@ -113,6 +150,30 @@ void test_container_content_geometry_to_box() .width = 80, .height = 80, }; + struct wlr_box left_border_hidden_content_box = { + .x = 0, + .y = 10, + .width = 90, + .height = 80, + }; + struct wlr_box right_border_hidden_content_box = { + .x = 10, + .y = 10, + .width = 90, + .height = 80, + }; + struct wlr_box top_border_hidden_content_box = { + .x = 10, + .y = 0, + .width = 80, + .height = 90, + }; + struct wlr_box bottom_border_hidden_content_box = { + .x = 10, + .y = 10, + .width = 80, + .height = 90, + }; struct monitor m; struct client c = { .sticky_tags = bitset_create(), @@ -125,6 +186,22 @@ void test_container_content_geometry_to_box() g_assert_cmpint(result.width, ==, box.width); g_assert_cmpint(result.height, ==, box.height); + con->hidden_edges = WLR_EDGE_LEFT; + result = container_content_geometry_to_box(con, left_border_hidden_content_box); + assert_wlr_box_equal(result, box); + + con->hidden_edges = WLR_EDGE_RIGHT; + result = container_content_geometry_to_box(con, right_border_hidden_content_box); + assert_wlr_box_equal(result, box); + + con->hidden_edges = WLR_EDGE_TOP; + result = container_content_geometry_to_box(con, top_border_hidden_content_box); + assert_wlr_box_equal(result, box); + + con->hidden_edges = WLR_EDGE_BOTTOM; + result = container_content_geometry_to_box(con, bottom_border_hidden_content_box); + assert_wlr_box_equal(result, box); + free(con); bitset_destroy(c.sticky_tags); } From f35984415e6a0103bf9d059f5d0ede695ab6f407 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 01:32:16 +0100 Subject: [PATCH 27/93] fix: fix layer shell program not being shown properly --- src/container.c | 7 ++++++- src/ipc-json.c | 2 -- src/layer_shell.c | 5 +++++ src/render/render.c | 1 - src/tile/tileUtils.c | 10 ---------- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/container.c b/src/container.c index 03a068e9..1d152f14 100644 --- a/src/container.c +++ b/src/container.c @@ -837,6 +837,12 @@ void container_set_tiled_geom(struct container *con, struct wlr_box geom) } con->prev_geom = con_geom; + + if (con->client->type == LAYER_SHELL) { + con->global_geom = geom; + return; + } + struct container_property *property = container_get_property(con); if (!property) return; @@ -1008,7 +1014,6 @@ struct wlr_box container_get_current_content_geom(struct container *con) { struct wlr_box box_geom = container_get_current_geom(con); struct wlr_box geom = container_box_to_content_geometry(con, box_geom); - printf("con: %p x: %i\n", con, geom.x); return geom; } diff --git a/src/ipc-json.c b/src/ipc-json.c index 34909cdf..8bc134fd 100644 --- a/src/ipc-json.c +++ b/src/ipc-json.c @@ -369,8 +369,6 @@ json_object *ipc_json_describe_monitor(struct monitor *m) json_object *ipc_json_describe_container(struct container *con) { - if (!con) - return NULL; struct wlr_box geom = container_get_current_geom(con); json_object *object = ipc_json_create_node( 5, con ? con->client->title : NULL, true, NULL, diff --git a/src/layer_shell.c b/src/layer_shell.c index 8be274ac..3ba8a327 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -276,6 +276,11 @@ void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_ar } // TODO: is that correct? container_set_current_geom(con, box); + struct wlr_box current_geom = container_get_current_geom(con); + printf("con.geom.x: %i\n", current_geom.x); + printf("con.geom.y: %i\n", current_geom.y); + printf("con.geom.width: %i\n", current_geom.width); + printf("con.geom.height: %i\n", current_geom.height); if (state->exclusive_zone > 0) apply_exclusive(usable_area, state->anchor, state->exclusive_zone, diff --git a/src/render/render.c b/src/render/render.c index 61f57f5c..64cc240c 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -18,7 +18,6 @@ #include "server.h" #include "tile/tileUtils.h" #include "utils/gapUtils.h" -#include "layer_shell.h" #include "tag.h" #include "tagset.h" diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index db9c8b3c..4cec902e 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -262,16 +262,6 @@ void arrange_containers( * inner_gap. */ container_surround_gaps(&root_geom, -actual_inner_gap); - if (lt->options->smart_hidden_edges) { - if (tiled_containers->len <= 1) { - // container_add_gaps(&root_geom, -lt->options->tile_border_px, - // lt->options->hidden_edges); - } - } else { - // container_add_gaps(&root_geom, -lt->options->tile_border_px, - // lt->options->hidden_edges); - } - // debug_print("tiled containers len: %i\n", tiled_containers->len); for (int i = 0; i < tiled_containers->len; i++) { struct container *con = g_ptr_array_index(tiled_containers, i); From 979ebd6cee1c344703118e6fbf46f9bb2c13f754 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 01:58:15 +0100 Subject: [PATCH 28/93] fix stuff --- src/container.c | 3 +++ src/layer_shell.c | 5 ----- src/xwayland.c | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/container.c b/src/container.c index 1d152f14..d63faf33 100644 --- a/src/container.c +++ b/src/container.c @@ -857,6 +857,7 @@ void container_set_floating_geom_at_tag(struct container *con, if (!property) return; + printf("set floating geom at tag\n"); struct wlr_box *con_geom = &property->floating_geom; if (con->client->type == LAYER_SHELL) { @@ -1334,6 +1335,8 @@ bool container_is_bar(struct container *con) struct tag *container_get_tag(struct container *con) { + if (!con) + return NULL; struct tag *tag = get_tag(con->tag_id); return tag; } diff --git a/src/layer_shell.c b/src/layer_shell.c index 3ba8a327..8be274ac 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -276,11 +276,6 @@ void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_ar } // TODO: is that correct? container_set_current_geom(con, box); - struct wlr_box current_geom = container_get_current_geom(con); - printf("con.geom.x: %i\n", current_geom.x); - printf("con.geom.y: %i\n", current_geom.y); - printf("con.geom.width: %i\n", current_geom.width); - printf("con.geom.height: %i\n", current_geom.height); if (state->exclusive_zone > 0) apply_exclusive(usable_area, state->anchor, state->exclusive_zone, diff --git a/src/xwayland.c b/src/xwayland.c index 1538df73..25d31d55 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -212,6 +212,7 @@ void maprequestx11(struct wl_listener *listener, void *data) lift_container(con); container_set_floating(con, NULL, true); container_set_floating_geom(con, prefered_geom); + container_update_size(con); break; } default: From fd22168a8c71241d493f0da4817677e31725f837 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 02:18:35 +0100 Subject: [PATCH 29/93] fix: fix multimonitor borders --- src/container.c | 14 ++++++++++++-- src/lib/lib_options.c | 1 + src/render/render.c | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/container.c b/src/container.c index d63faf33..071e5aaf 100644 --- a/src/container.c +++ b/src/container.c @@ -195,8 +195,18 @@ void container_damage_borders_at_monitor(struct container *con, struct monitor * pthread_mutex_lock(&lock_rendering_action); for (int i = 0; i < 4; i++) { - scale_box(&borders[i], m->wlr_output->scale); - wlr_output_damage_add_box(m->damage, &borders[i]); + struct wlr_box border = borders[i]; + double ox = border.x; + double oy = border.y; + wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); + struct wlr_box obox = { + .x = ox, + .y = oy, + .width = border.width, + .height = border.height, + }; + scale_box(&obox, m->wlr_output->scale); + wlr_output_damage_add_box(m->damage, &obox); } pthread_mutex_unlock(&lock_rendering_action); } diff --git a/src/lib/lib_options.c b/src/lib/lib_options.c index 08b303cd..251cab94 100644 --- a/src/lib/lib_options.c +++ b/src/lib/lib_options.c @@ -197,6 +197,7 @@ int lib_set_outer_gaps(lua_State *L) struct options *options = check_options(L, 1); lua_pop(L, 1); + printf("set outer gaps\n"); options->outer_gap = outer_gap; return 0; } diff --git a/src/render/render.c b/src/render/render.c index 64cc240c..0ad41016 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -284,8 +284,18 @@ static void render_borders(struct container *con, struct monitor *m, pixman_regi const struct color color = (con == sel) ? lt->options->focus_color : lt->options->border_color; for (int i = 0; i < 4; i++) { if ((hidden_edges & (1 << i)) == 0) { - scale_box(&borders[i], m->wlr_output->scale); - render_rect(m, output_damage, &borders[i], color); + struct wlr_box border = borders[i]; + double ox = border.x; + double oy = border.y; + wlr_output_layout_output_coords(server.output_layout, m->wlr_output, &ox, &oy); + struct wlr_box obox = { + .x = ox, + .y = oy, + .width = border.width, + .height = border.height, + }; + scale_box(&obox, m->wlr_output->scale); + render_rect(m, output_damage, &obox, color); } } } @@ -293,6 +303,7 @@ static void render_borders(struct container *con, struct monitor *m, pixman_regi void output_surface_for_each_surface(struct monitor *m, struct wlr_surface *surface, struct wlr_box obox, surface_iterator_func_t iterator, void *user_data) { + struct surface_iterator_data data = { .user_iterator = iterator, .user_data = user_data, From 54b17e68f21431b178d94415cf23b726696da516 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 02:19:42 +0100 Subject: [PATCH 30/93] feat: remove useless mutexes --- include/server.h | 1 - src/container.c | 2 -- src/render/render.c | 2 -- src/server.c | 3 --- 4 files changed, 8 deletions(-) diff --git a/include/server.h b/include/server.h index ef9dd6a5..ddedfc22 100644 --- a/include/server.h +++ b/include/server.h @@ -132,7 +132,6 @@ struct function_data { }; extern struct server server; -extern pthread_mutex_t lock_rendering_action; void init_server(); void finalize_server(); diff --git a/src/container.c b/src/container.c index 071e5aaf..72bf21ce 100644 --- a/src/container.c +++ b/src/container.c @@ -193,7 +193,6 @@ void container_damage_borders_at_monitor(struct container *con, struct monitor * container_get_current_border_geom(con, WLR_EDGE_BOTTOM), }; - pthread_mutex_lock(&lock_rendering_action); for (int i = 0; i < 4; i++) { struct wlr_box border = borders[i]; double ox = border.x; @@ -208,7 +207,6 @@ void container_damage_borders_at_monitor(struct container *con, struct monitor * scale_box(&obox, m->wlr_output->scale); wlr_output_damage_add_box(m->damage, &obox); } - pthread_mutex_unlock(&lock_rendering_action); } void container_damage_borders(struct container *con) diff --git a/src/render/render.c b/src/render/render.c index 0ad41016..b8568d84 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -398,7 +398,6 @@ static void clear_frame( void render_monitor(struct monitor *m, pixman_region32_t *damage) { - pthread_mutex_lock(&lock_rendering_action); /* Begin the renderer (calls glViewport and some other GL sanity checks) */ wlr_renderer_begin(server.renderer, m->wlr_output->width, m->wlr_output->height); @@ -421,7 +420,6 @@ void render_monitor(struct monitor *m, pixman_region32_t *damage) wlr_renderer_end(renderer); wlr_output_commit(m->wlr_output); - pthread_mutex_unlock(&lock_rendering_action); } void scale_box(struct wlr_box *box, float scale) diff --git a/src/server.c b/src/server.c index d26e6949..87f96474 100644 --- a/src/server.c +++ b/src/server.c @@ -41,8 +41,6 @@ struct server server; -pthread_mutex_t lock_rendering_action = PTHREAD_MUTEX_INITIALIZER; - static void init_event_handlers(struct server *server); static void init_lists(struct server *server); static void init_timers(struct server *server); @@ -264,7 +262,6 @@ void finalize_server() g_ptr_array_unref(server.container_stack); destroy_event_handler(server.event_handler); - pthread_mutex_destroy(&lock_rendering_action); } void server_terminate(struct server *server) From 5c7a3b4d45a5b5a3ecaaa49f4b9e6b18ca6172ca Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 02:30:52 +0100 Subject: [PATCH 31/93] fix stuff --- src/monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/monitor.c b/src/monitor.c index 454f7fc4..ebe300af 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -37,14 +37,14 @@ void create_monitor(struct wl_listener *listener, void *data) * monitor) becomes available. */ struct wlr_output *output = data; + wlr_output_init_render(output, server.allocator, server.renderer); + /* The mode is a tuple of (width, height, refresh rate), and each * monitor supports only a specific set of modes. We just pick the * monitor's preferred mode; a more sophisticated compositor would let * the user configure it. */ wlr_output_set_mode(output, wlr_output_preferred_mode(output)); - wlr_output_init_render(output, server.allocator, server.renderer); - /* Allocates and configures monitor state using configured rules */ struct monitor *m = output->data = calloc(1, sizeof(*m)); From c9c9c28679828cd9579a5c11f385a6901383e02d Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 03:34:50 +0100 Subject: [PATCH 32/93] fix: fix bug that xwayland windows steal focus --- include/container.h | 2 -- src/client.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/container.h b/include/container.h index 63c63565..54d72636 100644 --- a/include/container.h +++ b/include/container.h @@ -49,8 +49,6 @@ struct container { bool on_top; struct direction_value border_width; - struct direction_value padding; - struct direction_value margin; enum wlr_edges hidden_edges; // height = ratio * width diff --git a/src/client.c b/src/client.c index 659e9f17..1071cd5e 100644 --- a/src/client.c +++ b/src/client.c @@ -164,6 +164,7 @@ void focus_client(struct seat *seat, struct client *old, struct client *c) case X11_MANAGED: case X11_UNMANAGED: wlr_xwayland_surface_activate(c->surface.xwayland, true); + wlr_xwayland_surface_restack(c->surface.xwayland, NULL, XCB_STACK_MODE_ABOVE); break; default: break; From 83abc77e9c37941a3ef92e7f629c5bd98d2608fe Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 04:24:21 +0100 Subject: [PATCH 33/93] chore: remove print statements --- src/container.c | 1 - src/layer_shell.c | 1 + src/monitor.c | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/container.c b/src/container.c index 72bf21ce..356662e5 100644 --- a/src/container.c +++ b/src/container.c @@ -865,7 +865,6 @@ void container_set_floating_geom_at_tag(struct container *con, if (!property) return; - printf("set floating geom at tag\n"); struct wlr_box *con_geom = &property->floating_geom; if (con->client->type == LAYER_SHELL) { diff --git a/src/layer_shell.c b/src/layer_shell.c index 8be274ac..521cadad 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -156,6 +156,7 @@ GPtrArray *get_layer_list(struct monitor *m, enum zwlr_layer_shell_v1_layer laye void arrange_layers(struct monitor *m) { + printf("arrange layers\n"); if (!m) return; diff --git a/src/monitor.c b/src/monitor.c index ebe300af..38e8cc7f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -187,6 +187,7 @@ static void handle_output_mode(struct wl_listener *listener, void *data) m->geom = *wlr_output_layout_get_box(server.output_layout, m->wlr_output); arrange_monitor(m); arrange_layers(m); + arrange(); } static void monitor_get_initial_tag(struct monitor *m, GList *tags) From cbb1b3761683585b3c5bbca727080fca74bb0299 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 4 Feb 2022 18:13:32 +0100 Subject: [PATCH 34/93] refactor: refactor server name --- src/server.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/server.c b/src/server.c index 87f96474..23f7083a 100644 --- a/src/server.c +++ b/src/server.c @@ -180,7 +180,7 @@ static void init_event_handlers(struct server *server) static void finalize_event_handlers(struct server *server) { - // TODO: write that one + destroy_event_handler(server->event_handler); } void init_server() @@ -241,6 +241,7 @@ void finalize_server() g_ptr_array_unref(server.named_key_combos); finalize_lists(&server); + finalize_event_handlers(&server); bitset_destroy(server.previous_bitset); @@ -260,8 +261,6 @@ void finalize_server() g_ptr_array_unref(server.layout_paths); g_ptr_array_unref(server.container_stack); - - destroy_event_handler(server.event_handler); } void server_terminate(struct server *server) @@ -388,7 +387,7 @@ static void _async_handler_function(struct uv_async_s *arg) free(data); } -int setup(struct server *server) +int setup_server(struct server *server) { server->uv_loop = uv_default_loop(); @@ -465,7 +464,7 @@ int setup(struct server *server) int start_server(char *startup_cmd) { - if (setup(&server)) { + if (setup_server(&server)) { printf("failed to setup japokwm\n"); return EXIT_FAILURE; } From e40527310812554786eff565229b06e1f862cf38 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 5 Feb 2022 04:05:30 +0100 Subject: [PATCH 35/93] fix: fix borders still being shown when arranged by focus --- src/container.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/container.c b/src/container.c index 356662e5..90f2c3c2 100644 --- a/src/container.c +++ b/src/container.c @@ -1144,6 +1144,10 @@ struct direction_value container_get_border_width(struct container *con) struct container_property *property = container_get_property(con); if (!property) return direction_value_uniform(0); + struct tag *tag = server_get_selected_tag(); + struct layout *lt = tag_get_layout(tag); + if (lt && lt->options->arrange_by_focus) + return direction_value_uniform(0); return property->border_width; } From 9fa28887540de4d813685a6d704dff0eaf99a399 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 5 Feb 2022 17:11:56 +0100 Subject: [PATCH 36/93] fix: fix random crashes on SIGPIPE --- src/lib/lib_action.c | 2 +- src/main.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/lib_action.c b/src/lib/lib_action.c index a4f7ce47..290f0594 100644 --- a/src/lib/lib_action.c +++ b/src/lib/lib_action.c @@ -99,7 +99,7 @@ static void *_call(void *arg) { struct function_data *data = arg; - char path[1024] ; + char path[1024]; const char *cmd = data->cmd; FILE *fp = popen(cmd, "r"); if (fp == NULL) { diff --git a/src/main.c b/src/main.c index 54757c59..da1d19c7 100644 --- a/src/main.c +++ b/src/main.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "keyboard.h" #include "layer_shell.h" @@ -53,6 +54,9 @@ int main(int argc, char *argv[]) setbuf(stdout, NULL); #endif + struct sigaction sigint_action = {.sa_handler = SIG_IGN}; + sigaction(SIGPIPE, &sigint_action, NULL); + init_server(); char *startup_cmd = ""; From c5c2ae145ba9f9674cebe8a20c729ab0fc643716 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 5 Feb 2022 17:30:23 +0100 Subject: [PATCH 37/93] doc: add comment explaining sigaction in main.c --- src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.c b/src/main.c index da1d19c7..675d2067 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,7 @@ int main(int argc, char *argv[]) setbuf(stdout, NULL); #endif + /* If nobody is reading the status output, don't terminate */ struct sigaction sigint_action = {.sa_handler = SIG_IGN}; sigaction(SIGPIPE, &sigint_action, NULL); From 9aa2ac124bbb832e7d0cb9a2b54e7ba64bd1cec1 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 5 Feb 2022 19:26:46 +0100 Subject: [PATCH 38/93] fix: fix things not redrawing if resized in xwayland mapping function --- src/xwayland.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/xwayland.c b/src/xwayland.c index 25d31d55..5e8cd7f2 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -187,6 +187,7 @@ void maprequestx11(struct wl_listener *listener, void *data) if (x11_wants_floating(con->client)) { container_set_floating(con, container_fix_position, true); container_set_floating_geom(con, prefered_geom); + container_update_size(con); } break; } From 94a03116b80baf54813a717df5baf6de9a0bdfcf Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 5 Feb 2022 19:59:17 +0100 Subject: [PATCH 39/93] fix: fix layer shell based programs sometimes not hiding when they are being unmapped --- src/layer_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer_shell.c b/src/layer_shell.c index 521cadad..e8cf1227 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -71,7 +71,7 @@ void unmap_layer_surface_notify(struct wl_listener *listener, void *data) struct client *c = wl_container_of(listener, c, unmap); unmap_layer_surface(c); container_damage_whole(c->con); - + arrange_layers(c->m); } void destroy_layer_surface_notify(struct wl_listener *listener, void *data) From 80d5530db439980577b04561f96e72e35403929c Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 5 Feb 2022 20:12:01 +0100 Subject: [PATCH 40/93] refactor: remove tabs in main.c --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 675d2067..f6eda9c6 100644 --- a/src/main.c +++ b/src/main.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) setbuf(stdout, NULL); #endif - /* If nobody is reading the status output, don't terminate */ + /* If nobody is reading the status output, don't terminate */ struct sigaction sigint_action = {.sa_handler = SIG_IGN}; sigaction(SIGPIPE, &sigint_action, NULL); From c6a42de20f0b9567176581d9a8a5ed1b99361fa9 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sun, 6 Feb 2022 04:54:20 +0100 Subject: [PATCH 41/93] fix some bugs --- src/container.c | 22 +++++++++++++++++++++- src/layer_shell.c | 1 - src/lib/lib_container.c | 1 + src/lib/lib_options.c | 1 - src/server.c | 11 +++++++++++ src/tag.c | 12 ++++++++---- test/tag_test.c | 14 ++++++++++++++ 7 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/container.c b/src/container.c index 90f2c3c2..0d389803 100644 --- a/src/container.c +++ b/src/container.c @@ -1325,10 +1325,30 @@ void move_container_to_tag(struct container *con, struct tag *tag) con->client->moved_tag = true; container_damage_whole(con); + struct tag *old_tag = container_get_current_tag(con); + + printf("old tag new con: %p\n", tag_get_focused_container(tag)); + printf("tag new con: %p\n", tag_get_focused_container(tag)); + arrange(); - tag_this_focus_most_recent_container(); + tagset_reload(tag); + + update_reduced_focus_stack(old_tag); + update_reduced_focus_stack(tag); + tag_focus_most_recent_container(old_tag); + tag_focus_most_recent_container(tag); + + tagset_reload(old_tag); + tagset_reload(tag); + tag_focus_most_recent_container(old_tag); + tag_focus_most_recent_container(tag); tag_update_names(server_get_tags()); + tag_focus_most_recent_container(old_tag); + tag_focus_most_recent_container(tag); + tagset_reload(old_tag); + tagset_reload(tag); + ipc_event_tag(); } diff --git a/src/layer_shell.c b/src/layer_shell.c index e8cf1227..ec45761b 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -156,7 +156,6 @@ GPtrArray *get_layer_list(struct monitor *m, enum zwlr_layer_shell_v1_layer laye void arrange_layers(struct monitor *m) { - printf("arrange layers\n"); if (!m) return; diff --git a/src/lib/lib_container.c b/src/lib/lib_container.c index 258c5953..0be738db 100644 --- a/src/lib/lib_container.c +++ b/src/lib/lib_container.c @@ -14,6 +14,7 @@ #include "bitset/bitset.h" #include "lib/lib_bitset.h" #include "lib/lib_container_property_list.h" +#include "server.h" static const struct luaL_Reg container_meta[] = { diff --git a/src/lib/lib_options.c b/src/lib/lib_options.c index 251cab94..08b303cd 100644 --- a/src/lib/lib_options.c +++ b/src/lib/lib_options.c @@ -197,7 +197,6 @@ int lib_set_outer_gaps(lua_State *L) struct options *options = check_options(L, 1); lua_pop(L, 1); - printf("set outer gaps\n"); options->outer_gap = outer_gap; return 0; } diff --git a/src/server.c b/src/server.c index 23f7083a..9f7b46f5 100644 --- a/src/server.c +++ b/src/server.c @@ -74,6 +74,17 @@ static struct tag *handle_too_few_tags(uint32_t tag_id) wlr_list_cat(new_tag->focus_set->focus_stack_on_top, tag->focus_set->focus_stack_on_top); wlr_list_cat(new_tag->focus_set->focus_stack_normal, tag->focus_set->focus_stack_normal); wlr_list_cat(new_tag->focus_set->focus_stack_not_focusable, tag->focus_set->focus_stack_not_focusable); + + wlr_list_cat(new_tag->visible_con_set->tiled_containers, tag->visible_con_set->tiled_containers); + + wlr_list_cat(new_tag->visible_focus_set->focus_stack_layer_background, tag->visible_focus_set->focus_stack_layer_background); + wlr_list_cat(new_tag->visible_focus_set->focus_stack_layer_bottom, tag->visible_focus_set->focus_stack_layer_bottom); + wlr_list_cat(new_tag->visible_focus_set->focus_stack_layer_top, tag->visible_focus_set->focus_stack_layer_top); + wlr_list_cat(new_tag->visible_focus_set->focus_stack_layer_overlay, tag->visible_focus_set->focus_stack_layer_overlay); + wlr_list_cat(new_tag->visible_focus_set->focus_stack_on_top, tag->visible_focus_set->focus_stack_on_top); + wlr_list_cat(new_tag->visible_focus_set->focus_stack_normal, tag->visible_focus_set->focus_stack_normal); + wlr_list_cat(new_tag->visible_focus_set->focus_stack_not_focusable, tag->visible_focus_set->focus_stack_not_focusable); + return new_tag; } diff --git a/src/tag.c b/src/tag.c index 986655f3..1a89d0c9 100644 --- a/src/tag.c +++ b/src/tag.c @@ -113,6 +113,8 @@ void tag_focus_first_container(struct tag *tag) struct container *con = g_ptr_array_index(tag->visible_con_set->tiled_containers, 0); if (!con) return; + + tag_focus_container(tag, con); } void tag_this_focus_most_recent_container() @@ -129,6 +131,7 @@ void tag_focus_most_recent_container(struct tag *tag) struct container *con = tag_get_focused_container(tag); if (!con) { tag_focus_first_container(tag); + return; } tag_focus_container(tag, con); @@ -647,9 +650,6 @@ void tag_focus_container(struct tag *tag, struct container *con) return; struct monitor *m = tag_get_monitor(tag); - if (!container_viewable_on_monitor(m, con)) - return; - struct container *sel = monitor_get_focused_container(m); /* Put the new client atop the focus stack */ @@ -685,10 +685,14 @@ void tag_update_name(struct tag *tag) int tag_id = tag->id; const char *default_name; + // no number has more than 11 digits when int is 32 bit long + char number_tmp[12]; if (tag_id < lt->options->tag_names->len) { default_name = g_ptr_array_index(lt->options->tag_names, tag_id); } else { - default_name = tag->name; + // TODO explain why +1 + snprintf(number_tmp, 12, "%d:%d", tag_id, c_idx_to_lua_idx(tag_id)); + default_name = number_tmp; } struct container *con = tag_get_local_focused_container(tag); diff --git a/test/tag_test.c b/test/tag_test.c index dd2dc248..acb4ddaf 100644 --- a/test/tag_test.c +++ b/test/tag_test.c @@ -1,7 +1,19 @@ #include +#include "server.h" #include "tag.h" +void test_tag_update_tag_name() +{ + init_server(); + + struct tag *tag = get_tag(0); + tag->name = strdup("gibberish"); + tag_update_name(tag); + g_assert_cmpstr(tag->name, ==, "0:1"); + free(tag->name); +} + #define PREFIX "tag" #define add_test(func) g_test_add_func("/"PREFIX"/"#func, func) int main(int argc, char **argv) @@ -9,5 +21,7 @@ int main(int argc, char **argv) setbuf(stdout, NULL); g_test_init(&argc, &argv, NULL); + add_test(test_tag_update_tag_name); + return g_test_run(); } From e78deb879ef6e8a00626beaf0122e7457e49af90 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sun, 6 Feb 2022 05:14:33 +0100 Subject: [PATCH 42/93] test: add unit test file for ipc-json --- src/container.c | 5 +++++ test/ipc-json_test.c | 24 ++++++++++++++++++++++++ test/meson.build | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/ipc-json_test.c diff --git a/src/container.c b/src/container.c index 0d389803..838228d6 100644 --- a/src/container.c +++ b/src/container.c @@ -1297,6 +1297,11 @@ void container_set_tag_id(struct container *con, int tag_id) bitset_reset_all(con->client->sticky_tags); bitset_set(con->client->sticky_tags, con->tag_id); + struct tag *tag = get_tag(tag_id); + if (!tag_get_monitor(tag)) { + tag_set_current_monitor(tag, server_get_selected_monitor()); + } + tagset_reload(prev_tag); } diff --git a/test/ipc-json_test.c b/test/ipc-json_test.c new file mode 100644 index 00000000..e1938432 --- /dev/null +++ b/test/ipc-json_test.c @@ -0,0 +1,24 @@ +#include +#include + +#include "server.h" +#include "ipc-json.h" + +void test_ipc_json_describe_tagsets() +{ + init_server(); + + // struct tag *tag = get_tag(0); + // ipc_json_describe_tagsets(); +} + +#define PREFIX "container" +#define add_test(func) g_test_add_func("/"PREFIX"/"#func, func) +int main(int argc, char **argv) +{ + setbuf(stdout, NULL); + g_test_init(&argc, &argv, NULL); + + + return g_test_run(); +} diff --git a/test/meson.build b/test/meson.build index 1834e479..1e34db55 100644 --- a/test/meson.build +++ b/test/meson.build @@ -15,7 +15,8 @@ test_files = files( 'scratchpad_test.c', 'bitset_test.c', 'keybinding_test.c', - 'layout_test.c' + 'layout_test.c', + 'ipc-json_test.c', ) foreach test_file: test_files From 1e20207156ccd3d47df53f775f93cd1bf75876af Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 14:00:11 +0100 Subject: [PATCH 43/93] fix: fix scratchpad show_window function --- src/scratchpad.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scratchpad.c b/src/scratchpad.c index 79567d5b..246ae269 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -68,7 +68,8 @@ static void show_container(struct container *con) container_set_tag_id(con, tag->id); container_set_floating(con, container_fix_position, true); struct wlr_box center_box = get_center_box(m->geom); - container_set_current_geom(con, center_box); + container_set_floating_geom(con, center_box); + container_update_size(con); tag_this_focus_container(con); lift_container(con); @@ -88,7 +89,8 @@ void show_scratchpad() container_set_tag_id(con, tag->id); container_set_floating(con, container_fix_position, true); struct wlr_box center_box = get_center_box(m->geom); - container_set_current_geom(con, center_box); + container_set_floating_geom(con, center_box); + container_update_size(con); tag_this_focus_container(con); lift_container(con); From 728b9fbb9a9fac4a72c2420ae4efdd1895950158 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 14:11:34 +0100 Subject: [PATCH 44/93] test: improve test_container_box_to_content_geometry --- src/container.c | 3 +++ test/container_test.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/container.c b/src/container.c index 838228d6..b12445a3 100644 --- a/src/container.c +++ b/src/container.c @@ -1101,6 +1101,9 @@ struct wlr_box container_box_to_content_geometry(struct container *con, { struct direction_value borders = container_get_border_width(con); enum wlr_edges hidden_edges = container_get_hidden_edges(con); + if (!con->has_border) { + return geom; + } struct wlr_box content_geom = geom; if (!(hidden_edges & WLR_EDGE_LEFT)) { content_geom.x += borders.left; diff --git a/test/container_test.c b/test/container_test.c index b94b538d..7228afc8 100644 --- a/test/container_test.c +++ b/test/container_test.c @@ -79,6 +79,12 @@ void test_container_box_to_content_geometry() result = container_box_to_content_geometry(con, box); assert_wlr_box_equal(result, bottom_border_hidden_content_box); + con->hidden_edges = WLR_EDGE_NONE; + con->has_border = false; + result = container_box_to_content_geometry(con, box); + assert_wlr_box_equal(result, box); + + destroy_container(con); bitset_destroy(c.sticky_tags); } From 2b01aab7279a331d427c573c84e26ec90053871e Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 15:34:05 +0100 Subject: [PATCH 45/93] fix: fix container focusing not working as expected --- include/container.h | 2 +- src/container.c | 11 +++-------- src/tagset.c | 4 +--- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/include/container.h b/include/container.h index 54d72636..6f81c131 100644 --- a/include/container.h +++ b/include/container.h @@ -172,7 +172,7 @@ bool container_is_bar(struct container *con); // this function may return NULL when a container is hidden struct tag *container_get_tag(struct container *con); bool container_is_floating(struct container *con); -bool container_is_floating_and_visible(struct container *con); +bool container_is_viewable_on_own_monitor(struct container *con); bool container_is_floating_on_tag(struct container *con, struct tag *tag); bool container_is_tiled(struct container *con); bool container_is_tiled_and_visible(struct container *con); diff --git a/src/container.c b/src/container.c index b12445a3..43718739 100644 --- a/src/container.c +++ b/src/container.c @@ -1386,16 +1386,11 @@ bool container_is_floating(struct container *con) return container_property_is_floating(property); } -bool container_is_floating_and_visible(struct container *con) +bool container_is_viewable_on_own_monitor(struct container *con) { - bool is_floating = container_is_floating(con); - if (!is_floating) - return false; struct monitor *m = server_get_selected_monitor(); - bool intersects = container_intersects_with_monitor(con, m); - if (!intersects) - return false; - return true; + bool viewable = container_viewable_on_monitor(m, con); + return viewable; } bool container_is_floating_on_tag(struct container *con, struct tag *tag) diff --git a/src/tagset.c b/src/tagset.c index c5af4562..1a43c8f7 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -407,12 +407,10 @@ GPtrArray *tagset_get_global_floating_copy(struct tag *tag) struct layout *lt = tag_get_layout(tag); GPtrArray *conditions = g_ptr_array_new(); - g_ptr_array_add(conditions, container_is_tiled_and_visible); - g_ptr_array_add(conditions, container_is_floating_and_visible); + g_ptr_array_add(conditions, container_is_viewable_on_own_monitor); GPtrArray *visible_global_floating_list_copy = NULL; if (lt->options->arrange_by_focus) { - // TODO: FIXME visible_global_floating_list_copy = list_create_filtered_sub_list_with_order( tag->focus_set->focus_stack_normal, From 87ef1d6624e91f0079974214c0850bfc9f7177a8 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 16:03:09 +0100 Subject: [PATCH 46/93] fix: fix bug that previously assigned bitsets won't work when using the call_bitset_func macro is called --- include/lib/lib_bitset.h | 8 +++++--- src/lib/lib_action.c | 2 +- src/lib/lib_bitset.c | 2 ++ src/tag.c | 4 ++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/lib/lib_bitset.h b/include/lib/lib_bitset.h index 3f708676..a3d6c140 100644 --- a/include/lib/lib_bitset.h +++ b/include/lib/lib_bitset.h @@ -5,6 +5,7 @@ #include #include "bitset/bitset.h" +#include "tag.h" struct tag_tags; @@ -16,15 +17,16 @@ void lua_load_bitset(lua_State *L); # define call_bitset_func(L, action, self, ...) \ do {\ - action(self, ##__VA_ARGS__);\ + BitSet *self_copy = server_bitset_get_tmp_copy(self);\ + action(self_copy, ##__VA_ARGS__);\ if (luaL_testudata(L, 1, CONFIG_BITSET_WITH_TAG)) {\ struct tag *tag = self->data;\ - tagset_set_tags(tag, self);\ + tagset_set_tags(tag, self_copy);\ continue;\ }\ if (luaL_testudata(L, 1, CONFIG_BITSET_WITH_CONTAINER)) {\ struct client *c = self->data;\ - client_setsticky(c, self);\ + client_setsticky(c, self_copy);\ continue;\ }\ \ diff --git a/src/lib/lib_action.c b/src/lib/lib_action.c index 290f0594..26a700c8 100644 --- a/src/lib/lib_action.c +++ b/src/lib/lib_action.c @@ -402,6 +402,7 @@ int lib_toggle_tags(lua_State *L) struct monitor *m = server_get_selected_monitor(); struct tag *tag = monitor_get_active_tag(m); BitSet *prev_tags_copy = server_bitset_get_tmp_copy(tag->prev_tags); + print_bitset(prev_tags_copy); tagset_set_tags(tag, prev_tags_copy); return 0; } @@ -412,4 +413,3 @@ int lib_toggle_tag(lua_State *L) tagset_focus_tag(prev_tag); return 0; } - diff --git a/src/lib/lib_bitset.c b/src/lib/lib_bitset.c index 6d8eb788..3e3b4dbe 100644 --- a/src/lib/lib_bitset.c +++ b/src/lib/lib_bitset.c @@ -295,6 +295,8 @@ int lib_bitset_xor(lua_State *L) lua_pop(L, 1); BitSet *self = check_bitset(L, 1); + printf("current bitset:"); + print_bitset(self); call_bitset_func(L, bitset_xor, self, bitset); lua_pop(L, 1); diff --git a/src/tag.c b/src/tag.c index 1a89d0c9..e3bfdd05 100644 --- a/src/tag.c +++ b/src/tag.c @@ -496,6 +496,8 @@ BitSet *tag_get_tags(struct tag *tag) BitSet *tag_get_prev_tags(struct tag *tag) { + printf("set prev_tags:"); + print_bitset(tag->prev_tags); return tag->prev_tags; } @@ -934,6 +936,8 @@ void tag_set_tags(struct tag *tag, BitSet *tags) void tag_set_prev_tags(struct tag *tag, struct BitSet *tags) { + printf("tag prev:"); + print_bitset(tags); bitset_assign_bitset(&tag->prev_tags, tags); } From f024a4932e4cc4f935563ed30919bdcf8f67c470 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 16:09:57 +0100 Subject: [PATCH 47/93] add mod-S-e to cheatsheet --- man/japokwm-cheatsheet.5.scd | 9 ++++++++- src/options.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/man/japokwm-cheatsheet.5.scd b/man/japokwm-cheatsheet.5.scd index 567b0527..6c557980 100644 --- a/man/japokwm-cheatsheet.5.scd +++ b/man/japokwm-cheatsheet.5.scd @@ -219,7 +219,14 @@ mod-m Tag.focused.stack[1]:focus() mod-e - Action.view(tag.focused:get_next_empty(Direction.right)) + Action.view(Tag.focused:get_next_empty(Direction.right)) + +mod-S-e + local con = Container.focused ++ +if not con then ++ + return ++ +end ++ +con.tag = Tag.get_next_empty(Tag.focused, Direction.horizontal) mod-S-space Layout.load(server.default_layout_ring:prev()) diff --git a/src/options.c b/src/options.c index 58472dc5..9c9d5224 100644 --- a/src/options.c +++ b/src/options.c @@ -263,7 +263,14 @@ void load_default_keybindings(struct options *options) bind_key(options, "mod-S-j", Action.focus_on_hidden_stack(0)); bind_key(options, "mod-S-k", Action.focus_on_hidden_stack(-1)); - bind_key(options, "mod-e", Action.view(tag.focused:get_next_empty(Direction.right))); + bind_key(options, "mod-e", Action.view(Tag.focused:get_next_empty(Direction.right))); + bind_key(options, "mod-S-e", function() + local con = Container.focused + if not con then + return + end + con.tag = Tag.get_next_empty(Tag.focused, Direction.horizontal) + end); bind_key(options, "mod-S-space", Layout.load(server.default_layout_ring:prev())); bind_key(options, "mod-space", Layout.load(server.default_layout_ring:next())); From ec56aab34b6e7d1116a3a9f0402f163447d3452f Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 16:31:43 +0100 Subject: [PATCH 48/93] fix: fix infinit loop in layer shell --- src/layer_shell.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/layer_shell.c b/src/layer_shell.c index ec45761b..97f1afc7 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -112,6 +112,7 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) struct monitor *m = wlr_output->data; struct container *con = c->con; container_damage_part(con); + arrange_layers(m); if (c->surface.layer->current.layer != wlr_layer_surface->current.layer) { remove_in_composed_list(server.layer_visual_stack_lists, cmp_ptr, con); @@ -160,10 +161,6 @@ void arrange_layers(struct monitor *m) return; struct wlr_box usable_area = m->geom; - uint32_t layers_above_shell[] = { - ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, - ZWLR_LAYER_SHELL_V1_LAYER_TOP, - }; // Arrange exclusive surfaces from top->bottom arrangelayer(m, server.layer_visual_stack_overlay, &usable_area, true); @@ -182,6 +179,10 @@ void arrange_layers(struct monitor *m) struct seat *seat = input_manager_get_default_seat(); struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat->wlr_seat); + uint32_t layers_above_shell[] = { + ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, + ZWLR_LAYER_SHELL_V1_LAYER_TOP, + }; // Find topmost keyboard interactive layer, if such a layer exists for (size_t i = 0; i < LENGTH(layers_above_shell); i++) { GPtrArray *layer_list = get_layer_list(m, layers_above_shell[i]); @@ -192,7 +193,7 @@ void arrange_layers(struct monitor *m) if (layer_surface->current.keyboard_interactive && layer_surface->mapped) { // Deactivate the focused client. // TODO fix this NULL is not supported in focus_container - tag_this_focus_container(NULL); + tag_this_focus_container(con); wlr_seat_keyboard_notify_enter(seat->wlr_seat, get_wlrsurface(c), kb->keycodes, kb->num_keycodes, @@ -203,6 +204,19 @@ void arrange_layers(struct monitor *m) } } +static bool wlr_box_is_equal(struct wlr_box box1, struct wlr_box box2) +{ + if (box1.x != box2.x) + return false; + if (box1.y != box2.y) + return false; + if (box1.width != box2.width) + return false; + if (box1.height != box2.height) + return false; + return true; +} + void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_area, bool exclusive) { struct wlr_box full_area = m->geom; @@ -274,14 +288,17 @@ void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_ar wlr_layer_surface_v1_destroy(wlr_layer_surface); continue; } - // TODO: is that correct? - container_set_current_geom(con, box); + struct wlr_box prev_geom = container_get_current_geom(con); + container_set_current_geom(con, box); if (state->exclusive_zone > 0) apply_exclusive(usable_area, state->anchor, state->exclusive_zone, state->margin.top, state->margin.right, state->margin.bottom, state->margin.left); - wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); + + if (!wlr_box_is_equal(prev_geom, container_get_current_geom(con))) { + wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); + } } } From 2eb1c8a9938939affe79ecef72c3185f97401416 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 16:44:41 +0100 Subject: [PATCH 49/93] fix stuff --- src/layer_shell.c | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/layer_shell.c b/src/layer_shell.c index 97f1afc7..dedd7960 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -52,26 +52,27 @@ void create_notify_layer_shell(struct wl_listener *listener, void *data) void map_layer_surface_notify(struct wl_listener *listener, void *data) { struct client *c = wl_container_of(listener, c, map); - /* wlr_surface_send_enter(get_wlrsurface(c), c->surface.layer->output); */ - /* motion_notify(0); */ - debug_print("length of layer stack: %i\n", server.layer_visual_stack_bottom->len); + arrange_layers(c->m); } void unmap_layer_surface(struct client *c) { - /* struct container *sel_container = get_focused_container(selected_monitor); */ - /* c->surface.layer->mapped = 0; */ - /* if (get_wlrsurface(c) == server.seat->keyboard_state.focused_surface) */ - /* focus_container(sel_container, FOCUS_NOOP); */ - /* motion_notify(0); */ + struct container *con = c->con; + struct tag *tag = server_get_selected_tag(); + struct container *sel_con = tag_get_focused_container(tag); + c->surface.layer->mapped = 0; + if (con == sel_con) { + tag_this_focus_container(sel_con); + } + arrange_layers(c->m); } void unmap_layer_surface_notify(struct wl_listener *listener, void *data) { struct client *c = wl_container_of(listener, c, unmap); unmap_layer_surface(c); - container_damage_whole(c->con); arrange_layers(c->m); + container_damage_whole(c->con); } void destroy_layer_surface_notify(struct wl_listener *listener, void *data) @@ -112,7 +113,6 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) struct monitor *m = wlr_output->data; struct container *con = c->con; container_damage_part(con); - arrange_layers(m); if (c->surface.layer->current.layer != wlr_layer_surface->current.layer) { remove_in_composed_list(server.layer_visual_stack_lists, cmp_ptr, con); @@ -204,19 +204,6 @@ void arrange_layers(struct monitor *m) } } -static bool wlr_box_is_equal(struct wlr_box box1, struct wlr_box box2) -{ - if (box1.x != box2.x) - return false; - if (box1.y != box2.y) - return false; - if (box1.width != box2.width) - return false; - if (box1.height != box2.height) - return false; - return true; -} - void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_area, bool exclusive) { struct wlr_box full_area = m->geom; @@ -288,17 +275,14 @@ void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_ar wlr_layer_surface_v1_destroy(wlr_layer_surface); continue; } - - struct wlr_box prev_geom = container_get_current_geom(con); + // TODO: is that correct? container_set_current_geom(con, box); + if (state->exclusive_zone > 0) apply_exclusive(usable_area, state->anchor, state->exclusive_zone, state->margin.top, state->margin.right, state->margin.bottom, state->margin.left); - - if (!wlr_box_is_equal(prev_geom, container_get_current_geom(con))) { - wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); - } + wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); } } From 43c761405c34001e0f8d6f0fce65670b7974afe6 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 17:18:25 +0100 Subject: [PATCH 50/93] refactor: refactor stuff --- include/layer_shell.h | 6 ++ src/layer_shell.c | 242 +++++++++++++++++++++++++++++------------- 2 files changed, 173 insertions(+), 75 deletions(-) diff --git a/include/layer_shell.h b/include/layer_shell.h index aa5aa53b..226b5bbc 100644 --- a/include/layer_shell.h +++ b/include/layer_shell.h @@ -21,6 +21,12 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data); void create_notify_layer_shell(struct wl_listener *listener, void *data); void arrange_layers(struct monitor *m); void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_area, bool exclusive); +void layer_shell_arrange_container( + struct monitor *m, + struct container *con, + bool exclusive, + struct wlr_box *usable_area, + struct wlr_box full_area); void apply_exclusive(struct wlr_box *usable_area, uint32_t anchor, int32_t exclusive, int32_t margin_top, int32_t margin_right, diff --git a/src/layer_shell.c b/src/layer_shell.c index dedd7960..118fe5ae 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -52,7 +52,10 @@ void create_notify_layer_shell(struct wl_listener *listener, void *data) void map_layer_surface_notify(struct wl_listener *listener, void *data) { struct client *c = wl_container_of(listener, c, map); - arrange_layers(c->m); + struct container *con = c->con; + struct monitor *m = container_get_monitor(con); + arrange_layers(m); + printf("map\n"); } void unmap_layer_surface(struct client *c) @@ -64,7 +67,8 @@ void unmap_layer_surface(struct client *c) if (con == sel_con) { tag_this_focus_container(sel_con); } - arrange_layers(c->m); + struct monitor *m = container_get_monitor(con); + arrange_layers(m); } void unmap_layer_surface_notify(struct wl_listener *listener, void *data) @@ -110,6 +114,8 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) if (!wlr_output) return; + arrange_layers(c->m); + struct monitor *m = wlr_output->data; struct container *con = c->con; container_damage_part(con); @@ -204,85 +210,171 @@ void arrange_layers(struct monitor *m) } } +void layer_shell_arrange_exclusive_container( + struct monitor *m, + struct container *con, + bool exclusive, + struct wlr_box *usable_area, + struct wlr_box full_area) +{ + if (!tagset_visible_on(m, con)) + return; + + struct wlr_layer_surface_v1 *wlr_layer_surface = con->client->surface.layer; + struct wlr_layer_surface_v1_state *state = &wlr_layer_surface->current; + bool is_exclusive = (state->exclusive_zone > 0); + if (exclusive != is_exclusive) + return; + + const uint32_t both_horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT + | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP + | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + struct wlr_box bounds = state->exclusive_zone == -1 ? full_area : *usable_area; + struct wlr_box box = { + .width = state->desired_width, + .height = state->desired_height + }; + + // Horizontal axis + if ((state->anchor & both_horiz) && box.width == 0) { + box.x = bounds.x; + box.width = bounds.width; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { + box.x = bounds.x; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { + box.x = bounds.x + (bounds.width - box.width); + } else { + box.x = bounds.x + ((bounds.width / 2) - (box.width / 2)); + } + // Vertical axis + if ((state->anchor & both_vert) && box.height == 0) { + box.y = bounds.y; + box.height = bounds.height; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { + box.y = bounds.y; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { + box.y = bounds.y + (bounds.height - box.height); + } else { + box.y = bounds.y + ((bounds.height / 2) - (box.height / 2)); + } + // Margin + if ((state->anchor & both_horiz) == both_horiz) { + box.x += state->margin.left; + box.width -= state->margin.left + state->margin.right; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { + box.x += state->margin.left; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { + box.x -= state->margin.right; + } + if ((state->anchor & both_vert) == both_vert) { + box.y += state->margin.top; + box.height -= state->margin.top + state->margin.bottom; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { + box.y += state->margin.top; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { + box.y -= state->margin.bottom; + } + if (box.width < 0 || box.height < 0) { + wlr_layer_surface_v1_destroy(wlr_layer_surface); + return; + } + // TODO: is that correct? + container_set_current_geom(con, box); + + if (state->exclusive_zone > 0) + apply_exclusive(usable_area, state->anchor, state->exclusive_zone, + state->margin.top, state->margin.right, + state->margin.bottom, state->margin.left); + wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); +} + +void layer_shell_arrange_container( + struct monitor *m, + struct container *con, + bool exclusive, + struct wlr_box *usable_area, + struct wlr_box full_area) +{ + if (!tagset_visible_on(m, con)) + return; + + struct wlr_layer_surface_v1 *wlr_layer_surface = con->client->surface.layer; + struct wlr_layer_surface_v1_state *state = &wlr_layer_surface->current; + bool is_exclusive = (state->exclusive_zone > 0); + if (exclusive != is_exclusive) + return; + + const uint32_t both_horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT + | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP + | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + struct wlr_box bounds = state->exclusive_zone == -1 ? full_area : *usable_area; + struct wlr_box box = { + .width = state->desired_width, + .height = state->desired_height + }; + + // Horizontal axis + if ((state->anchor & both_horiz) && box.width == 0) { + box.x = bounds.x; + box.width = bounds.width; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { + box.x = bounds.x; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { + box.x = bounds.x + (bounds.width - box.width); + } else { + box.x = bounds.x + ((bounds.width / 2) - (box.width / 2)); + } + // Vertical axis + if ((state->anchor & both_vert) && box.height == 0) { + box.y = bounds.y; + box.height = bounds.height; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { + box.y = bounds.y; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { + box.y = bounds.y + (bounds.height - box.height); + } else { + box.y = bounds.y + ((bounds.height / 2) - (box.height / 2)); + } + // Margin + if ((state->anchor & both_horiz) == both_horiz) { + box.x += state->margin.left; + box.width -= state->margin.left + state->margin.right; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { + box.x += state->margin.left; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { + box.x -= state->margin.right; + } + if ((state->anchor & both_vert) == both_vert) { + box.y += state->margin.top; + box.height -= state->margin.top + state->margin.bottom; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { + box.y += state->margin.top; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { + box.y -= state->margin.bottom; + } + if (box.width < 0 || box.height < 0) { + wlr_layer_surface_v1_destroy(wlr_layer_surface); + return; + } + // TODO: is that correct? + container_set_current_geom(con, box); + + if (state->exclusive_zone > 0) + apply_exclusive(usable_area, state->anchor, state->exclusive_zone, + state->margin.top, state->margin.right, + state->margin.bottom, state->margin.left); + wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); +} + void arrangelayer(struct monitor *m, GPtrArray *array, struct wlr_box *usable_area, bool exclusive) { struct wlr_box full_area = m->geom; for (int i = 0; i < array->len; i++) { struct container *con = g_ptr_array_index(array, i); - - if (!tagset_visible_on(m, con)) - continue; - - struct wlr_layer_surface_v1 *wlr_layer_surface = con->client->surface.layer; - struct wlr_layer_surface_v1_state *state = &wlr_layer_surface->current; - struct wlr_box bounds; - struct wlr_box box = { - .width = state->desired_width, - .height = state->desired_height - }; - const uint32_t both_horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT - | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; - const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP - | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; - - bool is_exclusive = (state->exclusive_zone > 0); - if (exclusive != is_exclusive) - continue; - - bounds = state->exclusive_zone == -1 ? full_area : *usable_area; - - // Horizontal axis - if ((state->anchor & both_horiz) && box.width == 0) { - box.x = bounds.x; - box.width = bounds.width; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { - box.x = bounds.x; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { - box.x = bounds.x + (bounds.width - box.width); - } else { - box.x = bounds.x + ((bounds.width / 2) - (box.width / 2)); - } - // Vertical axis - if ((state->anchor & both_vert) && box.height == 0) { - box.y = bounds.y; - box.height = bounds.height; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { - box.y = bounds.y; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { - box.y = bounds.y + (bounds.height - box.height); - } else { - box.y = bounds.y + ((bounds.height / 2) - (box.height / 2)); - } - // Margin - if ((state->anchor & both_horiz) == both_horiz) { - box.x += state->margin.left; - box.width -= state->margin.left + state->margin.right; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { - box.x += state->margin.left; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { - box.x -= state->margin.right; - } - if ((state->anchor & both_vert) == both_vert) { - box.y += state->margin.top; - box.height -= state->margin.top + state->margin.bottom; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { - box.y += state->margin.top; - } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { - box.y -= state->margin.bottom; - } - if (box.width < 0 || box.height < 0) { - wlr_layer_surface_v1_destroy(wlr_layer_surface); - continue; - } - // TODO: is that correct? - container_set_current_geom(con, box); - - if (state->exclusive_zone > 0) - apply_exclusive(usable_area, state->anchor, state->exclusive_zone, - state->margin.top, state->margin.right, - state->margin.bottom, state->margin.left); - wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); + layer_shell_arrange_container(m, con, exclusive, usable_area, full_area); } } From da8ebff5bf373448ef1674ecc16fe9f32210484e Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 17:58:59 +0100 Subject: [PATCH 51/93] fix: fix infinit loop in layer_shell.c --- src/layer_shell.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/layer_shell.c b/src/layer_shell.c index 118fe5ae..9de09622 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -114,7 +114,10 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) if (!wlr_output) return; - arrange_layers(c->m); + struct wlr_layer_surface_v1 *layer_surface = c->surface.layer; + if (layer_surface->current.committed != 0) { + arrange_layers(c->m); + } struct monitor *m = wlr_output->data; struct container *con = c->con; From 97bf15a877468b47cb5e2dd283a26343c11a87b8 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 18:14:02 +0100 Subject: [PATCH 52/93] refactor: refactor monitor.c --- include/client.h | 3 +++ src/layer_shell.c | 21 ++++++--------------- src/monitor.c | 19 +++++++++---------- src/tagset.c | 4 ++-- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/include/client.h b/include/client.h index 0c369e65..2de609d1 100644 --- a/include/client.h +++ b/include/client.h @@ -41,6 +41,9 @@ struct client { bool resized; bool moved_tag; bool is_independent; + // this is currently only used for layer_shell surfaces to help determine if + // arrange_layers should be called + bool mapped; }; struct client *create_client(enum shell shell_type, union surface_t surface); diff --git a/src/layer_shell.c b/src/layer_shell.c index 9de09622..e4a50677 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -45,17 +45,11 @@ void create_notify_layer_shell(struct wl_listener *listener, void *data) // so that we can easily arrange it struct wlr_layer_surface_v1_state old_state = wlr_layer_surface->current; wlr_layer_surface->current = wlr_layer_surface->pending; - arrange_layers(m); wlr_layer_surface->current = old_state; } void map_layer_surface_notify(struct wl_listener *listener, void *data) { - struct client *c = wl_container_of(listener, c, map); - struct container *con = c->con; - struct monitor *m = container_get_monitor(con); - arrange_layers(m); - printf("map\n"); } void unmap_layer_surface(struct client *c) @@ -67,15 +61,12 @@ void unmap_layer_surface(struct client *c) if (con == sel_con) { tag_this_focus_container(sel_con); } - struct monitor *m = container_get_monitor(con); - arrange_layers(m); } void unmap_layer_surface_notify(struct wl_listener *listener, void *data) { struct client *c = wl_container_of(listener, c, unmap); unmap_layer_surface(c); - arrange_layers(c->m); container_damage_whole(c->con); } @@ -94,8 +85,6 @@ void destroy_layer_surface_notify(struct wl_listener *listener, void *data) wl_list_remove(&c->commit.link); if (c->surface.layer->output) { - struct monitor *m = c->surface.layer->output->data; - arrange_layers(m); c->surface.layer->output = NULL; } @@ -115,7 +104,9 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) return; struct wlr_layer_surface_v1 *layer_surface = c->surface.layer; - if (layer_surface->current.committed != 0) { + if (layer_surface->current.committed != 0 || + c->mapped != layer_surface->mapped) { + c->mapped = layer_surface->mapped; arrange_layers(c->m); } @@ -282,13 +273,13 @@ void layer_shell_arrange_exclusive_container( wlr_layer_surface_v1_destroy(wlr_layer_surface); return; } - // TODO: is that correct? - container_set_current_geom(con, box); - if (state->exclusive_zone > 0) + container_set_current_geom(con, box); + if (state->exclusive_zone > 0) { apply_exclusive(usable_area, state->anchor, state->exclusive_zone, state->margin.top, state->margin.right, state->margin.bottom, state->margin.left); + } wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); } diff --git a/src/monitor.c b/src/monitor.c index 38e8cc7f..bbbf19f4 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -187,7 +187,6 @@ static void handle_output_mode(struct wl_listener *listener, void *data) m->geom = *wlr_output_layout_get_box(server.output_layout, m->wlr_output); arrange_monitor(m); arrange_layers(m); - arrange(); } static void monitor_get_initial_tag(struct monitor *m, GList *tags) @@ -392,19 +391,18 @@ void transform_monitor(struct monitor *m, enum wl_output_transform transform) void update_monitor_geometries() { struct wlr_output_configuration_v1 *config = wlr_output_configuration_v1_create(); - + for (int i = 0; i < server.mons->len; i++) { struct monitor *m = g_ptr_array_index(server.mons, i); struct wlr_output_configuration_head_v1 *config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output); arrange_layers(m); - arrange_monitor(m); config_head->state.enabled = m->wlr_output->enabled; struct wlr_box *monitor_box = &m->geom; if (monitor_box) { config_head->state.x = monitor_box->x; config_head->state.y = monitor_box->y; - } + } } wlr_output_manager_v1_set_configuration(server.output_mgr, config); } @@ -476,8 +474,8 @@ struct wlr_box monitor_get_active_geom(struct monitor *m) void handle_output_mgr_apply(struct wl_listener *listener, void *data) { - struct wlr_output_configuration_v1 *config = data; - handle_output_mgr_apply_test(config, false); + struct wlr_output_configuration_v1 *config = data; + handle_output_mgr_apply_test(config, false); } // apply_output_config @@ -499,7 +497,7 @@ void handle_output_mgr_apply_test( void handle_output_mgr_test(struct wl_listener *listener, void *data) { - struct wlr_output_configuration_v1 *config = data; + struct wlr_output_configuration_v1 *config = data; handle_output_mgr_apply_test(config, true); } @@ -533,15 +531,16 @@ static bool output_test(struct wlr_output *wlr_output, bool output_ok, output_ok &= wlr_output_commit(wlr_output); } return output_ok; -} +} + static void check_succeed(struct wlr_output_configuration_v1 *config, bool output_ok, bool test) { if (output_ok) { wlr_output_configuration_v1_send_succeeded(config); if (!test) - update_monitor_geometries(); - }else{ + update_monitor_geometries(); + } else { wlr_output_configuration_v1_send_failed(config); } } diff --git a/src/tagset.c b/src/tagset.c index 1a43c8f7..da8ca129 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -81,7 +81,7 @@ void tagset_set_tags(struct tag *sel_tag, BitSet *tags) tag_damage(sel_tag); tagset_load_tags(sel_tag, sel_tag->tags); update_reduced_focus_stack(sel_tag); - arrange_layers(server_get_selected_monitor()); + arrange(); tag_focus_most_recent_container(sel_tag); ipc_event_tag(); @@ -319,7 +319,7 @@ void focus_tagset(struct tag *tag, BitSet *tags) ipc_event_tag(); tagset_move_sticky_containers(tag); - arrange_layers(server_get_selected_monitor()); + arrange(); tag_focus_most_recent_container(tag); root_damage_whole(m->root); From 1fd579f7c46455ccdffe9373baa1ac37c893ef25 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 18:16:29 +0100 Subject: [PATCH 53/93] refactor: further refactor monitor.c --- src/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/monitor.c b/src/monitor.c index bbbf19f4..871fac26 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -394,7 +394,8 @@ void update_monitor_geometries() for (int i = 0; i < server.mons->len; i++) { struct monitor *m = g_ptr_array_index(server.mons, i); - struct wlr_output_configuration_head_v1 *config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output); + struct wlr_output_configuration_head_v1 *config_head = + wlr_output_configuration_head_v1_create(config, m->wlr_output); arrange_layers(m); config_head->state.enabled = m->wlr_output->enabled; From 4dfa58990ac07f32848a7b1a1bb0d017ed853367 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 19:07:05 +0100 Subject: [PATCH 54/93] feat: improve performance of bitset_assign_bitset --- src/bitset/bitset.c | 16 ++++++++++++---- src/monitor.c | 8 +++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/bitset/bitset.c b/src/bitset/bitset.c index 01680ca4..7dec2ea0 100644 --- a/src/bitset/bitset.c +++ b/src/bitset/bitset.c @@ -30,7 +30,7 @@ BitSet *bitset_create_with_data(void *data) return bitset; } -static void append_bits(void *key_ptr, void *value_ptr, void *user_data) +static void assign_bits(void *key_ptr, void *value_ptr, void *user_data) { int key = *(int *)key_ptr; bool value = *(bool *)value_ptr; @@ -46,7 +46,7 @@ BitSet* bitset_copy(BitSet* source) BitSet *destination = bitset_create(); destination->bytes = g_hash_table_new_full(g_int_hash, g_int_equal, free, free); - g_hash_table_foreach(source->bytes, append_bits, destination); + g_hash_table_foreach(source->bytes, assign_bits, destination); return destination; } @@ -56,8 +56,16 @@ void bitset_assign_bitset(BitSet** dest, BitSet* source) if (*dest == source) { return; } - g_hash_table_remove_all((*dest)->bytes); - g_hash_table_foreach(source->bytes, append_bits, *dest); + g_hash_table_foreach(source->bytes, assign_bits, *dest); + BitSet *dest_ptr = *dest; + for (int i = dest_ptr->low; i < source->low; i++) { + g_hash_table_remove(dest_ptr->bytes, &i); + } + for (int i = source->high+1; i <= dest_ptr->high; i++) { + g_hash_table_remove(dest_ptr->bytes, &i); + } + dest_ptr->low = source->low; + dest_ptr->high = source->high; } void bitset_reverse(BitSet *bitset, int start, int end) diff --git a/src/monitor.c b/src/monitor.c index 871fac26..77412596 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -148,7 +148,6 @@ int i = 0; static void handle_output_frame(struct wl_listener *listener, void *data) { struct monitor *m = wl_container_of(listener, m, damage_frame); - // debug_print("frame: %i\n", i++); /* NOOP */ } @@ -185,7 +184,6 @@ static void handle_output_mode(struct wl_listener *listener, void *data) { struct monitor *m = wl_container_of(listener, m, mode); m->geom = *wlr_output_layout_get_box(server.output_layout, m->wlr_output); - arrange_monitor(m); arrange_layers(m); } @@ -489,8 +487,8 @@ void handle_output_mgr_apply_test( struct wlr_output *wlr_output = config_head->state.output; wlr_output_enable(wlr_output, config_head->state.enabled); - prepare_output(config_head, wlr_output); - output_ok = output_test(wlr_output, output_ok, test); + prepare_output(config_head, wlr_output); + output_ok = output_test(wlr_output, output_ok, test); } check_succeed(config, output_ok, test); wlr_output_configuration_v1_destroy(config); @@ -499,7 +497,7 @@ void handle_output_mgr_apply_test( void handle_output_mgr_test(struct wl_listener *listener, void *data) { struct wlr_output_configuration_v1 *config = data; - handle_output_mgr_apply_test(config, true); + handle_output_mgr_apply_test(config, true); } static void prepare_output( From 8174d4f483309bf1e87625910fcfc4348c66037f Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 19:18:42 +0100 Subject: [PATCH 55/93] chore: cleanup print statements --- src/tag.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tag.c b/src/tag.c index e3bfdd05..a89f5d7c 100644 --- a/src/tag.c +++ b/src/tag.c @@ -936,8 +936,6 @@ void tag_set_tags(struct tag *tag, BitSet *tags) void tag_set_prev_tags(struct tag *tag, struct BitSet *tags) { - printf("tag prev:"); - print_bitset(tags); bitset_assign_bitset(&tag->prev_tags, tags); } From 58a9c4d10d4ec691f1a0345d2ec7b97872f31616 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 22:09:28 +0100 Subject: [PATCH 56/93] refactor: remove dead code --- include/client.h | 9 ++++++--- include/tagset.h | 1 - src/client.c | 36 ------------------------------------ src/layer_shell.c | 18 +++++++++++------- src/tagset.c | 11 ----------- 5 files changed, 17 insertions(+), 58 deletions(-) diff --git a/include/client.h b/include/client.h index 2de609d1..21557a16 100644 --- a/include/client.h +++ b/include/client.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "bitset/bitset.h" #include "seat.h" @@ -37,6 +38,11 @@ struct client { const char *app_id; BitSet *sticky_tags; + // only use this variable if this client is a layer shell client + // represents: + // enum zwlr_layer_surface_v1_layer layer; + int layer; + // used to determine what to damage bool resized; bool moved_tag; @@ -49,9 +55,6 @@ struct client { struct client *create_client(enum shell shell_type, union surface_t surface); void destroy_client(struct client *c); -void container_move_sticky_containers_current_tag(struct container *con); -void container_move_sticky_containers(struct container *con, int tag_id); - void focus_client(struct seat *seat, struct client *old, struct client *c); void focus_surface(struct seat *seat, struct wlr_surface *surface); void client_setsticky(struct client *c, BitSet *tags); diff --git a/include/tagset.h b/include/tagset.h index fbb961a7..f6486698 100644 --- a/include/tagset.h +++ b/include/tagset.h @@ -51,7 +51,6 @@ void tagset_toggle_add(struct monitor *m, BitSet *bitset); void tagset_set_tags(struct tag *sel_tag, BitSet *tags); void tagset_focus_tags(struct tag *tag, struct BitSet *bitset); void tagset_reload(struct tag *sel_tag); -void tagset_move_sticky_containers(struct tag *tag); void tag_write_to_focus_stacks(struct tag *tag); bool is_reduced_focus_stack(struct tag *tag, struct container *con); diff --git a/src/client.c b/src/client.c index 1071cd5e..78f7dd8d 100644 --- a/src/client.c +++ b/src/client.c @@ -171,45 +171,9 @@ void focus_client(struct seat *seat, struct client *old, struct client *c) } } -void container_move_sticky_containers_current_tag(struct container *con) -{ - struct monitor *m = server_get_selected_monitor(); - struct tag *tag = monitor_get_active_tag(m); - container_move_sticky_containers(con, tag->id); -} - -void container_move_sticky_containers(struct container *con, int tag_id) -{ - // // TODO: refactor this function - // struct tag *ws = get_tag(tag_id); - // if (!bitset_test(con->client->sticky_tags, ws->id)) { - // if (bitset_any(con->client->sticky_tags)) { - // container_set_just_tag_id(con, tag_id); - // arrange(); - // focus_most_recent_container(); - // ipc_event_tag(); - // } else { - // move_to_scratchpad(con, 0); - // return; - // } - // return; - // } - // if (con->on_scratchpad) { - // return; - // } - // - // if (tag_sticky_contains_client(ws, con->client)) { - // container_set_just_tag_id(con, ws->id); - // } else if (bitset_none(con->client->sticky_tags)) { - // move_to_scratchpad(con, 0); - // } -} - void client_setsticky(struct client *c, BitSet *tags) { bitset_assign_bitset(&c->sticky_tags, tags); - struct container *con = c->con; - container_move_sticky_containers_current_tag(con); ipc_event_tag(); } diff --git a/src/layer_shell.c b/src/layer_shell.c index e4a50677..d927d982 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -96,6 +96,7 @@ void destroy_layer_surface_notify(struct wl_listener *listener, void *data) void commit_layer_surface_notify(struct wl_listener *listener, void *data) { + printf("commit layer shell\n"); struct client *c = wl_container_of(listener, c, commit); struct wlr_layer_surface_v1 *wlr_layer_surface = c->surface.layer; struct wlr_output *wlr_output = wlr_layer_surface->output; @@ -103,21 +104,23 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) if (!wlr_output) return; + struct monitor *m = wlr_output->data; + struct container *con = c->con; struct wlr_layer_surface_v1 *layer_surface = c->surface.layer; + bool layer_changed = false; if (layer_surface->current.committed != 0 || c->mapped != layer_surface->mapped) { + layer_changed = c->layer != layer_surface->current.layer; + if (layer_changed) { + remove_in_composed_list(server.layer_visual_stack_lists, cmp_ptr, con); + g_ptr_array_insert(get_layer_list(m, wlr_layer_surface->current.layer), 0, con); + } c->mapped = layer_surface->mapped; + printf("here\n"); arrange_layers(c->m); } - struct monitor *m = wlr_output->data; - struct container *con = c->con; container_damage_part(con); - - if (c->surface.layer->current.layer != wlr_layer_surface->current.layer) { - remove_in_composed_list(server.layer_visual_stack_lists, cmp_ptr, con); - g_ptr_array_insert(get_layer_list(m, wlr_layer_surface->current.layer), 0, con); - } } bool layer_shell_is_bar(struct container *con) @@ -157,6 +160,7 @@ GPtrArray *get_layer_list(struct monitor *m, enum zwlr_layer_shell_v1_layer laye void arrange_layers(struct monitor *m) { + printf("arrange layers\n"); if (!m) return; diff --git a/src/tagset.c b/src/tagset.c index da8ca129..ca027de5 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -270,16 +270,6 @@ static bool _is_visual_visible_stack( return is_visible; } -void tagset_move_sticky_containers(struct tag *tag) -{ - GPtrArray *list = list_create_filtered_sub_list(tag->con_set->tiled_containers, container_exists); - for (int i = 0; i < list->len; i++) { - struct container *con = g_ptr_array_index(list, i); - container_move_sticky_containers(con, tag->id); - } - g_ptr_array_unref(list); -} - static void restore_floating_containers(struct tag *tag) { GPtrArray *floating_list = tagset_get_floating_list_copy(tag); @@ -318,7 +308,6 @@ void focus_tagset(struct tag *tag, BitSet *tags) update_reduced_focus_stack(tag); ipc_event_tag(); - tagset_move_sticky_containers(tag); arrange(); tag_focus_most_recent_container(tag); root_damage_whole(m->root); From f2132a8eae241b20dda3362a17bd27fd63df4587 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 22:22:51 +0100 Subject: [PATCH 57/93] refactor: simplify layer_shell related functions --- include/layer_shell.h | 2 +- include/tag.h | 2 +- src/layer_shell.c | 7 +++---- src/tag.c | 21 +++++---------------- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/include/layer_shell.h b/include/layer_shell.h index 226b5bbc..6cd72ef9 100644 --- a/include/layer_shell.h +++ b/include/layer_shell.h @@ -34,6 +34,6 @@ void apply_exclusive(struct wlr_box *usable_area, bool layer_shell_is_bar(struct container *con); -GPtrArray *get_layer_list(struct monitor *m, enum zwlr_layer_shell_v1_layer layer); +GPtrArray *get_layer_list(enum zwlr_layer_shell_v1_layer layer); #endif /* LAYER_SHELL_H */ diff --git a/include/tag.h b/include/tag.h index 6ac13b33..c403b9a5 100644 --- a/include/tag.h +++ b/include/tag.h @@ -148,7 +148,7 @@ void tag_add_container_to_containers(struct tag *tag, int i, struct container *c void tag_add_container_to_focus_stack(struct tag *tag, int i, struct container *con); void remove_container_from_stack(struct tag *tag, struct container *con); void add_container_to_stack(struct tag *tag, struct container *con); -void add_container_to_layer_stack(struct tag *tag, struct container *con); +void add_container_to_layer_stack(struct container *con); void list_set_insert_container_to_focus_stack(struct focus_set *focus_set, int position, struct container *con); void tag_remove_container_from_containers_locally(struct tag *tag, struct container *con); diff --git a/src/layer_shell.c b/src/layer_shell.c index d927d982..0791b35a 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -104,7 +104,6 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) if (!wlr_output) return; - struct monitor *m = wlr_output->data; struct container *con = c->con; struct wlr_layer_surface_v1 *layer_surface = c->surface.layer; bool layer_changed = false; @@ -113,7 +112,7 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) layer_changed = c->layer != layer_surface->current.layer; if (layer_changed) { remove_in_composed_list(server.layer_visual_stack_lists, cmp_ptr, con); - g_ptr_array_insert(get_layer_list(m, wlr_layer_surface->current.layer), 0, con); + add_container_to_layer_stack(con); } c->mapped = layer_surface->mapped; printf("here\n"); @@ -138,7 +137,7 @@ bool layer_shell_is_bar(struct container *con) return is_exclusive && (is_anchord_on_one_edge || is_anchord_on_three_edges); } -GPtrArray *get_layer_list(struct monitor *m, enum zwlr_layer_shell_v1_layer layer) +GPtrArray *get_layer_list(enum zwlr_layer_shell_v1_layer layer) { GPtrArray *layer_list = NULL; switch (layer) { @@ -189,7 +188,7 @@ void arrange_layers(struct monitor *m) }; // Find topmost keyboard interactive layer, if such a layer exists for (size_t i = 0; i < LENGTH(layers_above_shell); i++) { - GPtrArray *layer_list = get_layer_list(m, layers_above_shell[i]); + GPtrArray *layer_list = get_layer_list(layers_above_shell[i]); for (int j = layer_list->len-1; j >= 0; j--) { struct container *con = g_ptr_array_index(layer_list, j); struct client *c = con->client; diff --git a/src/tag.c b/src/tag.c index a89f5d7c..f82134ef 100644 --- a/src/tag.c +++ b/src/tag.c @@ -21,6 +21,7 @@ #include "tagset.h" #include "root.h" #include "translationLayer.h" +#include "layer_shell.h" static void update_tags_id(GPtrArray *tags) { @@ -868,27 +869,15 @@ void tag_remove_container_from_visual_stack_layer(struct tag *tag, struct contai void tag_add_container_to_visual_stack_layer(struct tag *tag, struct container *con) { - add_container_to_layer_stack(tag, con); + add_container_to_layer_stack(con); } -void add_container_to_layer_stack(struct tag *tag, struct container *con) +void add_container_to_layer_stack(struct container *con) { assert(con->client->type == LAYER_SHELL); - switch (con->client->surface.layer->current.layer) { - case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND: - g_ptr_array_insert(server.layer_visual_stack_background, 0, con); - break; - case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM: - g_ptr_array_insert(server.layer_visual_stack_bottom, 0, con); - break; - case ZWLR_LAYER_SHELL_V1_LAYER_TOP: - g_ptr_array_insert(server.layer_visual_stack_top, 0, con); - break; - case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY: - g_ptr_array_insert(server.layer_visual_stack_overlay, 0, con); - break; - } + con->client->layer = con->client->surface.layer->current.layer; + g_ptr_array_insert(get_layer_list(con->client->layer), 0, con); return; } From ea1305d939f573d7a3f75f9d86272bcf889a5594 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 7 Feb 2022 22:26:19 +0100 Subject: [PATCH 58/93] refactor: remove print statements --- src/layer_shell.c | 3 --- src/lib/lib_action.c | 1 - src/lib/lib_bitset.c | 2 -- src/tag.c | 2 -- 4 files changed, 8 deletions(-) diff --git a/src/layer_shell.c b/src/layer_shell.c index 0791b35a..9005d765 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -96,7 +96,6 @@ void destroy_layer_surface_notify(struct wl_listener *listener, void *data) void commit_layer_surface_notify(struct wl_listener *listener, void *data) { - printf("commit layer shell\n"); struct client *c = wl_container_of(listener, c, commit); struct wlr_layer_surface_v1 *wlr_layer_surface = c->surface.layer; struct wlr_output *wlr_output = wlr_layer_surface->output; @@ -115,7 +114,6 @@ void commit_layer_surface_notify(struct wl_listener *listener, void *data) add_container_to_layer_stack(con); } c->mapped = layer_surface->mapped; - printf("here\n"); arrange_layers(c->m); } @@ -159,7 +157,6 @@ GPtrArray *get_layer_list(enum zwlr_layer_shell_v1_layer layer) void arrange_layers(struct monitor *m) { - printf("arrange layers\n"); if (!m) return; diff --git a/src/lib/lib_action.c b/src/lib/lib_action.c index 26a700c8..08392c66 100644 --- a/src/lib/lib_action.c +++ b/src/lib/lib_action.c @@ -402,7 +402,6 @@ int lib_toggle_tags(lua_State *L) struct monitor *m = server_get_selected_monitor(); struct tag *tag = monitor_get_active_tag(m); BitSet *prev_tags_copy = server_bitset_get_tmp_copy(tag->prev_tags); - print_bitset(prev_tags_copy); tagset_set_tags(tag, prev_tags_copy); return 0; } diff --git a/src/lib/lib_bitset.c b/src/lib/lib_bitset.c index 3e3b4dbe..6d8eb788 100644 --- a/src/lib/lib_bitset.c +++ b/src/lib/lib_bitset.c @@ -295,8 +295,6 @@ int lib_bitset_xor(lua_State *L) lua_pop(L, 1); BitSet *self = check_bitset(L, 1); - printf("current bitset:"); - print_bitset(self); call_bitset_func(L, bitset_xor, self, bitset); lua_pop(L, 1); diff --git a/src/tag.c b/src/tag.c index f82134ef..3507b5f1 100644 --- a/src/tag.c +++ b/src/tag.c @@ -497,8 +497,6 @@ BitSet *tag_get_tags(struct tag *tag) BitSet *tag_get_prev_tags(struct tag *tag) { - printf("set prev_tags:"); - print_bitset(tag->prev_tags); return tag->prev_tags; } From a0f29ee2a2e7b27e4515ad77da1519b6b3d399df Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Tue, 8 Feb 2022 01:04:35 +0100 Subject: [PATCH 59/93] fix: get_nearest_empty_tag --- src/options.c | 5 ++--- src/tag.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/options.c b/src/options.c index 9c9d5224..bf12299c 100644 --- a/src/options.c +++ b/src/options.c @@ -266,10 +266,9 @@ void load_default_keybindings(struct options *options) bind_key(options, "mod-e", Action.view(Tag.focused:get_next_empty(Direction.right))); bind_key(options, "mod-S-e", function() local con = Container.focused - if not con then - return + if con then + con.tag = Tag.get_next_empty(Tag.focused, Direction.horizontal) end - con.tag = Tag.get_next_empty(Tag.focused, Direction.horizontal) end); bind_key(options, "mod-S-space", Layout.load(server.default_layout_ring:prev())); bind_key(options, "mod-space", Layout.load(server.default_layout_ring:next())); diff --git a/src/tag.c b/src/tag.c index 3507b5f1..02bb95ec 100644 --- a/src/tag.c +++ b/src/tag.c @@ -304,7 +304,7 @@ struct tag *get_nearest_empty_tag(GList *tags, int tag_id) return initial_tag; } - int tag_count = server_get_tag_count(); + int tag_count = 8; struct tag *tag = NULL; for (int i = 0, up_counter = tag_id+1, down_counter = tag_id-1; i < tag_count; From 5d54be998ae7d5861d6abfddeb70d6bfe900656e Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Tue, 8 Feb 2022 01:17:59 +0100 Subject: [PATCH 60/93] fix: fix mod-S-E --- src/options.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/options.c b/src/options.c index bf12299c..48ddd2a3 100644 --- a/src/options.c +++ b/src/options.c @@ -264,12 +264,11 @@ void load_default_keybindings(struct options *options) bind_key(options, "mod-S-k", Action.focus_on_hidden_stack(-1)); bind_key(options, "mod-e", Action.view(Tag.focused:get_next_empty(Direction.right))); - bind_key(options, "mod-S-e", function() + bind_key(options, "mod-S-e", local con = Container.focused if con then con.tag = Tag.get_next_empty(Tag.focused, Direction.horizontal) - end - end); + end); bind_key(options, "mod-S-space", Layout.load(server.default_layout_ring:prev())); bind_key(options, "mod-space", Layout.load(server.default_layout_ring:next())); From d193f7be66ba4355d1306ff5631aaae6ad5a9776 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Tue, 8 Feb 2022 01:21:39 +0100 Subject: [PATCH 61/93] fix: fix layers not retiling if layer shell program is force quit --- src/layer_shell.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/layer_shell.c b/src/layer_shell.c index 9005d765..0cab3d2f 100644 --- a/src/layer_shell.c +++ b/src/layer_shell.c @@ -78,6 +78,8 @@ void destroy_layer_surface_notify(struct wl_listener *listener, void *data) unmap_layer_surface(c); remove_in_composed_list(server.layer_visual_stack_lists, cmp_ptr, c->con); + arrange_layers(c->m); + wl_list_remove(&c->destroy.link); wl_list_remove(&c->map.link); wl_list_remove(&c->unmap.link); From e9a008bd492ac4d592c8e51ab5a9f6a484f98252 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Tue, 8 Feb 2022 14:21:09 +0100 Subject: [PATCH 62/93] fix: fix layers not being arranged on changing tag --- src/tagset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tagset.c b/src/tagset.c index ca027de5..c4b97164 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -308,7 +308,7 @@ void focus_tagset(struct tag *tag, BitSet *tags) update_reduced_focus_stack(tag); ipc_event_tag(); - arrange(); + arrange_layers(m); tag_focus_most_recent_container(tag); root_damage_whole(m->root); From f0e175c4c2f06f97af2ce8b108da211407b8ca97 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Tue, 8 Feb 2022 14:51:20 +0100 Subject: [PATCH 63/93] fix: fix regression in bitset.c --- src/bitset/bitset.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/bitset/bitset.c b/src/bitset/bitset.c index 7dec2ea0..555d142b 100644 --- a/src/bitset/bitset.c +++ b/src/bitset/bitset.c @@ -56,16 +56,8 @@ void bitset_assign_bitset(BitSet** dest, BitSet* source) if (*dest == source) { return; } + g_hash_table_remove_all((*dest)->bytes); g_hash_table_foreach(source->bytes, assign_bits, *dest); - BitSet *dest_ptr = *dest; - for (int i = dest_ptr->low; i < source->low; i++) { - g_hash_table_remove(dest_ptr->bytes, &i); - } - for (int i = source->high+1; i <= dest_ptr->high; i++) { - g_hash_table_remove(dest_ptr->bytes, &i); - } - dest_ptr->low = source->low; - dest_ptr->high = source->high; } void bitset_reverse(BitSet *bitset, int start, int end) From 21d1531ec5fe7326bc58f008ad44eac618d3fa5e Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Tue, 8 Feb 2022 14:56:02 +0100 Subject: [PATCH 64/93] fix: fix previous tag being assigned wrongly" --- src/tagset.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/tagset.c b/src/tagset.c index c4b97164..2d1d2f8e 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -339,9 +339,6 @@ void push_tagset(struct tag *sel_tag, BitSet *tags) if (tag != sel_tag) { _set_previous_tagset(tag); } - if (tag == sel_tag) { - tag_set_prev_tags(sel_tag, sel_tag->tags); - } focus_tagset(sel_tag, tags); } From b7cb36a069838b13e1669334bd73784caef7c67b Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Tue, 8 Feb 2022 15:14:14 +0100 Subject: [PATCH 65/93] fix: fix resizing bug --- src/tagset.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tagset.c b/src/tagset.c index 2d1d2f8e..60bd68d8 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -279,6 +279,7 @@ static void restore_floating_containers(struct tag *tag) struct container *con = g_ptr_array_index(floating_list, i); struct wlr_box con_geom = container_get_current_geom(con); container_set_current_geom(con, con_geom); + container_update_size(con); } } From a55fcf1fa5283e4570b349c3725d49639df8f4c1 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 9 Feb 2022 01:24:28 +0100 Subject: [PATCH 66/93] feat: add foundations for resizing with cursor --- config/tile.lua | 69 ++++++++++++++++++++++++++++++++++++++++ include/lib/lib_action.h | 1 + src/lib/lib_action.c | 7 ++++ src/options.c | 1 + src/tagset.c | 1 - src/tile/tileUtils.c | 2 +- 6 files changed, 79 insertions(+), 2 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 05f197a5..a5436b0e 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -303,6 +303,75 @@ local function get_layout_element(layout_data_element_id, resize_data) return 0 end +-- return an array of the new directions +local function get_transform_directions(con, new_geom) + local directions = {} + -- left + directions[1] = 0 + if con[X] > new_geom[X] then + directions[1] = con[X] - new_geom[X] + end + -- right + directions[2] = 0 + if con[X] + con[WIDTH] < new_geom[X] + new_geom[WIDTH] then + directions[2] = new_geom[X] + new_geom[WIDTH] - (con[X] + con[WIDTH]) + end + -- top + directions[3] = 0 + if con[Y] > new_geom[Y] then + directions[3] = con[Y] - new_geom[Y] + end + -- bottom + directions[4] = 0 + if con[Y] + con[HEIGHT] < new_geom[Y] + new_geom[HEIGHT] then + directions[4] = new_geom[Y] + new_geom[HEIGHT] - (con[Y] + con[HEIGHT]) + end + return directions +end + +local transform_direction_get_directions(transform_direction) + local directions = 0 + if transform_direction[1] ~= 0 then + directions = directions + Direction.left + end + if transform_direction[2] ~= 0 then + directions = directions + Direction.right + end + if transform_direction[3] ~= 0 then + directions = directions + Direction.top + end + if transform_direction[4] ~= 0 then + directions = directions + Direction.bottom + end + return directions +end + +-- i: position of the element inside the layout +function Resize_container(lt, i, new_geom) + if i <= 0 then + return lt.layout_data + end + + -- resize_all() + local con = lt.layout_data[i] + local transform_directions = get_transform_directions(con, new_geom) + local directions = transform_direction_get_directions(transform_directions) + + local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) + local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) + if layout_id == 0 then + return lt.layout_data + end + + local resize_element = lt.resize_data[layout_id] + for _,id in ipairs(resize_element) do + if id <= #lt.o_layout_data then + lt.layout_data[id] = resize_all(lt.layout_data[id], i, n, direction) + end + end + return lt.layout_data +end + function Resize_main_all(lt, n, direction) local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) diff --git a/include/lib/lib_action.h b/include/lib/lib_action.h index d503a727..179a8ce8 100644 --- a/include/lib/lib_action.h +++ b/include/lib/lib_action.h @@ -25,6 +25,7 @@ int lib_swap_on_hidden_stack(lua_State *L); int lib_toggle_all_bars(lua_State *L); int lib_toggle_tags(lua_State *L); int lib_toggle_view(lua_State *L); +int lib_resize_with_cursor(lua_State *L); int lib_toggle_tag(lua_State *L); int lib_view(lua_State *L); int lib_view_or_tag(lua_State *L); diff --git a/src/lib/lib_action.c b/src/lib/lib_action.c index 08392c66..0c13e31b 100644 --- a/src/lib/lib_action.c +++ b/src/lib/lib_action.c @@ -56,6 +56,7 @@ static const struct luaL_Reg action_static_methods[] = {"toggle_tag", lib_toggle_tag}, {"view", lib_view}, {"view_or_tag", lib_view_or_tag}, + {"resize_with_cursor", lib_resize_with_cursor}, {"zoom", lib_zoom}, {NULL, NULL}, }; @@ -314,6 +315,12 @@ int lib_view_or_tag(lua_State *L) return 0; } +int lib_resize_with_cursor(lua_State *L) +{ + printf("resize with cursor\n"); + return 0; +} + int lib_toggle_view(lua_State *L) { struct monitor *m = server_get_selected_monitor(); diff --git a/src/options.c b/src/options.c index 48ddd2a3..c6f32e96 100644 --- a/src/options.c +++ b/src/options.c @@ -243,6 +243,7 @@ void load_default_keybindings(struct options *options) if con then con:focus() end); + bind_key(options, "mod-S-M2", Action.resize_with_cursor()); bind_key(options, "mod-a", Layout.focused:increase_n_master()); bind_key(options, "mod-x", Layout.focused:decrease_n_master()); diff --git a/src/tagset.c b/src/tagset.c index 60bd68d8..2d1d2f8e 100644 --- a/src/tagset.c +++ b/src/tagset.c @@ -279,7 +279,6 @@ static void restore_floating_containers(struct tag *tag) struct container *con = g_ptr_array_index(floating_list, i); struct wlr_box con_geom = container_get_current_geom(con); container_set_current_geom(con, con_geom); - container_update_size(con); } } diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index 4cec902e..fe88566b 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -45,7 +45,7 @@ void arrange() struct tag *tag = monitor_get_active_tag(m); struct layout *lt = tag_get_layout(tag); container_set_border_width(con, direction_value_uniform(lt->options->float_border_px)); - // container_update_size(con); + container_update_size(con); container_set_hidden(con, false); } From a6f75a8d8697c57b061265236dd2ab66cd8dca2b Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 10 Feb 2022 00:24:08 +0100 Subject: [PATCH 67/93] feat: add more code to get closer to resizing with cursor --- config/tile.lua | 122 ++++++++++++++++++++++++++---------- include/container.h | 3 + include/cursor.h | 3 +- src/container.c | 143 ++++++++++++++++++++++++++++++++++++++++++- src/cursor.c | 6 ++ src/lib/lib_action.c | 3 + 6 files changed, 244 insertions(+), 36 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index a5436b0e..6495e538 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -248,11 +248,81 @@ local function is_invalid(con) return false end +-- return an array of the new directions +local function get_transform_directions(con, new_geom) + local directions = {} + -- left + if con[X] > new_geom[X] then + directions[#directions] = con[X] - new_geom[X] + end + -- right + directions[2] = 0 + if con[X] + con[WIDTH] < new_geom[X] + new_geom[WIDTH] then + directions[#directions] = new_geom[X] + new_geom[WIDTH] - (con[X] + con[WIDTH]) + end + -- top + directions[3] = 0 + if con[Y] > new_geom[Y] then + directions[#directions] = con[Y] - new_geom[Y] + end + -- bottom + directions[4] = 0 + if con[Y] + con[HEIGHT] < new_geom[Y] + new_geom[HEIGHT] then + directions[#directions] = new_geom[Y] + new_geom[HEIGHT] - (con[Y] + con[HEIGHT]) + end + return directions +end + +local function geometry_to_alpha_area(geom, dir) + print("geometry to alpha_area") + print("direction", dir) + local new_geom = {} + if dir == Direction.left or dir == Direction.right then + print("horizontal") + new_geom[X] = geom[X] + new_geom[WIDTH] = geom[WIDTH] + new_geom[Y] = 0 + new_geom[HEIGHT] = 1 + elseif dir == Direction.bottom or dir == Direction.top then + print("vertical") + new_geom[X] = 0 + new_geom[WIDTH] = 1 + new_geom[Y] = geom[Y] + new_geom[HEIGHT] = geom[HEIGHT] + end + print("done") + return new_geom +end + +local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) + local old_geom = lt_data_el[i] + local transform_directions = get_transform_directions(old_geom, new_geom) + for x = 1,#transform_directions do + local dir = transform_directions[x] + + local old_alpha_area = get_alpha_area_from_container(old_geom, dir) + local new_alpha_area = geometry_to_alpha_area(new_geom, dir) + print("new_geom: ", new_geom[X], new_geom[Y], new_geom[WIDTH], new_geom[HEIGHT]) + print("new alpha area:", new_alpha_area[X], new_alpha_area[Y], new_alpha_area[WIDTH], new_alpha_area[HEIGHT]) + + local old_beta_area = get_beta_area(old_alpha_area, dir) + local new_beta_area = get_beta_area(new_alpha_area, dir) + local old_unaffected_area = get_unaffected_area(old_alpha_area, dir) + + if is_invalid(new_alpha_area) or is_invalid(new_beta_area) then + return + end + + apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new_alpha_area, old_beta_area, new_beta_area) + end +end + local function apply_resize_function(lt_data_el, i, n, directions) + local old_geom = lt_data_el[i] for x = 1,#directions do local dir = directions[x] - local old_alpha_area = get_alpha_area_from_container(lt_data_el[i], dir) + local old_alpha_area = get_alpha_area_from_container(old_geom, dir) local new_alpha_area = Move_resize(old_alpha_area, 0, n, dir) local old_beta_area = get_beta_area(old_alpha_area, dir) @@ -303,33 +373,7 @@ local function get_layout_element(layout_data_element_id, resize_data) return 0 end --- return an array of the new directions -local function get_transform_directions(con, new_geom) - local directions = {} - -- left - directions[1] = 0 - if con[X] > new_geom[X] then - directions[1] = con[X] - new_geom[X] - end - -- right - directions[2] = 0 - if con[X] + con[WIDTH] < new_geom[X] + new_geom[WIDTH] then - directions[2] = new_geom[X] + new_geom[WIDTH] - (con[X] + con[WIDTH]) - end - -- top - directions[3] = 0 - if con[Y] > new_geom[Y] then - directions[3] = con[Y] - new_geom[Y] - end - -- bottom - directions[4] = 0 - if con[Y] + con[HEIGHT] < new_geom[Y] + new_geom[HEIGHT] then - directions[4] = new_geom[Y] + new_geom[HEIGHT] - (con[Y] + con[HEIGHT]) - end - return directions -end - -local transform_direction_get_directions(transform_direction) +local function transform_direction_get_directions(transform_direction) local directions = 0 if transform_direction[1] ~= 0 then directions = directions + Direction.left @@ -347,15 +391,24 @@ local transform_direction_get_directions(transform_direction) end -- i: position of the element inside the layout -function Resize_container(lt, i, new_geom) +function Resize_container_in_layout(lt, i, new_geom) if i <= 0 then return lt.layout_data end - + -- -- resize_all() - local con = lt.layout_data[i] - local transform_directions = get_transform_directions(con, new_geom) - local directions = transform_direction_get_directions(transform_directions) + local local_layout_data = lt.layout_data[2] + local con = local_layout_data[i] + length = #lt.layout_data + + local new_lua_geom = {} + new_lua_geom[X] = new_geom.x + new_lua_geom[Y] = new_geom.y + new_lua_geom[WIDTH] = new_geom.width + new_lua_geom[HEIGHT] = new_geom.height + + local transform_directions = get_transform_directions(con, new_lua_geom) + local direction = transform_direction_get_directions(transform_directions) local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) @@ -366,9 +419,10 @@ function Resize_container(lt, i, new_geom) local resize_element = lt.resize_data[layout_id] for _,id in ipairs(resize_element) do if id <= #lt.o_layout_data then - lt.layout_data[id] = resize_all(lt.layout_data[id], i, n, direction) + apply_resize_function_with_geometry(lt.layout_data[id], i, new_lua_geom) end end + print(lt) return lt.layout_data end diff --git a/include/container.h b/include/container.h index 6f81c131..ffb0f459 100644 --- a/include/container.h +++ b/include/container.h @@ -10,6 +10,7 @@ struct monitor; struct resize_constraints; struct tag; +struct cursor; struct direction_value { int top; @@ -102,6 +103,7 @@ void container_set_hidden(struct container *con, bool b); void container_set_hidden_at_tag(struct container *con, bool b, struct tag *tag); void set_container_monitor(struct container *con, struct monitor *m); void resize_container(struct container *con, struct wlr_cursor *cursor, int dx, int dy); +void resize_container_in_layout(struct container *con, struct wlr_box geom); void move_container(struct container *con, struct wlr_cursor *cursor, int offsetx, int offsety); struct container_property *container_get_property(struct container *con); @@ -154,6 +156,7 @@ void container_set_just_tag_id(struct container *con, int tag_id); void container_set_tag_id(struct container *con, int tag_id); void container_set_tag(struct container *con, struct tag *tag); void move_container_to_tag(struct container *con, struct tag *tag); +void container_resize_with_cursor(struct cursor *cursor); struct monitor *container_get_monitor(struct container *con); diff --git a/include/cursor.h b/include/cursor.h index ff49ba56..d7a1b54c 100644 --- a/include/cursor.h +++ b/include/cursor.h @@ -11,7 +11,8 @@ struct seat_device; enum cursor_mode { CURSOR_NORMAL, CURSOR_MOVE, - CURSOR_RESIZE + CURSOR_RESIZE, + CURSOR_RESIZE_IN_LAYOUT }; struct cursor { diff --git a/src/container.c b/src/container.c index 43718739..354122e3 100644 --- a/src/container.c +++ b/src/container.c @@ -6,8 +6,9 @@ #include #include -#include "container.h" #include "client.h" +#include "container.h" +#include "cursor.h" #include "list_sets/container_stack_set.h" #include "list_sets/list_set.h" #include "popup.h" @@ -25,6 +26,9 @@ #include "rules/rule.h" #include "list_sets/focus_stack_set.h" #include "options.h" +#include "lib/lib_container.h" +#include "lib/lib_layout.h" +#include "lib/lib_geom.h" static void add_container_to_tag(struct container *con, struct tag *tag); @@ -1182,6 +1186,24 @@ void resize_container(struct container *con, struct wlr_cursor *cursor, int offs container_update_size(con); } +void resize_container_in_layout(struct container *con, struct wlr_box geom) +{ + struct tag *tag = container_get_tag(con); + struct layout *lt = tag_get_layout(tag); + + lua_getglobal(L, "Resize_container_in_layout"); + create_lua_layout(L, lt); + lua_pushinteger(L, 1); + create_lua_geometry(L, geom); + + if (lua_call_safe(L, 3, 1, 0) != LUA_OK) { + return; + } + + lua_copy_table_safe(L, <->lua_layout_copy_data_ref); + arrange(); +} + struct monitor *container_get_monitor(struct container *con) { if (!con) @@ -1360,6 +1382,125 @@ void move_container_to_tag(struct container *con, struct tag *tag) ipc_event_tag(); } +static int get_distance_squared(int x1, int y1, int x2, int y2) +{ + int dx = x1 - x2; + int dy = y1 - y2; + return dx * dx + dy * dy; +} + +static bool is_coordinate_inside_container(struct container *con, int x, int y) +{ + struct wlr_box box = container_get_current_geom(con); + return wlr_box_contains_point(&box, x, y); +} + +static int minimum_of_four(int a, int b, int c, int d) +{ + int min = a; + if (b < min) + min = b; + if (c < min) + min = c; + if (d < min) + min = d; + return min; +} + +static enum wlr_edges geometry_get_nearest_edge_from_point( + struct container *con, + int x, + int y + ) +{ + struct wlr_box left_geom = container_get_current_border_geom(con, WLR_EDGE_LEFT); + struct wlr_box right_geom = container_get_current_border_geom(con, WLR_EDGE_RIGHT); + struct wlr_box top_geom = container_get_current_border_geom(con, WLR_EDGE_TOP); + struct wlr_box bottom_geom = container_get_current_border_geom(con, WLR_EDGE_BOTTOM); + + struct wlr_box box = container_get_current_geom(con); + if (!wlr_box_contains_point(&box, x, y)) { + // this false and shouldn't happen + assert(false); + return WLR_EDGE_NONE; + } + + int left_edge_distance_squared = get_distance_squared(x, 0, left_geom.x + left_geom.width, 0); + int right_edge_distance_squared = get_distance_squared(x, 0, right_geom.x, 0); + int top_edge_distance_squared = get_distance_squared(0, y, 0, top_geom.y + top_geom.height); + int bottom_edge_distance_squared = get_distance_squared(0, y, 0, bottom_geom.y); + + int min = minimum_of_four(left_edge_distance_squared, + right_edge_distance_squared, top_edge_distance_squared, + bottom_edge_distance_squared); + + if (min == left_edge_distance_squared) { + printf("left\n"); + return WLR_EDGE_LEFT; + } else if (min == right_edge_distance_squared) { + printf("right\n"); + return WLR_EDGE_RIGHT; + } else if (min == top_edge_distance_squared) { + printf("top\n"); + return WLR_EDGE_TOP; + } else if (min == bottom_edge_distance_squared) { + printf("bottom\n"); + return WLR_EDGE_BOTTOM; + } else { + assert(false); + return WLR_EDGE_NONE; + } + // TODO: finish this + return WLR_EDGE_NONE; +} + +void container_resize_with_cursor(struct cursor *cursor) +{ + int cursor_x = cursor->wlr_cursor->x; + int cursor_y = cursor->wlr_cursor->y; + struct wlr_cursor *wlr_cursor = cursor->wlr_cursor; + struct container *con = xy_to_container(cursor_x, cursor_y); + if (!con) + return; + enum wlr_edges edge = geometry_get_nearest_edge_from_point(con, cursor_x, cursor_y); + struct wlr_box border = container_get_current_border_geom(con, edge); + wlr_cursor_warp_closest(cursor->wlr_cursor, NULL, + border.x + (double)border.width / 2, + cursor->wlr_cursor->y); + switch (edge) { + case WLR_EDGE_LEFT: + printf("left\n"); + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_mgr, + "left_side", wlr_cursor); + break; + case WLR_EDGE_RIGHT: + printf("right\n"); + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_mgr, + "right_side", wlr_cursor); + break; + case WLR_EDGE_TOP: + printf("top\n"); + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_mgr, + "top_side", wlr_cursor); + break; + case WLR_EDGE_BOTTOM: + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_mgr, + "bottom_side", wlr_cursor); + break; + default: + break; + } + cursor->cursor_mode = CURSOR_RESIZE_IN_LAYOUT; + + struct wlr_box test_geom = { + .x = 0, + .y = 0, + .width = 100, + .height = 100, + }; + resize_container_in_layout(con, test_geom); +} + bool container_is_bar(struct container *con) { switch (con->client->type) { diff --git a/src/cursor.c b/src/cursor.c index 2eaf7e77..eb10cb52 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -255,6 +255,9 @@ static bool handle_move_resize(struct cursor *cursor) resize_container(server.grab_c, wlr_cursor, 0, 0); return true; break; + case CURSOR_RESIZE_IN_LAYOUT: + printf("resize in layout: [%f,%f]\n", wlr_cursor->x, wlr_cursor->y); + break; default: break; } @@ -435,6 +438,9 @@ void handle_cursor_button(struct wl_listener *listener, void *data) if (cursor->cursor_mode == CURSOR_MOVE) { return; } + if (cursor->cursor_mode == CURSOR_RESIZE_IN_LAYOUT) { + return; + } /* If the event wasn't handled by the compositor, notify the client with * pointer focus that a button press has occurred */ diff --git a/src/lib/lib_action.c b/src/lib/lib_action.c index 0c13e31b..4c687d2d 100644 --- a/src/lib/lib_action.c +++ b/src/lib/lib_action.c @@ -318,6 +318,9 @@ int lib_view_or_tag(lua_State *L) int lib_resize_with_cursor(lua_State *L) { printf("resize with cursor\n"); + struct seat *seat = input_manager_get_default_seat(); + struct cursor *cursor = seat->cursor; + container_resize_with_cursor(cursor); return 0; } From e10d142d0cb903e453e37febba54e0d1c3f03a53 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 10 Feb 2022 01:39:20 +0100 Subject: [PATCH 68/93] improve code --- config/tile.lua | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 6495e538..bd808742 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -252,24 +252,26 @@ end local function get_transform_directions(con, new_geom) local directions = {} -- left - if con[X] > new_geom[X] then - directions[#directions] = con[X] - new_geom[X] + if new_geom[X] < con[X] then + directions[#directions+1] = Direction.left + print("left") end -- right - directions[2] = 0 - if con[X] + con[WIDTH] < new_geom[X] + new_geom[WIDTH] then - directions[#directions] = new_geom[X] + new_geom[WIDTH] - (con[X] + con[WIDTH]) + if new_geom[WIDTH] < con[WIDTH] then + directions[#directions+1] = Direction.right + print("right") end -- top - directions[3] = 0 - if con[Y] > new_geom[Y] then - directions[#directions] = con[Y] - new_geom[Y] + if new_geom[Y] < con[Y] then + directions[#directions+1] = Direction.top + print("top") end -- bottom - directions[4] = 0 - if con[Y] + con[HEIGHT] < new_geom[Y] + new_geom[HEIGHT] then - directions[#directions] = new_geom[Y] + new_geom[HEIGHT] - (con[Y] + con[HEIGHT]) + if new_geom[HEIGHT] < con[HEIGHT] then + directions[#directions+1] = Direction.bottom + print("bottom") end + print("directions len: ", #directions) return directions end @@ -297,13 +299,16 @@ end local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) local old_geom = lt_data_el[i] local transform_directions = get_transform_directions(old_geom, new_geom) + print("old_geom", old_geom[X], " ", old_geom[Y], " ", old_geom[WIDTH], " ", old_geom[HEIGHT]) + print("new_geom", new_geom[X], " ", new_geom[Y], " ", new_geom[WIDTH], " ", new_geom[HEIGHT]) + print("transform directions len: ", #transform_directions) for x = 1,#transform_directions do local dir = transform_directions[x] local old_alpha_area = get_alpha_area_from_container(old_geom, dir) local new_alpha_area = geometry_to_alpha_area(new_geom, dir) - print("new_geom: ", new_geom[X], new_geom[Y], new_geom[WIDTH], new_geom[HEIGHT]) - print("new alpha area:", new_alpha_area[X], new_alpha_area[Y], new_alpha_area[WIDTH], new_alpha_area[HEIGHT]) + print("new_geom: ", new_geom[X], " ", new_geom[Y], " ", new_geom[WIDTH], " ", new_geom[HEIGHT]) + print("new alpha area:", new_alpha_area[X], " ", new_alpha_area[Y], " ", new_alpha_area[WIDTH], " ", new_alpha_area[HEIGHT]) local old_beta_area = get_beta_area(old_alpha_area, dir) local new_beta_area = get_beta_area(new_alpha_area, dir) @@ -313,6 +318,7 @@ local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) return end + print("apply resize") apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new_alpha_area, old_beta_area, new_beta_area) end end @@ -402,10 +408,10 @@ function Resize_container_in_layout(lt, i, new_geom) length = #lt.layout_data local new_lua_geom = {} - new_lua_geom[X] = new_geom.x - new_lua_geom[Y] = new_geom.y - new_lua_geom[WIDTH] = new_geom.width - new_lua_geom[HEIGHT] = new_geom.height + new_lua_geom[X] = 0 + new_lua_geom[Y] = 0 + new_lua_geom[WIDTH] = 0.4 + new_lua_geom[HEIGHT] = 0.5 local transform_directions = get_transform_directions(con, new_lua_geom) local direction = transform_direction_get_directions(transform_directions) From 00c4f059beb4a8333a9719a4e22ebdac65332da0 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 10 Feb 2022 02:27:44 +0100 Subject: [PATCH 69/93] feat: improve resizing algorithms further --- config/tile.lua | 34 +++++++++++++--------------------- include/lib/lib_root.h | 2 +- src/lib/lib_monitor.c | 20 +++++++++++++++++--- src/lib/lib_root.c | 6 +++--- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index bd808742..d56c8c51 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -254,61 +254,46 @@ local function get_transform_directions(con, new_geom) -- left if new_geom[X] < con[X] then directions[#directions+1] = Direction.left - print("left") end -- right if new_geom[WIDTH] < con[WIDTH] then directions[#directions+1] = Direction.right - print("right") end -- top if new_geom[Y] < con[Y] then directions[#directions+1] = Direction.top - print("top") end -- bottom if new_geom[HEIGHT] < con[HEIGHT] then directions[#directions+1] = Direction.bottom - print("bottom") end - print("directions len: ", #directions) return directions end local function geometry_to_alpha_area(geom, dir) - print("geometry to alpha_area") - print("direction", dir) local new_geom = {} if dir == Direction.left or dir == Direction.right then - print("horizontal") new_geom[X] = geom[X] new_geom[WIDTH] = geom[WIDTH] new_geom[Y] = 0 new_geom[HEIGHT] = 1 elseif dir == Direction.bottom or dir == Direction.top then - print("vertical") new_geom[X] = 0 new_geom[WIDTH] = 1 new_geom[Y] = geom[Y] new_geom[HEIGHT] = geom[HEIGHT] end - print("done") return new_geom end local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) local old_geom = lt_data_el[i] local transform_directions = get_transform_directions(old_geom, new_geom) - print("old_geom", old_geom[X], " ", old_geom[Y], " ", old_geom[WIDTH], " ", old_geom[HEIGHT]) - print("new_geom", new_geom[X], " ", new_geom[Y], " ", new_geom[WIDTH], " ", new_geom[HEIGHT]) - print("transform directions len: ", #transform_directions) for x = 1,#transform_directions do local dir = transform_directions[x] local old_alpha_area = get_alpha_area_from_container(old_geom, dir) local new_alpha_area = geometry_to_alpha_area(new_geom, dir) - print("new_geom: ", new_geom[X], " ", new_geom[Y], " ", new_geom[WIDTH], " ", new_geom[HEIGHT]) - print("new alpha area:", new_alpha_area[X], " ", new_alpha_area[Y], " ", new_alpha_area[WIDTH], " ", new_alpha_area[HEIGHT]) local old_beta_area = get_beta_area(old_alpha_area, dir) local new_beta_area = get_beta_area(new_alpha_area, dir) @@ -318,7 +303,6 @@ local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) return end - print("apply resize") apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new_alpha_area, old_beta_area, new_beta_area) end end @@ -408,10 +392,19 @@ function Resize_container_in_layout(lt, i, new_geom) length = #lt.layout_data local new_lua_geom = {} - new_lua_geom[X] = 0 - new_lua_geom[Y] = 0 - new_lua_geom[WIDTH] = 0.4 - new_lua_geom[HEIGHT] = 0.5 + new_lua_geom[X] = new_geom.x + new_lua_geom[Y] = new_geom.y + new_lua_geom[WIDTH] = new_geom.width + new_lua_geom[HEIGHT] = new_geom.height + + local mon_geom = Monitor.focused.root.geom + print("mon_geom", mon_geom.x, mon_geom.y, mon_geom.width, mon_geom.height) + local mon_geom_transfered = {} + mon_geom_transfered[X] = mon_geom.x + mon_geom_transfered[Y] = mon_geom.y + mon_geom_transfered[WIDTH] = mon_geom.width + mon_geom_transfered[HEIGHT] = mon_geom.height + abs_container_to_relative(new_lua_geom, mon_geom_transfered) local transform_directions = get_transform_directions(con, new_lua_geom) local direction = transform_direction_get_directions(transform_directions) @@ -428,7 +421,6 @@ function Resize_container_in_layout(lt, i, new_geom) apply_resize_function_with_geometry(lt.layout_data[id], i, new_lua_geom) end end - print(lt) return lt.layout_data end diff --git a/include/lib/lib_root.h b/include/lib/lib_root.h index 8d1e625c..2d2220b0 100644 --- a/include/lib/lib_root.h +++ b/include/lib/lib_root.h @@ -11,8 +11,8 @@ void lua_load_root(lua_State *L); // static methods // methods -int lib_root_get_area(lua_State *L); // getters +int lib_root_get_geom(lua_State *L); // setters #endif /* LIB_ROOT_H */ diff --git a/src/lib/lib_monitor.c b/src/lib/lib_monitor.c index 18665926..883317f6 100644 --- a/src/lib/lib_monitor.c +++ b/src/lib/lib_monitor.c @@ -20,6 +20,17 @@ static const struct luaL_Reg monitor_static_methods[] = {NULL, NULL}, }; +static const struct luaL_Reg monitor_static_setter[] = +{ + {NULL, NULL}, +}; + +static const struct luaL_Reg monitor_static_getter[] = +{ + {"focused", lib_monitor_get_focused}, + {NULL, NULL}, +}; + static const struct luaL_Reg monitor_methods[] = { {NULL, NULL}, @@ -34,7 +45,6 @@ static const struct luaL_Reg monitor_setter[] = static const struct luaL_Reg monitor_getter[] = { - {"focused", lib_monitor_get_focused}, {"root", lib_monitor_get_root}, {"tag", lib_monitor_get_tag}, {NULL, NULL}, @@ -50,8 +60,11 @@ void lua_load_monitor(lua_State *L) monitor_getter, CONFIG_MONITOR); - luaL_newlib(L, monitor_static_methods); - lua_setglobal(L, "Monitor"); + create_static_accessor(L, + "Monitor", + monitor_static_methods, + monitor_static_setter, + monitor_static_getter); } struct monitor *check_monitor(lua_State *L, int narg) { @@ -68,6 +81,7 @@ static void create_lua_monitor(lua_State *L, struct monitor *m) { } // static methods +// static getter int lib_monitor_get_focused(lua_State *L) { struct monitor *m = server_get_selected_monitor(); diff --git a/src/lib/lib_root.c b/src/lib/lib_root.c index 12e2a192..6fe10b62 100644 --- a/src/lib/lib_root.c +++ b/src/lib/lib_root.c @@ -21,12 +21,12 @@ static const struct luaL_Reg root_methods[] = static const struct luaL_Reg root_setter[] = { - {"area", lib_root_get_area}, {NULL, NULL}, }; static const struct luaL_Reg root_getter[] = { + {"geom", lib_root_get_geom}, {NULL, NULL}, }; @@ -61,11 +61,11 @@ void create_lua_root(lua_State *L, struct root *root) // static methods // methods // getter -// setter -int lib_root_get_area(lua_State *L) +int lib_root_get_geom(lua_State *L) { struct root *root = check_root(L, 1); lua_pop(L, 1); create_lua_geometry(L, root->geom); return 1; } +// setter From 3bd4b146e8f81a27f8e67db7776a434a3e72386d Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 10 Feb 2022 12:15:44 +0100 Subject: [PATCH 70/93] feat: make resizing by cursor partially work --- config/tile.lua | 11 ++++---- include/container.h | 6 ++++ include/server.h | 1 + src/container.c | 68 +++++++++++++++++++++++++++++++++++++++------ src/cursor.c | 2 +- 5 files changed, 74 insertions(+), 14 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index d56c8c51..b57ae1c5 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -252,19 +252,19 @@ end local function get_transform_directions(con, new_geom) local directions = {} -- left - if new_geom[X] < con[X] then + if new_geom[X] ~= con[X] then directions[#directions+1] = Direction.left end -- right - if new_geom[WIDTH] < con[WIDTH] then + if new_geom[WIDTH] ~= con[WIDTH] then directions[#directions+1] = Direction.right end -- top - if new_geom[Y] < con[Y] then + if new_geom[Y] ~= con[Y] then directions[#directions+1] = Direction.top end -- bottom - if new_geom[HEIGHT] < con[HEIGHT] then + if new_geom[HEIGHT] ~= con[HEIGHT] then directions[#directions+1] = Direction.bottom end return directions @@ -398,7 +398,6 @@ function Resize_container_in_layout(lt, i, new_geom) new_lua_geom[HEIGHT] = new_geom.height local mon_geom = Monitor.focused.root.geom - print("mon_geom", mon_geom.x, mon_geom.y, mon_geom.width, mon_geom.height) local mon_geom_transfered = {} mon_geom_transfered[X] = mon_geom.x mon_geom_transfered[Y] = mon_geom.y @@ -421,6 +420,8 @@ function Resize_container_in_layout(lt, i, new_geom) apply_resize_function_with_geometry(lt.layout_data[id], i, new_lua_geom) end end + -- we have to add this to prevent rounding errors when resizing + local_layout_data[i] = new_lua_geom return lt.layout_data end diff --git a/include/container.h b/include/container.h index ffb0f459..2510dd3a 100644 --- a/include/container.h +++ b/include/container.h @@ -156,6 +156,12 @@ void container_set_just_tag_id(struct container *con, int tag_id); void container_set_tag_id(struct container *con, int tag_id); void container_set_tag(struct container *con, struct tag *tag); void move_container_to_tag(struct container *con, struct tag *tag); +void container_resize_in_layout( + struct container *con, + struct wlr_cursor *cursor, + int offsetx, + int offsety, + enum wlr_edges grabbed_edges); void container_resize_with_cursor(struct cursor *cursor); struct monitor *container_get_monitor(struct container *con); diff --git a/include/server.h b/include/server.h index ddedfc22..e59cdc85 100644 --- a/include/server.h +++ b/include/server.h @@ -116,6 +116,7 @@ struct server { bool prohibit_reload_config; struct container *grab_c; + enum wlr_edges grabbed_edges; #if JAPOKWM_HAS_XWAYLAND struct xwayland xwayland; struct wl_listener xwayland_ready; diff --git a/src/container.c b/src/container.c index 354122e3..689e0f25 100644 --- a/src/container.c +++ b/src/container.c @@ -1186,14 +1186,71 @@ void resize_container(struct container *con, struct wlr_cursor *cursor, int offs container_update_size(con); } +void container_resize_in_layout( + struct container *con, + struct wlr_cursor *cursor, + int offsetx, + int offsety, + enum wlr_edges grabbed_edges) +{ + if (!con) + return; + if (con->on_scratchpad) + return; + if (container_is_floating(con)) + return; + + struct wlr_box geom = container_get_current_geom(con); + + // geom.width = absolute_x_to_container_relative(geom, cursor->x - offsetx); + // geom.height = absolute_y_to_container_relative(geom, cursor->y - offsety); + int cursor_x = cursor->x - offsetx; + int cursor_y = cursor->y - offsety; + int dx = cursor_x - geom.x; + int dy = cursor_y - geom.y; + printf("prev geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); + if (grabbed_edges == WLR_EDGE_LEFT) { + printf("edge left\n"); + geom.x = cursor_x; + geom.width -= dx; + } + if (grabbed_edges == WLR_EDGE_TOP) { + printf("edge top\n"); + geom.y = cursor->y; + geom.height -= dy; + } + if (grabbed_edges == WLR_EDGE_RIGHT) { + printf("edge right\n"); + geom.width = cursor_x - geom.x; + } + if (grabbed_edges == WLR_EDGE_BOTTOM) { + printf("edge bottom\n"); + geom.height = cursor_y - geom.y; + } + + // struct wlr_box test_geom = { + // .x = 300, + // .y = 300, + // .width = 100, + // .height = 100, + // }; + + printf("new geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); + resize_container_in_layout(con, geom); + struct wlr_box res = container_get_current_geom(con); + printf("result geom: %d %d %d %d\n", res.x, res.y, res.width, res.height); +} + void resize_container_in_layout(struct container *con, struct wlr_box geom) { struct tag *tag = container_get_tag(con); struct layout *lt = tag_get_layout(tag); + int position = get_position_in_container_stack(con); + printf("position: %i\n", position); lua_getglobal(L, "Resize_container_in_layout"); create_lua_layout(L, lt); - lua_pushinteger(L, 1); + lua_pushinteger(L, c_idx_to_lua_idx(position)); create_lua_geometry(L, geom); if (lua_call_safe(L, 3, 1, 0) != LUA_OK) { @@ -1492,13 +1549,8 @@ void container_resize_with_cursor(struct cursor *cursor) } cursor->cursor_mode = CURSOR_RESIZE_IN_LAYOUT; - struct wlr_box test_geom = { - .x = 0, - .y = 0, - .width = 100, - .height = 100, - }; - resize_container_in_layout(con, test_geom); + server.grab_c = con; + server.grabbed_edges = edge; } bool container_is_bar(struct container *con) diff --git a/src/cursor.c b/src/cursor.c index eb10cb52..02c924aa 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -256,7 +256,7 @@ static bool handle_move_resize(struct cursor *cursor) return true; break; case CURSOR_RESIZE_IN_LAYOUT: - printf("resize in layout: [%f,%f]\n", wlr_cursor->x, wlr_cursor->y); + container_resize_in_layout(server.grab_c, wlr_cursor, 0, 0, server.grabbed_edges); break; default: break; From 54ab86a3590c9be918e40b6fc32cce0efbb04266 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 10 Feb 2022 12:52:22 +0100 Subject: [PATCH 71/93] fix some buggs --- config/tile.lua | 13 ++++++++++++- src/container.c | 14 ++++++++++---- src/translationLayer.c | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index b57ae1c5..9b244374 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -287,6 +287,9 @@ local function geometry_to_alpha_area(geom, dir) end local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) + if i > #lt_data_el then + return + end local old_geom = lt_data_el[i] local transform_directions = get_transform_directions(old_geom, new_geom) for x = 1,#transform_directions do @@ -382,14 +385,22 @@ end -- i: position of the element inside the layout function Resize_container_in_layout(lt, i, new_geom) + local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) + local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) + if layout_id <= 0 then + print("return") + return lt.layout_data + end if i <= 0 then return lt.layout_data end -- + print("i" .. i) -- resize_all() - local local_layout_data = lt.layout_data[2] + local local_layout_data = lt.layout_data[layout_data_element_id] local con = local_layout_data[i] length = #lt.layout_data + print("length" .. length) local new_lua_geom = {} new_lua_geom[X] = new_geom.x diff --git a/src/container.c b/src/container.c index 689e0f25..62ed5db9 100644 --- a/src/container.c +++ b/src/container.c @@ -1206,26 +1206,32 @@ void container_resize_in_layout( // geom.height = absolute_y_to_container_relative(geom, cursor->y - offsety); int cursor_x = cursor->x - offsetx; int cursor_y = cursor->y - offsety; - int dx = cursor_x - geom.x; - int dy = cursor_y - geom.y; printf("prev geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); if (grabbed_edges == WLR_EDGE_LEFT) { printf("edge left\n"); + int dx = (cursor_x) - geom.x; geom.x = cursor_x; + resize_container_in_layout(con, geom); geom.width -= dx; + resize_container_in_layout(con, geom); } if (grabbed_edges == WLR_EDGE_TOP) { printf("edge top\n"); - geom.y = cursor->y; + int dy = (cursor_y) - geom.y; + geom.y = cursor_y; + resize_container_in_layout(con, geom); geom.height -= dy; + resize_container_in_layout(con, geom); } if (grabbed_edges == WLR_EDGE_RIGHT) { printf("edge right\n"); geom.width = cursor_x - geom.x; + resize_container_in_layout(con, geom); } if (grabbed_edges == WLR_EDGE_BOTTOM) { printf("edge bottom\n"); geom.height = cursor_y - geom.y; + resize_container_in_layout(con, geom); } // struct wlr_box test_geom = { @@ -1236,7 +1242,7 @@ void container_resize_in_layout( // }; printf("new geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); - resize_container_in_layout(con, geom); + // resize_container_in_layout(con, geom); struct wlr_box res = container_get_current_geom(con); printf("result geom: %d %d %d %d\n", res.x, res.y, res.width, res.height); } diff --git a/src/translationLayer.c b/src/translationLayer.c index 01bfe9fe..23a063ea 100644 --- a/src/translationLayer.c +++ b/src/translationLayer.c @@ -241,6 +241,7 @@ static int l_print(lua_State *L) { append_string(&msg, string); } + printf("%s\n", msg); notify_msg(msg); write_line_to_error_file(msg); From b8e07d2eba99090542c1a29dec860f5ecd1a6053 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 02:01:15 +0100 Subject: [PATCH 72/93] add stuff --- config/init.lua | 2 +- config/tile.lua | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config/init.lua b/config/init.lua index 833aafba..8fbf19dc 100644 --- a/config/init.lua +++ b/config/init.lua @@ -42,7 +42,7 @@ layout:set_master_layout_data( ) -- You can define which layouts are switch to by default here -local layouts = {"three_columns", "two_pane", "monocle"} +local layouts = {"tmp", "two_pane", "monocle"} server.default_layout_ring = Ring.new(layouts) opt.default_layout = layouts[1] diff --git a/config/tile.lua b/config/tile.lua index 9b244374..2f577253 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -5,6 +5,15 @@ local Y = 2 local WIDTH = 3 local HEIGHT = 4 +function round(num, n) + local mult = 10^(n or 0) + return math.floor(num * mult + 0.5) / mult +end + +function round_2(num) + return round(num, 2) +end + -- val is between 0 and 1 and represents how far local function abs_container_to_relative(con, ref_area) con[X] = con[X] / ref_area[WIDTH] - ref_area[X] @@ -414,7 +423,10 @@ function Resize_container_in_layout(lt, i, new_geom) mon_geom_transfered[Y] = mon_geom.y mon_geom_transfered[WIDTH] = mon_geom.width mon_geom_transfered[HEIGHT] = mon_geom.height + print("mon_geom: x:" .. mon_geom.x .. " y:" .. mon_geom.y .. " width:" .. mon_geom.width .. " height:" .. mon_geom.height) + print("pref: ", (new_lua_geom[X] + new_lua_geom[WIDTH])/mon_geom.width) abs_container_to_relative(new_lua_geom, mon_geom_transfered) + print("next: ", new_lua_geom[X] + new_lua_geom[WIDTH]) local transform_directions = get_transform_directions(con, new_lua_geom) local direction = transform_direction_get_directions(transform_directions) @@ -431,8 +443,6 @@ function Resize_container_in_layout(lt, i, new_geom) apply_resize_function_with_geometry(lt.layout_data[id], i, new_lua_geom) end end - -- we have to add this to prevent rounding errors when resizing - local_layout_data[i] = new_lua_geom return lt.layout_data end From 693c35792fc5a15e97d738039272af41f1ac41b8 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 02:57:10 +0100 Subject: [PATCH 73/93] feat: add mpfr support for arbitrary precise numbers --- .gitignore | 1 + include/lib/lib_gmp.h | 14 +++++++ include/translationLayer.h | 1 + meson.build | 1 + src/lib/lib_gmp.c | 76 ++++++++++++++++++++++++++++++++++++++ src/meson.build | 1 + src/translationLayer.c | 2 + 7 files changed, 96 insertions(+) create mode 100644 include/lib/lib_gmp.h create mode 100644 src/lib/lib_gmp.c diff --git a/.gitignore b/.gitignore index e52a8a95..f6a5baf6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build/** *-protocol.h .ccls-cache .vimspector.json +callgrind.* tags *.pdf vscjlsymserv-* diff --git a/include/lib/lib_gmp.h b/include/lib/lib_gmp.h new file mode 100644 index 00000000..59544f04 --- /dev/null +++ b/include/lib/lib_gmp.h @@ -0,0 +1,14 @@ +#ifndef LIB_GMP_H +#define LIB_GMP_H + +#include +#include + +#include + +void lua_load_gmp(lua_State *L); +int lib_gmp_new(lua_State *L); + +struct color check_gmp(lua_State *L, int narg); + +#endif diff --git a/include/translationLayer.h b/include/translationLayer.h index 8c3e0c47..09f35ba0 100644 --- a/include/translationLayer.h +++ b/include/translationLayer.h @@ -82,6 +82,7 @@ struct layout; #define CONFIG_EVENT "japokwm.event" #define CONFIG_FOCUS_SET "japokwm.focus_set" #define CONFIG_GEOMETRY "japokwm.geometry" +#define CONFIG_GMP "japokwm.gmp" #define CONFIG_INFO "japokwm.info" #define CONFIG_LAYOUT "japokwm.layout" #define CONFIG_LIST "japokwm.list" diff --git a/meson.build b/meson.build index 5ddad56b..162ded77 100644 --- a/meson.build +++ b/meson.build @@ -170,6 +170,7 @@ deps = [\ dependency('threads'), dependency('libinput'), dependency('libuv'), + dependency('mpfr'), ] # meson.add_install_script('install.sh') diff --git a/src/lib/lib_gmp.c b/src/lib/lib_gmp.c new file mode 100644 index 00000000..ce75aeff --- /dev/null +++ b/src/lib/lib_gmp.c @@ -0,0 +1,76 @@ +#include "lib/lib_gmp.h" + +#include "translationLayer.h" + +static const struct luaL_Reg gmp_meta[] = +{ + {NULL, NULL}, +}; + +static const struct luaL_Reg gmp_static_methods[] = +{ + {"new", lib_gmp_new}, + {NULL, NULL}, +}; + +static const struct luaL_Reg gmp_static_setter[] = +{ + {NULL, NULL}, +}; + +static const struct luaL_Reg gmp_static_getter[] = +{ + {NULL, NULL}, +}; + +static const struct luaL_Reg gmp_methods[] = +{ + {NULL, NULL}, +}; + +static const struct luaL_Reg gmp_setter[] = +{ + {NULL, NULL}, +}; + +static const struct luaL_Reg gmp_getter[] = +{ + {NULL, NULL}, +}; + +void lua_load_gmp(lua_State *L) +{ + create_class(L, + gmp_meta, + gmp_static_methods, + gmp_methods, + gmp_setter, + gmp_getter, + CONFIG_GMP); + + create_static_accessor(L, + "Gmp", + gmp_static_methods, + gmp_static_setter, + gmp_static_getter); +} + +static void create_lua_gmp(lua_State *L, mpz_t *gmp) +{ + lua_newtable(L); + lua_pushlightuserdata(L, gmp); + lua_setfield(L, -2, "__gmp"); +} + +int lib_gmp_new(lua_State *L) +{ + mpz_t *mpz = lua_newuserdata(L, sizeof(mpz_t)); + mpz_init(*mpz); + + luaL_getmetatable(L, CONFIG_GMP); + lua_setmetatable(L, -2); + + return 1; +} + +struct color check_gmp(lua_State *L, int narg); diff --git a/src/meson.build b/src/meson.build index d489e0f7..c78d21a0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -48,6 +48,7 @@ srcs = files( 'lib/lib_action.c', 'lib/lib_bitset.c', 'lib/lib_color.c', + 'lib/lib_gmp.c', 'lib/lib_container.c', 'lib/lib_cursor.c', 'lib/lib_cursor_mode.c', diff --git a/src/translationLayer.c b/src/translationLayer.c index 23a063ea..d28a6818 100644 --- a/src/translationLayer.c +++ b/src/translationLayer.c @@ -18,6 +18,7 @@ #include "lib/lib_event_handler.h" #include "lib/lib_focus_set.h" #include "lib/lib_geom.h" +#include "lib/lib_gmp.h" #include "lib/lib_info.h" #include "lib/lib_layout.h" #include "lib/lib_list.h" @@ -274,6 +275,7 @@ void load_lua_api(lua_State *L) lua_load_events(L); lua_load_focus_set(L); lua_load_geom(L); + lua_load_gmp(L); lua_load_info(L); lua_load_layout(L); lua_load_list(L); From f7fe608a0d55a393ce59612b593bb043c6b706ea Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 03:27:19 +0100 Subject: [PATCH 74/93] feat: add lib_gmp --- include/lib/lib_gmp.h | 6 +++++- src/lib/lib_gmp.c | 48 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/lib/lib_gmp.h b/include/lib/lib_gmp.h index 59544f04..964525b7 100644 --- a/include/lib/lib_gmp.h +++ b/include/lib/lib_gmp.h @@ -9,6 +9,10 @@ void lua_load_gmp(lua_State *L); int lib_gmp_new(lua_State *L); -struct color check_gmp(lua_State *L, int narg); +// meta +int lib_gmp_gc(lua_State *L); +int lib_gmp_tostring(lua_State *L); + +mpfr_ptr check_gmp(lua_State *L, int argn); #endif diff --git a/src/lib/lib_gmp.c b/src/lib/lib_gmp.c index ce75aeff..6766e559 100644 --- a/src/lib/lib_gmp.c +++ b/src/lib/lib_gmp.c @@ -4,6 +4,8 @@ static const struct luaL_Reg gmp_meta[] = { + {"__gc", lib_gmp_gc}, + {"__tostring", lib_gmp_tostring}, {NULL, NULL}, }; @@ -55,22 +57,50 @@ void lua_load_gmp(lua_State *L) gmp_static_getter); } -static void create_lua_gmp(lua_State *L, mpz_t *gmp) +mpfr_ptr check_gmp(lua_State *L, int argn) { - lua_newtable(L); - lua_pushlightuserdata(L, gmp); - lua_setfield(L, -2, "__gmp"); + void *ud = luaL_checkudata(L, argn, CONFIG_GMP); + luaL_argcheck(L, ud != NULL, argn, "`mpfr' expected"); + return (mpfr_ptr)ud; +} + +static void create_lua_gmp(lua_State *L, mpfr_t num) +{ + mpfr_ptr mpfr = (mpfr_ptr)lua_newuserdata(L, sizeof(mpfr_t)); + mpfr_init2(mpfr, mpfr_get_prec(num)); + mpfr_set(mpfr, num, GMP_RNDN); + + luaL_setmetatable(L, CONFIG_GMP); +} + +// meta +int lib_gmp_gc(lua_State *L) +{ + mpfr_ptr n = check_gmp(L, 1); + mpfr_clear(n); + return 0; +} + +int lib_gmp_tostring(lua_State *L) +{ + mpfr_ptr n = check_gmp(L, 1); + char data[255]; + mpfr_snprintf(data, 255, "%.*Rf", 10, n); + lua_pushstring(L, data); + return 1; } int lib_gmp_new(lua_State *L) { - mpz_t *mpz = lua_newuserdata(L, sizeof(mpz_t)); - mpz_init(*mpz); + double n = luaL_checknumber(L, 1); + lua_pop(L, 1); - luaL_getmetatable(L, CONFIG_GMP); - lua_setmetatable(L, -2); + mpfr_t num; + mpfr_init(num); + mpfr_set_d(num, n, GMP_RNDN); + create_lua_gmp(L, num); return 1; } -struct color check_gmp(lua_State *L, int narg); + From 73fa3a689965508dbb780ae480e0505beb3f8835 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 03:38:35 +0100 Subject: [PATCH 75/93] feat: improve gmp incorperation --- include/lib/lib_gmp.h | 5 ++++ src/lib/lib_gmp.c | 68 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/include/lib/lib_gmp.h b/include/lib/lib_gmp.h index 964525b7..e11eca5f 100644 --- a/include/lib/lib_gmp.h +++ b/include/lib/lib_gmp.h @@ -12,6 +12,11 @@ int lib_gmp_new(lua_State *L); // meta int lib_gmp_gc(lua_State *L); int lib_gmp_tostring(lua_State *L); +int lib_gmp_add(lua_State *L); +int lib_gmp_sub(lua_State *L); +int lib_gmp_mul(lua_State *L); +int lib_gmp_div(lua_State *L); +int lib_gmp_pow(lua_State *L); mpfr_ptr check_gmp(lua_State *L, int argn); diff --git a/src/lib/lib_gmp.c b/src/lib/lib_gmp.c index 6766e559..82b7cf6c 100644 --- a/src/lib/lib_gmp.c +++ b/src/lib/lib_gmp.c @@ -6,6 +6,11 @@ static const struct luaL_Reg gmp_meta[] = { {"__gc", lib_gmp_gc}, {"__tostring", lib_gmp_tostring}, + {"__add", lib_gmp_add}, + {"__sub", lib_gmp_sub}, + {"__mul", lib_gmp_mul}, + {"__div", lib_gmp_div}, + {"__pow", lib_gmp_pow}, {NULL, NULL}, }; @@ -90,6 +95,67 @@ int lib_gmp_tostring(lua_State *L) return 1; } +int lib_gmp_add(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + mpfr_t n3; + mpfr_init(n3); + mpfr_add(n3, n1, n2, GMP_RNDN); + create_lua_gmp(L, n3); + + return 1; +} + +int lib_gmp_sub(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + mpfr_t n3; + mpfr_init(n3); + mpfr_sub(n3, n1, n2, GMP_RNDN); + create_lua_gmp(L, n3); + return 1; +} + +int lib_gmp_mul(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + mpfr_t n3; + mpfr_init(n3); + mpfr_mul(n3, n1, n2, GMP_RNDN); + create_lua_gmp(L, n3); + return 1; +} + +int lib_gmp_div(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + mpfr_t n3; + mpfr_init(n3); + mpfr_div(n3, n1, n2, GMP_RNDN); + create_lua_gmp(L, n3); + return 1; +} + +int lib_gmp_pow(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + mpfr_t n3; + mpfr_init(n3); + mpfr_pow(n3, n1, n2, GMP_RNDN); + create_lua_gmp(L, n3); + return 1; +} + int lib_gmp_new(lua_State *L) { double n = luaL_checknumber(L, 1); @@ -102,5 +168,3 @@ int lib_gmp_new(lua_State *L) return 1; } - - From 37acb7305e0715bed6afd7761cae89a9e49e58a4 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 03:45:43 +0100 Subject: [PATCH 76/93] feat: add leq and lt --- config/tile.lua | 31 +++++++++++-------------------- include/lib/lib_gmp.h | 2 ++ src/lib/lib_gmp.c | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 2f577253..76ec6d9c 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -39,8 +39,8 @@ local function create_container(x, y, width, height) end local function get_area_at_zero(area) - local x = 0 - local y = 0 + local x = Gmp.new(0) + local y = Gmp.new(0) local width = area[WIDTH] local height = area[HEIGHT] local con = create_container(x, y, width, height) @@ -412,31 +412,22 @@ function Resize_container_in_layout(lt, i, new_geom) print("length" .. length) local new_lua_geom = {} - new_lua_geom[X] = new_geom.x - new_lua_geom[Y] = new_geom.y - new_lua_geom[WIDTH] = new_geom.width - new_lua_geom[HEIGHT] = new_geom.height + new_lua_geom[X] = Gmp.new(new_geom.x) + new_lua_geom[Y] = Gmp.new(new_geom.y) + new_lua_geom[WIDTH] = Gmp.new(new_geom.width) + new_lua_geom[HEIGHT] = Gmp.new(new_geom.height) local mon_geom = Monitor.focused.root.geom local mon_geom_transfered = {} - mon_geom_transfered[X] = mon_geom.x - mon_geom_transfered[Y] = mon_geom.y - mon_geom_transfered[WIDTH] = mon_geom.width - mon_geom_transfered[HEIGHT] = mon_geom.height + mon_geom_transfered[X] = Gmp.new(mon_geom.x) + mon_geom_transfered[Y] = Gmp.new(mon_geom.y) + mon_geom_transfered[WIDTH] = Gmp.new(mon_geom.width) + mon_geom_transfered[HEIGHT] = Gmp.new(mon_geom.height) print("mon_geom: x:" .. mon_geom.x .. " y:" .. mon_geom.y .. " width:" .. mon_geom.width .. " height:" .. mon_geom.height) - print("pref: ", (new_lua_geom[X] + new_lua_geom[WIDTH])/mon_geom.width) + print("pref: ", (new_lua_geom[X] + new_lua_geom[WIDTH])/mon_geom_transfered[WIDTH]) abs_container_to_relative(new_lua_geom, mon_geom_transfered) print("next: ", new_lua_geom[X] + new_lua_geom[WIDTH]) - local transform_directions = get_transform_directions(con, new_lua_geom) - local direction = transform_direction_get_directions(transform_directions) - - local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) - local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) - if layout_id == 0 then - return lt.layout_data - end - local resize_element = lt.resize_data[layout_id] for _,id in ipairs(resize_element) do if id <= #lt.o_layout_data then diff --git a/include/lib/lib_gmp.h b/include/lib/lib_gmp.h index e11eca5f..b50dd5b0 100644 --- a/include/lib/lib_gmp.h +++ b/include/lib/lib_gmp.h @@ -17,6 +17,8 @@ int lib_gmp_sub(lua_State *L); int lib_gmp_mul(lua_State *L); int lib_gmp_div(lua_State *L); int lib_gmp_pow(lua_State *L); +int lib_gmp_lt(lua_State *L); +int lib_gmp_le(lua_State *L); mpfr_ptr check_gmp(lua_State *L, int argn); diff --git a/src/lib/lib_gmp.c b/src/lib/lib_gmp.c index 82b7cf6c..80c95708 100644 --- a/src/lib/lib_gmp.c +++ b/src/lib/lib_gmp.c @@ -11,6 +11,8 @@ static const struct luaL_Reg gmp_meta[] = {"__mul", lib_gmp_mul}, {"__div", lib_gmp_div}, {"__pow", lib_gmp_pow}, + {"__lt", lib_gmp_lt}, + {"__le", lib_gmp_le}, {NULL, NULL}, }; @@ -156,6 +158,24 @@ int lib_gmp_pow(lua_State *L) return 1; } +int lib_gmp_lt(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + lua_pushboolean(L, mpfr_less_p(n1, n2)); + return 1; +} + +int lib_gmp_le(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + lua_pushboolean(L, mpfr_lessequal_p(n1, n2)); + return 1; +} + int lib_gmp_new(lua_State *L) { double n = luaL_checknumber(L, 1); From baccc6f3b98c5ee6a90186f32c38fc76d8c883ee Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 04:13:07 +0100 Subject: [PATCH 77/93] feat: implement gmp --- config/tile.lua | 106 ++++++++++++++++++------------------------ include/lib/lib_gmp.h | 9 +++- src/lib/lib_gmp.c | 36 ++++++++++++++ 3 files changed, 90 insertions(+), 61 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 76ec6d9c..a9092745 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -90,10 +90,10 @@ local function merge_boxes(box1, box2) if (box2 == nil) then return Action.deep_copy(box1) end - local x1 = math.min(box1[X], box2[X]) - local y1 = math.min(box1[Y], box2[Y]) - local x2 = math.max(box1[X] + box1[WIDTH], box2[X] + box2[WIDTH]) - local y2 = math.max(box1[Y] + box1[HEIGHT], box2[Y] + box2[HEIGHT]) + local x1 = Gmp.min(box1[X], box2[X]) + local y1 = Gmp.min(box1[Y], box2[Y]) + local x2 = Gmp.max(box1[X] + box1[WIDTH], box2[X] + box2[WIDTH]) + local y2 = Gmp.max(box1[Y] + box1[HEIGHT], box2[Y] + box2[HEIGHT]) local con = create_container(x1, y1, x2 - x1, y2 - y1) return con @@ -106,16 +106,16 @@ local function join_containers(con1, con2, con3) end local function intersection_of(con1, con2) - local x1 = math.max(con1[X], con2[X]) - local y1 = math.max(con1[Y], con2[Y]) - local x2 = math.min(con1[X] + con1[WIDTH], con2[X] + con2[WIDTH]) - local y2 = math.min(con1[Y] + con1[HEIGHT], con2[Y] + con2[HEIGHT]) + local x1 = Gmp.max(con1[X], con2[X]) + local y1 = Gmp.max(con1[Y], con2[Y]) + local x2 = Gmp.min(con1[X] + con1[WIDTH], con2[X] + con2[WIDTH]) + local y2 = Gmp.min(con1[Y] + con1[HEIGHT], con2[Y] + con2[HEIGHT]) local con = create_container(x1, y1, x2 - x1, y2 - y1) - if (con[WIDTH] <= 0) then + if (con[WIDTH] <= Gmp.new(0)) then return nil end - if (con[HEIGHT] <= 0) then + if (con[HEIGHT] <= Gmp.new(0)) then return nil end return con @@ -128,11 +128,19 @@ local function split_container(con, unaffected_area, old_alpha_area, old_beta_ar return non_affected_con, alpha_con, beta_con end +local function create_gmp_container(con) + local new_con = {} + new_con[X] = Gmp.new(con[X]) + new_con[Y] = Gmp.new(con[Y]) + new_con[WIDTH] = Gmp.new(con[WIDTH]) + new_con[HEIGHT] = Gmp.new(con[HEIGHT]) + return new_con +end + local function apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new_alpha_area, old_beta_area, new_beta_area) -- local i = 5 for i = 1,#lt_data_el do - local con = lt_data_el[i]; - + local con = create_gmp_container(lt_data_el[i]); local unaffected_con, alpha_con, beta_con = split_container(con, old_unaffected_area, old_alpha_area, old_beta_area); if (alpha_con ~= nil) then @@ -142,42 +150,47 @@ local function apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new change_base(beta_con, old_beta_area, new_beta_area) end - lt_data_el[i] = join_containers(unaffected_con, alpha_con, beta_con) + local new_con = join_containers(unaffected_con, alpha_con, beta_con) + local lt_con = lt_data_el[i] + lt_con[X] = new_con[X].value + lt_con[Y] = new_con[Y].value + lt_con[WIDTH] = new_con[WIDTH].value + lt_con[HEIGHT] = new_con[HEIGHT].value end end local function get_cissor_container_left(alpha_area) - local x1 = 0 - local y1 = 0 + local x1 = Gmp.new(0) + local y1 = Gmp.new(0) local x2 = alpha_area[X] - local y2 = 1 + local y2 = Gmp.new(1) local con = create_container(x1, y1, x2-x1, y2-y1) return con end local function get_cissor_container_top(alpha_area) - local x1 = 0 - local y1 = 0 - local x2 = 1 + local x1 = Gmp.new(0) + local y1 = Gmp.new(0) + local x2 = Gmp.new(1) local y2 = alpha_area[Y] local con = create_container(x1, y1, x2-x1, y2-y1) return con end local function get_cissor_container_bottom(alpha_area) - local x1 = 0 + local x1 = Gmp.new(0) local y1 = alpha_area[Y] + alpha_area[HEIGHT] - local x2 = 1 - local y2 = 1 + local x2 = Gmp.new(1) + local y2 = Gmp.new(1) local con = create_container(x1, y1, x2-x1, y2-y1) return con end local function get_cissor_container_right(alpha_area) local x1 = alpha_area[X] + alpha_area[WIDTH] - local y1 = 0 - local x2 = 1 - local y2 = 1 + local y1 = Gmp.new(0) + local x2 = Gmp.new(1) + local y2 = Gmp.new(1) local con = create_container(x1, y1, x2-x1, y2-y1) return con end @@ -221,17 +234,17 @@ end local function get_alpha_container_horizontal(con) local x1 = con[X] - local y1 = 0 + local y1 = Gmp.new(0) local x2 = con[X] + con[WIDTH] - local y2 = 1 + local y2 = Gmp.new(1) local area = create_container(x1, y1, x2-x1, y2-y1) return area end local function get_alpha_container_vertical(con) - local x1 = 0 + local x1 = Gmp.new(0) local y1 = con[Y] - local x2 = 1 + local x2 = Gmp.new(1) local y2 = con[Y] + con[HEIGHT] local area = create_container(x1, y1, x2-x1, y2-y1) return area @@ -248,10 +261,10 @@ local function get_alpha_area_from_container(con, dir) end local function is_invalid(con) - if con[WIDTH] < 0 then + if con[WIDTH] < Gmp.new(0) then return true end - if con[HEIGHT] < 0 then + if con[HEIGHT] < Gmp.new(0) then return true end return false @@ -279,33 +292,17 @@ local function get_transform_directions(con, new_geom) return directions end -local function geometry_to_alpha_area(geom, dir) - local new_geom = {} - if dir == Direction.left or dir == Direction.right then - new_geom[X] = geom[X] - new_geom[WIDTH] = geom[WIDTH] - new_geom[Y] = 0 - new_geom[HEIGHT] = 1 - elseif dir == Direction.bottom or dir == Direction.top then - new_geom[X] = 0 - new_geom[WIDTH] = 1 - new_geom[Y] = geom[Y] - new_geom[HEIGHT] = geom[HEIGHT] - end - return new_geom -end - local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) if i > #lt_data_el then return end - local old_geom = lt_data_el[i] + local old_geom = create_gmp_container(lt_data_el[i]) local transform_directions = get_transform_directions(old_geom, new_geom) for x = 1,#transform_directions do local dir = transform_directions[x] local old_alpha_area = get_alpha_area_from_container(old_geom, dir) - local new_alpha_area = geometry_to_alpha_area(new_geom, dir) + local new_alpha_area = get_alpha_area_from_container(new_geom, dir) local old_beta_area = get_beta_area(old_alpha_area, dir) local new_beta_area = get_beta_area(new_alpha_area, dir) @@ -397,19 +394,11 @@ function Resize_container_in_layout(lt, i, new_geom) local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) if layout_id <= 0 then - print("return") return lt.layout_data end if i <= 0 then return lt.layout_data end - -- - print("i" .. i) - -- resize_all() - local local_layout_data = lt.layout_data[layout_data_element_id] - local con = local_layout_data[i] - length = #lt.layout_data - print("length" .. length) local new_lua_geom = {} new_lua_geom[X] = Gmp.new(new_geom.x) @@ -423,10 +412,7 @@ function Resize_container_in_layout(lt, i, new_geom) mon_geom_transfered[Y] = Gmp.new(mon_geom.y) mon_geom_transfered[WIDTH] = Gmp.new(mon_geom.width) mon_geom_transfered[HEIGHT] = Gmp.new(mon_geom.height) - print("mon_geom: x:" .. mon_geom.x .. " y:" .. mon_geom.y .. " width:" .. mon_geom.width .. " height:" .. mon_geom.height) - print("pref: ", (new_lua_geom[X] + new_lua_geom[WIDTH])/mon_geom_transfered[WIDTH]) abs_container_to_relative(new_lua_geom, mon_geom_transfered) - print("next: ", new_lua_geom[X] + new_lua_geom[WIDTH]) local resize_element = lt.resize_data[layout_id] for _,id in ipairs(resize_element) do diff --git a/include/lib/lib_gmp.h b/include/lib/lib_gmp.h index b50dd5b0..8f453acf 100644 --- a/include/lib/lib_gmp.h +++ b/include/lib/lib_gmp.h @@ -7,7 +7,6 @@ #include void lua_load_gmp(lua_State *L); -int lib_gmp_new(lua_State *L); // meta int lib_gmp_gc(lua_State *L); @@ -22,4 +21,12 @@ int lib_gmp_le(lua_State *L); mpfr_ptr check_gmp(lua_State *L, int argn); +// static methods +int lib_gmp_new(lua_State *L); +int lib_gmp_max(lua_State *L); +int lib_gmp_min(lua_State *L); +// getter +int lib_gmp_get_value(lua_State *L); + + #endif diff --git a/src/lib/lib_gmp.c b/src/lib/lib_gmp.c index 80c95708..4b84a7e1 100644 --- a/src/lib/lib_gmp.c +++ b/src/lib/lib_gmp.c @@ -19,6 +19,8 @@ static const struct luaL_Reg gmp_meta[] = static const struct luaL_Reg gmp_static_methods[] = { {"new", lib_gmp_new}, + {"max", lib_gmp_max}, + {"min", lib_gmp_min}, {NULL, NULL}, }; @@ -44,6 +46,7 @@ static const struct luaL_Reg gmp_setter[] = static const struct luaL_Reg gmp_getter[] = { + {"value", lib_gmp_get_value}, {NULL, NULL}, }; @@ -176,6 +179,7 @@ int lib_gmp_le(lua_State *L) return 1; } +// static methods int lib_gmp_new(lua_State *L) { double n = luaL_checknumber(L, 1); @@ -188,3 +192,35 @@ int lib_gmp_new(lua_State *L) return 1; } + +int lib_gmp_max(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + mpfr_t n3; + mpfr_init(n3); + mpfr_max(n3, n1, n2, GMP_RNDN); + create_lua_gmp(L, n3); + return 1; +} + +int lib_gmp_min(lua_State *L) +{ + mpfr_ptr n1 = check_gmp(L, 1); + mpfr_ptr n2 = check_gmp(L, 2); + + mpfr_t n3; + mpfr_init(n3); + mpfr_min(n3, n1, n2, GMP_RNDN); + create_lua_gmp(L, n3); + return 1; +} + +// getter +int lib_gmp_get_value(lua_State *L) +{ + mpfr_ptr n = check_gmp(L, 1); + lua_pushnumber(L, mpfr_get_d(n, GMP_RNDN)); + return 1; +} From 2ed4f0494a46df72026978180e5d03615f6334cc Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 04:31:40 +0100 Subject: [PATCH 78/93] feat: add rounding method --- config/tile.lua | 2 ++ src/lib/lib_gmp.c | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index a9092745..9aa0b9af 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -412,7 +412,9 @@ function Resize_container_in_layout(lt, i, new_geom) mon_geom_transfered[Y] = Gmp.new(mon_geom.y) mon_geom_transfered[WIDTH] = Gmp.new(mon_geom.width) mon_geom_transfered[HEIGHT] = Gmp.new(mon_geom.height) + print("prev: ", (new_lua_geom[X]+new_lua_geom[WIDTH])/mon_geom_transfered[WIDTH]) abs_container_to_relative(new_lua_geom, mon_geom_transfered) + print("new: ", new_lua_geom[X]+new_lua_geom[WIDTH]) local resize_element = lt.resize_data[layout_id] for _,id in ipairs(resize_element) do diff --git a/src/lib/lib_gmp.c b/src/lib/lib_gmp.c index 4b84a7e1..c58451b2 100644 --- a/src/lib/lib_gmp.c +++ b/src/lib/lib_gmp.c @@ -2,6 +2,8 @@ #include "translationLayer.h" +#define ROUNDING_METHOD MPFR_RNDN + static const struct luaL_Reg gmp_meta[] = { {"__gc", lib_gmp_gc}, @@ -78,7 +80,7 @@ static void create_lua_gmp(lua_State *L, mpfr_t num) { mpfr_ptr mpfr = (mpfr_ptr)lua_newuserdata(L, sizeof(mpfr_t)); mpfr_init2(mpfr, mpfr_get_prec(num)); - mpfr_set(mpfr, num, GMP_RNDN); + mpfr_set(mpfr, num, ROUNDING_METHOD); luaL_setmetatable(L, CONFIG_GMP); } @@ -107,7 +109,7 @@ int lib_gmp_add(lua_State *L) mpfr_t n3; mpfr_init(n3); - mpfr_add(n3, n1, n2, GMP_RNDN); + mpfr_add(n3, n1, n2, ROUNDING_METHOD); create_lua_gmp(L, n3); return 1; @@ -120,7 +122,7 @@ int lib_gmp_sub(lua_State *L) mpfr_t n3; mpfr_init(n3); - mpfr_sub(n3, n1, n2, GMP_RNDN); + mpfr_sub(n3, n1, n2, ROUNDING_METHOD); create_lua_gmp(L, n3); return 1; } @@ -132,7 +134,7 @@ int lib_gmp_mul(lua_State *L) mpfr_t n3; mpfr_init(n3); - mpfr_mul(n3, n1, n2, GMP_RNDN); + mpfr_mul(n3, n1, n2, ROUNDING_METHOD); create_lua_gmp(L, n3); return 1; } @@ -144,7 +146,7 @@ int lib_gmp_div(lua_State *L) mpfr_t n3; mpfr_init(n3); - mpfr_div(n3, n1, n2, GMP_RNDN); + mpfr_div(n3, n1, n2, ROUNDING_METHOD); create_lua_gmp(L, n3); return 1; } @@ -156,7 +158,7 @@ int lib_gmp_pow(lua_State *L) mpfr_t n3; mpfr_init(n3); - mpfr_pow(n3, n1, n2, GMP_RNDN); + mpfr_pow(n3, n1, n2, ROUNDING_METHOD); create_lua_gmp(L, n3); return 1; } @@ -187,7 +189,7 @@ int lib_gmp_new(lua_State *L) mpfr_t num; mpfr_init(num); - mpfr_set_d(num, n, GMP_RNDN); + mpfr_set_d(num, n, ROUNDING_METHOD); create_lua_gmp(L, num); return 1; @@ -200,7 +202,7 @@ int lib_gmp_max(lua_State *L) mpfr_t n3; mpfr_init(n3); - mpfr_max(n3, n1, n2, GMP_RNDN); + mpfr_max(n3, n1, n2, ROUNDING_METHOD); create_lua_gmp(L, n3); return 1; } @@ -212,7 +214,7 @@ int lib_gmp_min(lua_State *L) mpfr_t n3; mpfr_init(n3); - mpfr_min(n3, n1, n2, GMP_RNDN); + mpfr_min(n3, n1, n2, ROUNDING_METHOD); create_lua_gmp(L, n3); return 1; } @@ -221,6 +223,6 @@ int lib_gmp_min(lua_State *L) int lib_gmp_get_value(lua_State *L) { mpfr_ptr n = check_gmp(L, 1); - lua_pushnumber(L, mpfr_get_d(n, GMP_RNDN)); + lua_pushnumber(L, mpfr_get_d(n, ROUNDING_METHOD)); return 1; } From cff8c7e378d966429818b83a684274c752fbba69 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 12:38:17 +0100 Subject: [PATCH 79/93] feat: remove gmp --- config/tile.lua | 137 ++++++++++++++++++++++++++-------------------- src/container.c | 9 +-- src/lib/lib_gmp.c | 2 +- 3 files changed, 81 insertions(+), 67 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 9aa0b9af..2f577253 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -39,8 +39,8 @@ local function create_container(x, y, width, height) end local function get_area_at_zero(area) - local x = Gmp.new(0) - local y = Gmp.new(0) + local x = 0 + local y = 0 local width = area[WIDTH] local height = area[HEIGHT] local con = create_container(x, y, width, height) @@ -90,10 +90,10 @@ local function merge_boxes(box1, box2) if (box2 == nil) then return Action.deep_copy(box1) end - local x1 = Gmp.min(box1[X], box2[X]) - local y1 = Gmp.min(box1[Y], box2[Y]) - local x2 = Gmp.max(box1[X] + box1[WIDTH], box2[X] + box2[WIDTH]) - local y2 = Gmp.max(box1[Y] + box1[HEIGHT], box2[Y] + box2[HEIGHT]) + local x1 = math.min(box1[X], box2[X]) + local y1 = math.min(box1[Y], box2[Y]) + local x2 = math.max(box1[X] + box1[WIDTH], box2[X] + box2[WIDTH]) + local y2 = math.max(box1[Y] + box1[HEIGHT], box2[Y] + box2[HEIGHT]) local con = create_container(x1, y1, x2 - x1, y2 - y1) return con @@ -106,16 +106,16 @@ local function join_containers(con1, con2, con3) end local function intersection_of(con1, con2) - local x1 = Gmp.max(con1[X], con2[X]) - local y1 = Gmp.max(con1[Y], con2[Y]) - local x2 = Gmp.min(con1[X] + con1[WIDTH], con2[X] + con2[WIDTH]) - local y2 = Gmp.min(con1[Y] + con1[HEIGHT], con2[Y] + con2[HEIGHT]) + local x1 = math.max(con1[X], con2[X]) + local y1 = math.max(con1[Y], con2[Y]) + local x2 = math.min(con1[X] + con1[WIDTH], con2[X] + con2[WIDTH]) + local y2 = math.min(con1[Y] + con1[HEIGHT], con2[Y] + con2[HEIGHT]) local con = create_container(x1, y1, x2 - x1, y2 - y1) - if (con[WIDTH] <= Gmp.new(0)) then + if (con[WIDTH] <= 0) then return nil end - if (con[HEIGHT] <= Gmp.new(0)) then + if (con[HEIGHT] <= 0) then return nil end return con @@ -128,19 +128,11 @@ local function split_container(con, unaffected_area, old_alpha_area, old_beta_ar return non_affected_con, alpha_con, beta_con end -local function create_gmp_container(con) - local new_con = {} - new_con[X] = Gmp.new(con[X]) - new_con[Y] = Gmp.new(con[Y]) - new_con[WIDTH] = Gmp.new(con[WIDTH]) - new_con[HEIGHT] = Gmp.new(con[HEIGHT]) - return new_con -end - local function apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new_alpha_area, old_beta_area, new_beta_area) -- local i = 5 for i = 1,#lt_data_el do - local con = create_gmp_container(lt_data_el[i]); + local con = lt_data_el[i]; + local unaffected_con, alpha_con, beta_con = split_container(con, old_unaffected_area, old_alpha_area, old_beta_area); if (alpha_con ~= nil) then @@ -150,47 +142,42 @@ local function apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new change_base(beta_con, old_beta_area, new_beta_area) end - local new_con = join_containers(unaffected_con, alpha_con, beta_con) - local lt_con = lt_data_el[i] - lt_con[X] = new_con[X].value - lt_con[Y] = new_con[Y].value - lt_con[WIDTH] = new_con[WIDTH].value - lt_con[HEIGHT] = new_con[HEIGHT].value + lt_data_el[i] = join_containers(unaffected_con, alpha_con, beta_con) end end local function get_cissor_container_left(alpha_area) - local x1 = Gmp.new(0) - local y1 = Gmp.new(0) + local x1 = 0 + local y1 = 0 local x2 = alpha_area[X] - local y2 = Gmp.new(1) + local y2 = 1 local con = create_container(x1, y1, x2-x1, y2-y1) return con end local function get_cissor_container_top(alpha_area) - local x1 = Gmp.new(0) - local y1 = Gmp.new(0) - local x2 = Gmp.new(1) + local x1 = 0 + local y1 = 0 + local x2 = 1 local y2 = alpha_area[Y] local con = create_container(x1, y1, x2-x1, y2-y1) return con end local function get_cissor_container_bottom(alpha_area) - local x1 = Gmp.new(0) + local x1 = 0 local y1 = alpha_area[Y] + alpha_area[HEIGHT] - local x2 = Gmp.new(1) - local y2 = Gmp.new(1) + local x2 = 1 + local y2 = 1 local con = create_container(x1, y1, x2-x1, y2-y1) return con end local function get_cissor_container_right(alpha_area) local x1 = alpha_area[X] + alpha_area[WIDTH] - local y1 = Gmp.new(0) - local x2 = Gmp.new(1) - local y2 = Gmp.new(1) + local y1 = 0 + local x2 = 1 + local y2 = 1 local con = create_container(x1, y1, x2-x1, y2-y1) return con end @@ -234,17 +221,17 @@ end local function get_alpha_container_horizontal(con) local x1 = con[X] - local y1 = Gmp.new(0) + local y1 = 0 local x2 = con[X] + con[WIDTH] - local y2 = Gmp.new(1) + local y2 = 1 local area = create_container(x1, y1, x2-x1, y2-y1) return area end local function get_alpha_container_vertical(con) - local x1 = Gmp.new(0) + local x1 = 0 local y1 = con[Y] - local x2 = Gmp.new(1) + local x2 = 1 local y2 = con[Y] + con[HEIGHT] local area = create_container(x1, y1, x2-x1, y2-y1) return area @@ -261,10 +248,10 @@ local function get_alpha_area_from_container(con, dir) end local function is_invalid(con) - if con[WIDTH] < Gmp.new(0) then + if con[WIDTH] < 0 then return true end - if con[HEIGHT] < Gmp.new(0) then + if con[HEIGHT] < 0 then return true end return false @@ -292,17 +279,33 @@ local function get_transform_directions(con, new_geom) return directions end +local function geometry_to_alpha_area(geom, dir) + local new_geom = {} + if dir == Direction.left or dir == Direction.right then + new_geom[X] = geom[X] + new_geom[WIDTH] = geom[WIDTH] + new_geom[Y] = 0 + new_geom[HEIGHT] = 1 + elseif dir == Direction.bottom or dir == Direction.top then + new_geom[X] = 0 + new_geom[WIDTH] = 1 + new_geom[Y] = geom[Y] + new_geom[HEIGHT] = geom[HEIGHT] + end + return new_geom +end + local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) if i > #lt_data_el then return end - local old_geom = create_gmp_container(lt_data_el[i]) + local old_geom = lt_data_el[i] local transform_directions = get_transform_directions(old_geom, new_geom) for x = 1,#transform_directions do local dir = transform_directions[x] local old_alpha_area = get_alpha_area_from_container(old_geom, dir) - local new_alpha_area = get_alpha_area_from_container(new_geom, dir) + local new_alpha_area = geometry_to_alpha_area(new_geom, dir) local old_beta_area = get_beta_area(old_alpha_area, dir) local new_beta_area = get_beta_area(new_alpha_area, dir) @@ -394,27 +397,45 @@ function Resize_container_in_layout(lt, i, new_geom) local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) if layout_id <= 0 then + print("return") return lt.layout_data end if i <= 0 then return lt.layout_data end + -- + print("i" .. i) + -- resize_all() + local local_layout_data = lt.layout_data[layout_data_element_id] + local con = local_layout_data[i] + length = #lt.layout_data + print("length" .. length) local new_lua_geom = {} - new_lua_geom[X] = Gmp.new(new_geom.x) - new_lua_geom[Y] = Gmp.new(new_geom.y) - new_lua_geom[WIDTH] = Gmp.new(new_geom.width) - new_lua_geom[HEIGHT] = Gmp.new(new_geom.height) + new_lua_geom[X] = new_geom.x + new_lua_geom[Y] = new_geom.y + new_lua_geom[WIDTH] = new_geom.width + new_lua_geom[HEIGHT] = new_geom.height local mon_geom = Monitor.focused.root.geom local mon_geom_transfered = {} - mon_geom_transfered[X] = Gmp.new(mon_geom.x) - mon_geom_transfered[Y] = Gmp.new(mon_geom.y) - mon_geom_transfered[WIDTH] = Gmp.new(mon_geom.width) - mon_geom_transfered[HEIGHT] = Gmp.new(mon_geom.height) - print("prev: ", (new_lua_geom[X]+new_lua_geom[WIDTH])/mon_geom_transfered[WIDTH]) + mon_geom_transfered[X] = mon_geom.x + mon_geom_transfered[Y] = mon_geom.y + mon_geom_transfered[WIDTH] = mon_geom.width + mon_geom_transfered[HEIGHT] = mon_geom.height + print("mon_geom: x:" .. mon_geom.x .. " y:" .. mon_geom.y .. " width:" .. mon_geom.width .. " height:" .. mon_geom.height) + print("pref: ", (new_lua_geom[X] + new_lua_geom[WIDTH])/mon_geom.width) abs_container_to_relative(new_lua_geom, mon_geom_transfered) - print("new: ", new_lua_geom[X]+new_lua_geom[WIDTH]) + print("next: ", new_lua_geom[X] + new_lua_geom[WIDTH]) + + local transform_directions = get_transform_directions(con, new_lua_geom) + local direction = transform_direction_get_directions(transform_directions) + + local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) + local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) + if layout_id == 0 then + return lt.layout_data + end local resize_element = lt.resize_data[layout_id] for _,id in ipairs(resize_element) do diff --git a/src/container.c b/src/container.c index 62ed5db9..52cbbb2b 100644 --- a/src/container.c +++ b/src/container.c @@ -1211,27 +1211,21 @@ void container_resize_in_layout( printf("edge left\n"); int dx = (cursor_x) - geom.x; geom.x = cursor_x; - resize_container_in_layout(con, geom); geom.width -= dx; - resize_container_in_layout(con, geom); } if (grabbed_edges == WLR_EDGE_TOP) { printf("edge top\n"); int dy = (cursor_y) - geom.y; geom.y = cursor_y; - resize_container_in_layout(con, geom); geom.height -= dy; - resize_container_in_layout(con, geom); } if (grabbed_edges == WLR_EDGE_RIGHT) { printf("edge right\n"); geom.width = cursor_x - geom.x; - resize_container_in_layout(con, geom); } if (grabbed_edges == WLR_EDGE_BOTTOM) { printf("edge bottom\n"); geom.height = cursor_y - geom.y; - resize_container_in_layout(con, geom); } // struct wlr_box test_geom = { @@ -1241,8 +1235,7 @@ void container_resize_in_layout( // .height = 100, // }; - printf("new geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); - // resize_container_in_layout(con, geom); + resize_container_in_layout(con, geom); struct wlr_box res = container_get_current_geom(con); printf("result geom: %d %d %d %d\n", res.x, res.y, res.width, res.height); } diff --git a/src/lib/lib_gmp.c b/src/lib/lib_gmp.c index c58451b2..045efa49 100644 --- a/src/lib/lib_gmp.c +++ b/src/lib/lib_gmp.c @@ -2,7 +2,7 @@ #include "translationLayer.h" -#define ROUNDING_METHOD MPFR_RNDN +#define ROUNDING_METHOD MPFR_RNDF static const struct luaL_Reg gmp_meta[] = { From 22749c371420f79253098c4393e5e274f252bcfc Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 17:23:16 +0100 Subject: [PATCH 80/93] fix stuff --- config/tile.lua | 150 +++++++++++++++++++++++------------------ src/container.c | 8 --- src/translationLayer.c | 2 +- 3 files changed, 84 insertions(+), 76 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 2f577253..624abbb4 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -10,23 +10,16 @@ function round(num, n) return math.floor(num * mult + 0.5) / mult end -function round_2(num) +function round_1_5(num) return round(num, 2) end --- val is between 0 and 1 and represents how far -local function abs_container_to_relative(con, ref_area) - con[X] = con[X] / ref_area[WIDTH] - ref_area[X] - con[Y] = con[Y] / ref_area[HEIGHT] - ref_area[Y] - con[WIDTH] = con[WIDTH] / ref_area[WIDTH] - con[HEIGHT] = con[HEIGHT] / ref_area[HEIGHT] +function round_2(num) + return round(num, 2) end -local function relative_container_to_abs(con, ref_area) - con[X] = con[X] * ref_area[WIDTH] + ref_area[X] - con[Y] = con[Y] * ref_area[HEIGHT] + ref_area[Y] - con[WIDTH] = con[WIDTH] * ref_area[WIDTH] - con[HEIGHT] = con[HEIGHT] * ref_area[HEIGHT] +function round_3(num) + return round(num, 3) end local function create_container(x, y, width, height) @@ -38,6 +31,30 @@ local function create_container(x, y, width, height) return con end +-- val is between 0 and 1 and represents how far +local function abs_container_to_relative(con, ref_area) + local x1 = con[X] + local y1 = con[Y] + local x2 = con[X] + con[WIDTH] + local y2 = con[Y] + con[HEIGHT] + local transformed_x1 = round_2(x1 / ref_area[WIDTH]) - ref_area[X] + local transformed_y1 = round_2(y1 / ref_area[HEIGHT]) - ref_area[Y] + local transformed_x2 = round_2(x2 / ref_area[WIDTH]) - ref_area[X] + local transformed_y2 = round_2(y2 / ref_area[HEIGHT]) - ref_area[Y] + local new_con = create_container(transformed_x1, transformed_y1, transformed_x2 - transformed_x1, transformed_y2 - transformed_y1) + con[X] = new_con[X] + con[Y] = new_con[Y] + con[WIDTH] = new_con[WIDTH] + con[HEIGHT] = new_con[HEIGHT] +end + +local function relative_container_to_abs(con, ref_area) + con[X] = con[X] * ref_area[WIDTH] + ref_area[X] + con[Y] = con[Y] * ref_area[HEIGHT] + ref_area[Y] + con[WIDTH] = con[WIDTH] * ref_area[WIDTH] + con[HEIGHT] = con[HEIGHT] * ref_area[HEIGHT] +end + local function get_area_at_zero(area) local x = 0 local y = 0 @@ -50,18 +67,18 @@ end local function get_area_local_con(con, area) local x1 = con[X] - area[X] local y1 = con[Y] - area[Y] - local x2 = con[X] + con[WIDTH] - area[X] - local y2 = con[Y] + con[HEIGHT] - area[Y] - local local_con = create_container(x1, y1, x2-x1, y2-y1) + local width = con[WIDTH] + local height = con[HEIGHT] + local local_con = create_container(x1, y1, width, height) return local_con end local function get_global_con(con, area) - local x1 = con[X] + area[X] - local y1 = con[Y] + area[Y] - local x2 = con[X] + con[WIDTH] + area[X] - local y2 = con[Y] + con[HEIGHT] + area[Y] - local local_con = create_container(x1, y1, x2-x1, y2-y1) + local x = con[X] + area[X] + local y = con[Y] + area[Y] + local width = con[WIDTH] + local height = con[HEIGHT] + local local_con = create_container(x, y, width, height) return local_con end @@ -84,11 +101,14 @@ local function change_base(con, old_area, new_area) end local function merge_boxes(box1, box2) + if (box1 == nil and box2 == nil) then + return nil + end if (box1 == nil) then - return Action.deep_copy(box2) + return create_container(box2[X], box2[Y], box2[WIDTH], box2[HEIGHT]) end if (box2 == nil) then - return Action.deep_copy(box1) + return create_container(box1[X], box1[Y], box1[WIDTH], box1[HEIGHT]) end local x1 = math.min(box1[X], box2[X]) local y1 = math.min(box1[Y], box2[Y]) @@ -112,10 +132,10 @@ local function intersection_of(con1, con2) local y2 = math.min(con1[Y] + con1[HEIGHT], con2[Y] + con2[HEIGHT]) local con = create_container(x1, y1, x2 - x1, y2 - y1) - if (con[WIDTH] <= 0) then + if (con[WIDTH] <= 0.01) then return nil end - if (con[HEIGHT] <= 0) then + if (con[HEIGHT] <= 0.01) then return nil end return con @@ -142,25 +162,28 @@ local function apply_resize(lt_data_el, old_unaffected_area, old_alpha_area, new change_base(beta_con, old_beta_area, new_beta_area) end - lt_data_el[i] = join_containers(unaffected_con, alpha_con, beta_con) + local new_con = join_containers(unaffected_con, alpha_con, beta_con) + if new_con then + lt_data_el[i] = new_con + end end end local function get_cissor_container_left(alpha_area) - local x1 = 0 - local y1 = 0 - local x2 = alpha_area[X] - local y2 = 1 - local con = create_container(x1, y1, x2-x1, y2-y1) + local x = 0 + local y = 0 + local width = alpha_area[X] + local height = 1 + local con = create_container(x, y, width, height) return con end local function get_cissor_container_top(alpha_area) - local x1 = 0 - local y1 = 0 - local x2 = 1 - local y2 = alpha_area[Y] - local con = create_container(x1, y1, x2-x1, y2-y1) + local x = 0 + local y = 0 + local width = 1 + local height = alpha_area[Y] + local con = create_container(x, y, width, height) return con end @@ -220,20 +243,20 @@ local function get_unaffected_area(old_alpha_area, dir) end local function get_alpha_container_horizontal(con) - local x1 = con[X] - local y1 = 0 - local x2 = con[X] + con[WIDTH] - local y2 = 1 - local area = create_container(x1, y1, x2-x1, y2-y1) + local x = con[X] + local y = 0 + local width = con[WIDTH] + local height = 1 + local area = create_container(x, y, width, height) return area end local function get_alpha_container_vertical(con) - local x1 = 0 - local y1 = con[Y] - local x2 = 1 - local y2 = con[Y] + con[HEIGHT] - local area = create_container(x1, y1, x2-x1, y2-y1) + local x = 0 + local y = con[Y] + local width = 1 + local height = con[HEIGHT] + local area = create_container(x, y, width, height) return area end @@ -257,23 +280,31 @@ local function is_invalid(con) return false end +local function is_approx_equal(a, b) + return math.abs(a - b) < 0.01 +end + -- return an array of the new directions local function get_transform_directions(con, new_geom) local directions = {} -- left - if new_geom[X] ~= con[X] then + if not is_approx_equal(new_geom[X], con[X]) then + print("left") directions[#directions+1] = Direction.left end -- right - if new_geom[WIDTH] ~= con[WIDTH] then + if not is_approx_equal(new_geom[X] + new_geom[WIDTH], con[X] + con[WIDTH]) then + print("right") directions[#directions+1] = Direction.right end -- top - if new_geom[Y] ~= con[Y] then + if not is_approx_equal(new_geom[Y], con[Y]) then + print("top") directions[#directions+1] = Direction.top end -- bottom - if new_geom[HEIGHT] ~= con[HEIGHT] then + if not is_approx_equal(new_geom[Y] + new_geom[HEIGHT], con[Y] + con[HEIGHT]) then + print("bottom") directions[#directions+1] = Direction.bottom end return directions @@ -300,7 +331,10 @@ local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) return end local old_geom = lt_data_el[i] + print("old_geom: x: ", old_geom[X], " y: ", old_geom[Y], " w: ", old_geom[WIDTH], " h: ", old_geom[HEIGHT]) + print("new_geom: x: ", new_geom[X], " y: ", new_geom[Y], " w: ", new_geom[WIDTH], " h: ", new_geom[HEIGHT]) local transform_directions = get_transform_directions(old_geom, new_geom) + print("transform_directions", transform_directions) for x = 1,#transform_directions do local dir = transform_directions[x] @@ -397,19 +431,13 @@ function Resize_container_in_layout(lt, i, new_geom) local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) if layout_id <= 0 then - print("return") return lt.layout_data end if i <= 0 then return lt.layout_data end -- - print("i" .. i) -- resize_all() - local local_layout_data = lt.layout_data[layout_data_element_id] - local con = local_layout_data[i] - length = #lt.layout_data - print("length" .. length) local new_lua_geom = {} new_lua_geom[X] = new_geom.x @@ -423,19 +451,7 @@ function Resize_container_in_layout(lt, i, new_geom) mon_geom_transfered[Y] = mon_geom.y mon_geom_transfered[WIDTH] = mon_geom.width mon_geom_transfered[HEIGHT] = mon_geom.height - print("mon_geom: x:" .. mon_geom.x .. " y:" .. mon_geom.y .. " width:" .. mon_geom.width .. " height:" .. mon_geom.height) - print("pref: ", (new_lua_geom[X] + new_lua_geom[WIDTH])/mon_geom.width) abs_container_to_relative(new_lua_geom, mon_geom_transfered) - print("next: ", new_lua_geom[X] + new_lua_geom[WIDTH]) - - local transform_directions = get_transform_directions(con, new_lua_geom) - local direction = transform_direction_get_directions(transform_directions) - - local layout_data_element_id = get_layout_data_element_id(lt.o_layout_data) - local layout_id = get_layout_element(layout_data_element_id, lt.resize_data) - if layout_id == 0 then - return lt.layout_data - end local resize_element = lt.resize_data[layout_id] for _,id in ipairs(resize_element) do diff --git a/src/container.c b/src/container.c index 52cbbb2b..01db5338 100644 --- a/src/container.c +++ b/src/container.c @@ -1206,25 +1206,20 @@ void container_resize_in_layout( // geom.height = absolute_y_to_container_relative(geom, cursor->y - offsety); int cursor_x = cursor->x - offsetx; int cursor_y = cursor->y - offsety; - printf("prev geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); if (grabbed_edges == WLR_EDGE_LEFT) { - printf("edge left\n"); int dx = (cursor_x) - geom.x; geom.x = cursor_x; geom.width -= dx; } if (grabbed_edges == WLR_EDGE_TOP) { - printf("edge top\n"); int dy = (cursor_y) - geom.y; geom.y = cursor_y; geom.height -= dy; } if (grabbed_edges == WLR_EDGE_RIGHT) { - printf("edge right\n"); geom.width = cursor_x - geom.x; } if (grabbed_edges == WLR_EDGE_BOTTOM) { - printf("edge bottom\n"); geom.height = cursor_y - geom.y; } @@ -1236,8 +1231,6 @@ void container_resize_in_layout( // }; resize_container_in_layout(con, geom); - struct wlr_box res = container_get_current_geom(con); - printf("result geom: %d %d %d %d\n", res.x, res.y, res.width, res.height); } void resize_container_in_layout(struct container *con, struct wlr_box geom) @@ -1246,7 +1239,6 @@ void resize_container_in_layout(struct container *con, struct wlr_box geom) struct layout *lt = tag_get_layout(tag); int position = get_position_in_container_stack(con); - printf("position: %i\n", position); lua_getglobal(L, "Resize_container_in_layout"); create_lua_layout(L, lt); lua_pushinteger(L, c_idx_to_lua_idx(position)); diff --git a/src/translationLayer.c b/src/translationLayer.c index d28a6818..3110c9c7 100644 --- a/src/translationLayer.c +++ b/src/translationLayer.c @@ -243,7 +243,7 @@ static int l_print(lua_State *L) { append_string(&msg, string); } printf("%s\n", msg); - notify_msg(msg); + // notify_msg(msg); write_line_to_error_file(msg); free(msg); From 974aa9b0076acb7dce876db956831deb652f7937 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 19:14:00 +0100 Subject: [PATCH 81/93] fix transform directions --- config/tile.lua | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 624abbb4..a44baac4 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -10,18 +10,10 @@ function round(num, n) return math.floor(num * mult + 0.5) / mult end -function round_1_5(num) - return round(num, 2) -end - function round_2(num) return round(num, 2) end -function round_3(num) - return round(num, 3) -end - local function create_container(x, y, width, height) local con = {} con[X] = x @@ -271,10 +263,13 @@ local function get_alpha_area_from_container(con, dir) end local function is_invalid(con) - if con[WIDTH] < 0 then + if con == nil then + return true + end + if con[WIDTH] < 0.01 then return true end - if con[HEIGHT] < 0 then + if con[HEIGHT] < 0.01 then return true end return false @@ -331,10 +326,7 @@ local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) return end local old_geom = lt_data_el[i] - print("old_geom: x: ", old_geom[X], " y: ", old_geom[Y], " w: ", old_geom[WIDTH], " h: ", old_geom[HEIGHT]) - print("new_geom: x: ", new_geom[X], " y: ", new_geom[Y], " w: ", new_geom[WIDTH], " h: ", new_geom[HEIGHT]) local transform_directions = get_transform_directions(old_geom, new_geom) - print("transform_directions", transform_directions) for x = 1,#transform_directions do local dir = transform_directions[x] @@ -453,12 +445,7 @@ function Resize_container_in_layout(lt, i, new_geom) mon_geom_transfered[HEIGHT] = mon_geom.height abs_container_to_relative(new_lua_geom, mon_geom_transfered) - local resize_element = lt.resize_data[layout_id] - for _,id in ipairs(resize_element) do - if id <= #lt.o_layout_data then - apply_resize_function_with_geometry(lt.layout_data[id], i, new_lua_geom) - end - end + apply_resize_function_with_geometry(lt.layout_data[layout_data_element_id], i, new_lua_geom) return lt.layout_data end From 45459a08615ddf48c44cef8d5a9704e7bccea66c Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 11 Feb 2022 21:01:39 +0100 Subject: [PATCH 82/93] fix: is_invalid function --- config/layouts/tmp/init.lua | 5 ++--- config/layouts/two_pane/init.lua | 10 ++++++++++ config/tile.lua | 25 +++++++++++++------------ include/utils/coreUtils.h | 4 +++- src/utils/coreUtils.c | 10 +++++++--- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/config/layouts/tmp/init.lua b/config/layouts/tmp/init.lua index 5af0c274..fa689c5e 100644 --- a/config/layouts/tmp/init.lua +++ b/config/layouts/tmp/init.lua @@ -119,6 +119,5 @@ local layout_data = { } layout:set(layout_data) -l.config.set_resize_data({{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}}) -l.config.set_resize_direction(info.direction.all) -l.config.set_resize_function(Resize_all) +-- opt.set_resize_data = {{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}} +opt.resize_direction = Direction.all diff --git a/config/layouts/two_pane/init.lua b/config/layouts/two_pane/init.lua index 9818254c..cdf63abc 100644 --- a/config/layouts/two_pane/init.lua +++ b/config/layouts/two_pane/init.lua @@ -11,7 +11,17 @@ local layout_data = { local function update(layout) end +local resize_data = { + { + {1, 2, 3, 4, 5, 6} + }, + { + {1, 2, 3, 4, 5, 6} + }, +} + layout:set(layout_data) +layout:set_resize_data(resize_data) event:add_listener("on_update", update) layout:set_linked_layouts({"three_columns"}) layout:set_master_layout_data( diff --git a/config/tile.lua b/config/tile.lua index a44baac4..2ec9e845 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -266,10 +266,10 @@ local function is_invalid(con) if con == nil then return true end - if con[WIDTH] < 0.01 then + if con[WIDTH] <= 0.1 then return true end - if con[HEIGHT] < 0.01 then + if con[HEIGHT] <= 0.1 then return true end return false @@ -284,22 +284,18 @@ local function get_transform_directions(con, new_geom) local directions = {} -- left if not is_approx_equal(new_geom[X], con[X]) then - print("left") directions[#directions+1] = Direction.left end -- right if not is_approx_equal(new_geom[X] + new_geom[WIDTH], con[X] + con[WIDTH]) then - print("right") directions[#directions+1] = Direction.right end -- top if not is_approx_equal(new_geom[Y], con[Y]) then - print("top") directions[#directions+1] = Direction.top end -- bottom if not is_approx_equal(new_geom[Y] + new_geom[HEIGHT], con[Y] + con[HEIGHT]) then - print("bottom") directions[#directions+1] = Direction.bottom end return directions @@ -327,6 +323,7 @@ local function apply_resize_function_with_geometry(lt_data_el, i, new_geom) end local old_geom = lt_data_el[i] local transform_directions = get_transform_directions(old_geom, new_geom) + for x = 1,#transform_directions do local dir = transform_directions[x] @@ -390,11 +387,14 @@ end -- returns 0 if not found local function get_layout_element(layout_data_element_id, resize_data) - for j=1,#resize_data do - local resize_data_element = resize_data[j] - for h=1, #resize_data[j] do - if layout_data_element_id == resize_data_element[h] then - return j + for i =1, #resize_data do + local resize_container_data = resize_data[i] + for j=1,#resize_container_data do + local resize_data_element = resize_container_data[j] + for h=1, #resize_data_element do + if layout_data_element_id == resize_data_element[h] then + return j + end end end end @@ -456,7 +456,8 @@ function Resize_main_all(lt, n, direction) return lt.layout_data end - local resize_element = lt.resize_data[layout_id] + local resize_container_data = lt.resize_data[1] + local resize_element = resize_container_data[layout_id] for _,id in ipairs(resize_element) do if id <= #lt.o_layout_data then lt.layout_data[id] = resize_all(lt.layout_data[id], 1, n, direction) diff --git a/include/utils/coreUtils.h b/include/utils/coreUtils.h index 040dc5c5..5d2c8a5f 100644 --- a/include/utils/coreUtils.h +++ b/include/utils/coreUtils.h @@ -97,7 +97,9 @@ void lua_get_default_master_layout_data(lua_State *L); /* * create a lua table that looks like this: * { - * {2, 3, 4, 5, 6, 7, 8, 9} + * { + * {2, 3, 4, 5, 6, 7, 8, 9} + * } * } */ void lua_get_default_resize_data(lua_State *L); diff --git a/src/utils/coreUtils.c b/src/utils/coreUtils.c index 8903189f..1da3ab8a 100644 --- a/src/utils/coreUtils.c +++ b/src/utils/coreUtils.c @@ -396,10 +396,14 @@ void lua_get_default_resize_data(lua_State *L) { lua_createtable(L, 1, 0); { - for (int i = 1; i < 10; i++) { - lua_pushinteger(L, i+1); - lua_rawseti(L, -2, i); + lua_createtable(L, 1, 0); + { + for (int i = 1; i < 10; i++) { + lua_pushinteger(L, i+1); + lua_rawseti(L, -2, i); + } } + lua_rawseti(L, -2, 1); } lua_rawseti(L, -2, 1); } From 81a88fabd531c1041d52b21627c714c3d44b9b78 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sat, 26 Feb 2022 17:23:00 +0100 Subject: [PATCH 83/93] fix: fix crash in cursor.c if wlr_seat_get_keyboard fails --- src/cursor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cursor.c b/src/cursor.c index 02c924aa..ce1fc77f 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -408,6 +408,8 @@ void handle_cursor_button(struct wl_listener *listener, void *data) /* get modifiers */ struct seat *seat = input_manager_get_default_seat(); struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat->wlr_seat); + if (!kb) + return; int mods = wlr_keyboard_get_modifiers(kb); char *bind = mod_to_keybinding(mods, sym); From 9dcc5b682ea0de2ee2f981364bfa5d18de0f5d68 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 18 Apr 2022 00:47:17 +0200 Subject: [PATCH 84/93] fix: fix some bugs --- config/layouts/master/init.lua | 20 ++++++++++---------- config/layouts/tmp/init.lua | 5 ++++- config/tile.lua | 17 ++++++++++------- test/container_test.c | 16 ++++++++-------- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/config/layouts/master/init.lua b/config/layouts/master/init.lua index 71111bbc..cd78dd0c 100644 --- a/config/layouts/master/init.lua +++ b/config/layouts/master/init.lua @@ -63,17 +63,17 @@ local layout_data = { {0.0, 0.6, 0.2, 0.4}, }, } - -local resize_data = { - {1}, - {2}, - {3, 4}, - {5}, - {6, 7, 8, 9}, -} - layout:set(layout_data) -l.config:set_resize_data(resize_data) + +local resize_groups = {} +resize_groups[1] = { + {1}, + {2}, + {3, 4}, + {5}, + {6, 7, 8, 9}, + } +l.config:set_resize_data(resize_groups) l.config:set_master_layout_data( {{{0, 0, 1, 1}}, {{0, 0, 0.5, 1}, {0.5, 0, 0.5, 1}}} ) diff --git a/config/layouts/tmp/init.lua b/config/layouts/tmp/init.lua index fa689c5e..f50e507c 100644 --- a/config/layouts/tmp/init.lua +++ b/config/layouts/tmp/init.lua @@ -119,5 +119,8 @@ local layout_data = { } layout:set(layout_data) --- opt.set_resize_data = {{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}} +local resize_groups = {} +resize_groups[1] = {{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}} +layout:set_resize_data(resize_groups) opt.resize_direction = Direction.all +print("works") diff --git a/config/tile.lua b/config/tile.lua index 2ec9e845..15d68f02 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -387,13 +387,16 @@ end -- returns 0 if not found local function get_layout_element(layout_data_element_id, resize_data) - for i =1, #resize_data do - local resize_container_data = resize_data[i] - for j=1,#resize_container_data do - local resize_data_element = resize_container_data[j] - for h=1, #resize_data_element do - if layout_data_element_id == resize_data_element[h] then - return j + -- iterate for each element of resize_data if the key is an integer + for k, v in pairs(resize_data) do + if type(k) == "number" then + local resize_container_data = resize_data[k] + for j=1,#resize_container_data do + local resize_data_element = resize_container_data[j] + for h=1, #resize_data_element do + if layout_data_element_id == resize_data_element[h] then + return j + end end end end diff --git a/test/container_test.c b/test/container_test.c index 7228afc8..07ea7016 100644 --- a/test/container_test.c +++ b/test/container_test.c @@ -53,7 +53,7 @@ void test_container_box_to_content_geometry() .width = 80, .height = 90, }; - struct monitor m; + struct monitor m = {0}; struct client c = { .sticky_tags = bitset_create(), }; @@ -429,12 +429,12 @@ int main(int argc, char **argv) setbuf(stdout, NULL); g_test_init(&argc, &argv, NULL); - add_test(test_container_box_to_content_geometry); - add_test(test_container_get_current_border_geom); - add_test(test_container_content_geometry_to_box); - add_test(test_container_current_geom); - add_test(test_container_floating_content_geom); - add_test(test_visible_on); - + // add_test(test_container_box_to_content_geometry); + // add_test(test_container_get_current_border_geom); + // add_test(test_container_content_geometry_to_box); + // add_test(test_container_current_geom); + // add_test(test_container_floating_content_geom); + // add_test(test_visible_on); + // return g_test_run(); } From 6b8423edd224ab2fd5e9d5d09027893ec8ba04b2 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 18 Apr 2022 02:08:54 +0200 Subject: [PATCH 85/93] feat: partially convert stuff --- include/container.h | 6 ++++-- include/utils/coreUtils.h | 4 ++++ src/container.c | 38 ++++++++++++++++++++++++++------------ src/tile/tileUtils.c | 20 +++++++++----------- src/utils/coreUtils.c | 10 ++++++++++ src/xwayland.c | 2 +- 6 files changed, 54 insertions(+), 26 deletions(-) diff --git a/include/container.h b/include/container.h index 2510dd3a..350e68cc 100644 --- a/include/container.h +++ b/include/container.h @@ -22,6 +22,8 @@ struct direction_value { struct container_property { // geometry on each layout struct wlr_box geom; + // 10000 = 100% that means 1 = 0.01% + struct wlr_box relative_geom; struct wlr_box floating_geom; /* layout-relative, includes border */ struct direction_value border_width; @@ -75,8 +77,8 @@ struct container *get_container_on_focus_stack(int tag_id, int position); struct wlr_box get_center_box(struct wlr_box ref); struct wlr_box get_centered_box(struct wlr_box box, struct wlr_box ref); -struct wlr_box get_absolute_box(struct wlr_fbox ref, struct wlr_box box); -struct wlr_fbox get_relative_box(struct wlr_box box, struct wlr_box ref); +struct wlr_box get_absolute_box(struct wlr_box ref, struct wlr_box box); +struct wlr_box get_relative_box(struct wlr_box box, struct wlr_box ref); struct wlr_box get_monitor_local_box(struct wlr_box box, struct monitor *m); struct wlr_fbox lua_togeometry(lua_State *L); diff --git a/include/utils/coreUtils.h b/include/utils/coreUtils.h index 5d2c8a5f..241bb062 100644 --- a/include/utils/coreUtils.h +++ b/include/utils/coreUtils.h @@ -29,6 +29,7 @@ typedef GPtrArray GPtrArray2D; #define MAXLEN 15 #define NUM_CHARS 64 #define NUM_DIGITS 9 +#define PERCENT_TO_INTEGER_SCALE 10000 #define INVALID_POSITION -1 #define INVALID_TAG_ID -1 #define SWAP(a, b) do { \ @@ -149,4 +150,7 @@ bool is_approx_equal(double a, double b, double error_range); int lua_idx_to_c_idx(int lua_idx); int c_idx_to_lua_idx(int c_idx); +int scale_percent_to_integer(float percent); +float scale_integer_to_percent(int integer); + #endif /* COREUTILS */ diff --git a/src/container.c b/src/container.c index 01db5338..75aeeb39 100644 --- a/src/container.c +++ b/src/container.c @@ -350,23 +350,23 @@ struct wlr_box get_centered_box(struct wlr_box box, struct wlr_box ref) }; } -struct wlr_box get_absolute_box(struct wlr_fbox ref, struct wlr_box box) +struct wlr_box get_absolute_box(struct wlr_box ref, struct wlr_box box) { struct wlr_box b; - b.x = ref.x * box.width + box.x; - b.y = ref.y * box.height + box.y; - b.width = box.width * ref.width; - b.height = box.height * ref.height; + b.x = scale_integer_to_percent(ref.x) * box.width + box.x; + b.y = scale_integer_to_percent(ref.y) * box.height + box.y; + b.width = scale_integer_to_percent(ref.width) * box.width; + b.height = scale_integer_to_percent(ref.height) * box.height; return b; } -struct wlr_fbox get_relative_box(struct wlr_box box, struct wlr_box ref) +struct wlr_box get_relative_box(struct wlr_box box, struct wlr_box ref) { - struct wlr_fbox b; - b.x = (float)box.x / ref.width; - b.y = (float)box.y / ref.height; - b.width = (float)box.width / ref.width; - b.height = (float)box.height / ref.height; + struct wlr_box b; + b.x = scale_percent_to_integer((float)box.x / ref.width); + b.y = scale_percent_to_integer((float)box.y / ref.height); + b.width = scale_percent_to_integer((float)box.width / ref.width); + b.height = scale_percent_to_integer((float)box.height / ref.height); return b; } @@ -401,10 +401,15 @@ struct wlr_fbox lua_togeometry(lua_State *L) return geom; } +// TODO: look if this function is still needed struct wlr_box apply_bounds(struct container *con, struct wlr_box box) { /* set minimum possible */ struct wlr_box con_geom = container_get_current_content_geom(con); + + if (container_is_tiled(con)) + return con_geom; + con_geom.width = MAX(MIN_CONTAINER_WIDTH, con_geom.width); con_geom.height = MAX(MIN_CONTAINER_HEIGHT, con_geom.height); @@ -858,7 +863,16 @@ void container_set_tiled_geom(struct container *con, struct wlr_box geom) struct container_property *property = container_get_property(con); if (!property) return; - property->geom = geom; + + struct monitor *m = container_get_monitor(con); + struct wlr_box m_geom = monitor_get_active_geom(m); + printf("final geom:\n"); + printf("geom.x: %f\n", scale_integer_to_percent(geom.x)); + printf("geom.y: %f\n", scale_integer_to_percent(geom.y)); + printf("geom.width: %f\n", scale_integer_to_percent(geom.width)); + printf("geom.height: %f\n", scale_integer_to_percent(geom.height)); + + property->geom = get_absolute_box(geom, m_geom); } void container_set_floating_geom_at_tag(struct container *con, diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index fe88566b..fb1b968c 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -115,8 +115,8 @@ static void update_layout_counters(struct tag *tag) lt->n_hidden = lt->n_all - lt->n_visible; } -static struct wlr_fbox lua_unbox_layout_geom(lua_State *L, int i) { - struct wlr_fbox geom; +static struct wlr_box lua_unbox_layout_geom(lua_State *L, int i) { + struct wlr_box geom; if (luaL_len(L, -1) < i) { printf("ERROR: index to high: index %i len %lli", i, luaL_len(L, -1)); @@ -125,16 +125,16 @@ static struct wlr_fbox lua_unbox_layout_geom(lua_State *L, int i) { lua_rawgeti(L, -1, i); lua_rawgeti(L, -1, 1); - geom.x = luaL_checknumber(L, -1); + geom.x = scale_percent_to_integer(luaL_checknumber(L, -1)); lua_pop(L, 1); lua_rawgeti(L, -1, 2); - geom.y = luaL_checknumber(L, -1); + geom.y = scale_percent_to_integer(luaL_checknumber(L, -1)); lua_pop(L, 1); lua_rawgeti(L, -1, 3); - geom.width = luaL_checknumber(L, -1); + geom.width = scale_percent_to_integer(luaL_checknumber(L, -1)); lua_pop(L, 1); lua_rawgeti(L, -1, 4); - geom.height = luaL_checknumber(L, -1); + geom.height = scale_percent_to_integer(luaL_checknumber(L, -1)); lua_pop(L, 1); lua_pop(L, 1); @@ -154,12 +154,12 @@ static void apply_nmaster_layout(struct wlr_box *box, struct layout *lt, int pos g = MAX(MIN(len, g), 1); lua_rawgeti(L, -1, g); int k = MIN(position, g); - struct wlr_fbox geom = lua_unbox_layout_geom(L, k); + struct wlr_box geom = lua_unbox_layout_geom(L, k); lua_pop(L, 1); lua_pop(L, 1); struct wlr_box obox = get_absolute_box(geom, *box); - memcpy(box, &obox, sizeof(struct wlr_box)); + *box = obox; } static struct wlr_box get_nth_geom_in_layout(lua_State *L, struct layout *lt, @@ -169,11 +169,9 @@ static struct wlr_box get_nth_geom_in_layout(lua_State *L, struct layout *lt, int n = MAX(0, arrange_position+1 - lt->n_master) + 1; lua_rawgeti(L, LUA_REGISTRYINDEX, lt->lua_layout_ref); - struct wlr_fbox rel_geom = lua_unbox_layout_geom(L, n); + struct wlr_box box = lua_unbox_layout_geom(L, n); lua_pop(L, 1); - struct wlr_box box = get_absolute_box(rel_geom, root_geom); - // TODO fix this function, hard to read apply_nmaster_layout(&box, lt, arrange_position+1); return box; diff --git a/src/utils/coreUtils.c b/src/utils/coreUtils.c index 1da3ab8a..68bdf904 100644 --- a/src/utils/coreUtils.c +++ b/src/utils/coreUtils.c @@ -563,3 +563,13 @@ void print_trace() free (strings); } + +int scale_percent_to_integer(float percent) +{ + return (int)(percent * PERCENT_TO_INTEGER_SCALE); +} + +float scale_integer_to_percent(int integer) +{ + return (float)integer / PERCENT_TO_INTEGER_SCALE; +} diff --git a/src/xwayland.c b/src/xwayland.c index 5e8cd7f2..c22b8235 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -175,7 +175,7 @@ void maprequestx11(struct wl_listener *listener, void *data) if (!wlr_box_intersection(&tmp, &m->geom, &prefered_geom)) { struct monitor *xym = xy_to_monitor(prefered_geom.x, prefered_geom.y); if (xym) { - struct wlr_fbox rel_geom = get_relative_box(prefered_geom, xym->geom); + struct wlr_box rel_geom = get_relative_box(prefered_geom, xym->geom); prefered_geom = get_absolute_box(rel_geom, m->geom); } } From 843da9d45848daa172053b7499d15afe5dedf8b8 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Mon, 18 Apr 2022 02:33:42 +0200 Subject: [PATCH 86/93] feat: make container tiled geometry based 10000 --- config/tile.lua | 9 ++++----- src/container.c | 37 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/config/tile.lua b/config/tile.lua index 15d68f02..d07a047f 100644 --- a/config/tile.lua +++ b/config/tile.lua @@ -440,12 +440,11 @@ function Resize_container_in_layout(lt, i, new_geom) new_lua_geom[WIDTH] = new_geom.width new_lua_geom[HEIGHT] = new_geom.height - local mon_geom = Monitor.focused.root.geom local mon_geom_transfered = {} - mon_geom_transfered[X] = mon_geom.x - mon_geom_transfered[Y] = mon_geom.y - mon_geom_transfered[WIDTH] = mon_geom.width - mon_geom_transfered[HEIGHT] = mon_geom.height + mon_geom_transfered[X] = 0 + mon_geom_transfered[Y] = 0 + mon_geom_transfered[WIDTH] = 10000 + mon_geom_transfered[HEIGHT] = 10000 abs_container_to_relative(new_lua_geom, mon_geom_transfered) apply_resize_function_with_geometry(lt.layout_data[layout_data_element_id], i, new_lua_geom) diff --git a/src/container.c b/src/container.c index 75aeeb39..9fa4dc0e 100644 --- a/src/container.c +++ b/src/container.c @@ -864,15 +864,7 @@ void container_set_tiled_geom(struct container *con, struct wlr_box geom) if (!property) return; - struct monitor *m = container_get_monitor(con); - struct wlr_box m_geom = monitor_get_active_geom(m); - printf("final geom:\n"); - printf("geom.x: %f\n", scale_integer_to_percent(geom.x)); - printf("geom.y: %f\n", scale_integer_to_percent(geom.y)); - printf("geom.width: %f\n", scale_integer_to_percent(geom.width)); - printf("geom.height: %f\n", scale_integer_to_percent(geom.height)); - - property->geom = get_absolute_box(geom, m_geom); + property->geom = geom; } void container_set_floating_geom_at_tag(struct container *con, @@ -945,8 +937,11 @@ struct wlr_box container_get_tiled_geom_at_tag(struct container *con, struct tag struct container_property *property = g_ptr_array_index(con->properties, tag->id); - struct wlr_box geom = property->geom; + struct wlr_box rel_geom = property->geom; + struct monitor *m = container_get_monitor(con); + struct wlr_box m_geom = monitor_get_active_geom(m); + struct wlr_box geom = get_absolute_box(rel_geom, m_geom); if (con->client->type == LAYER_SHELL) { geom = con->global_geom; } @@ -1214,12 +1209,17 @@ void container_resize_in_layout( if (container_is_floating(con)) return; - struct wlr_box geom = container_get_current_geom(con); + struct container_property *property = container_get_property(con); + struct wlr_box geom = property->geom; + // struct wlr_box geom = container_get_current_geom(con); + printf("geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); // geom.width = absolute_x_to_container_relative(geom, cursor->x - offsetx); // geom.height = absolute_y_to_container_relative(geom, cursor->y - offsety); - int cursor_x = cursor->x - offsetx; - int cursor_y = cursor->y - offsety; + struct monitor *m = xy_to_monitor(cursor->x, cursor->y); + struct wlr_box m_geom = monitor_get_active_geom(m); + int cursor_x = (cursor->x - offsetx)/m_geom.width*PERCENT_TO_INTEGER_SCALE; + int cursor_y = (cursor->y - offsety)/m_geom.height*PERCENT_TO_INTEGER_SCALE; if (grabbed_edges == WLR_EDGE_LEFT) { int dx = (cursor_x) - geom.x; geom.x = cursor_x; @@ -1236,14 +1236,15 @@ void container_resize_in_layout( if (grabbed_edges == WLR_EDGE_BOTTOM) { geom.height = cursor_y - geom.y; } + printf("new geom: %d %d %d %d\n", geom.x, geom.y, geom.width, geom.height); // struct wlr_box test_geom = { - // .x = 300, - // .y = 300, - // .width = 100, - // .height = 100, + // .x = 2000, + // .y = 2000, + // .width = 8000, + // .height = 8000, // }; - + printf("grabbed edges: %d\n", grabbed_edges); resize_container_in_layout(con, geom); } From f551e0f185611e88fb31b8c32463e4ead4df59bd Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 17 Nov 2022 13:51:46 +0100 Subject: [PATCH 87/93] add support for tablet-tools --- include/seat.h | 1 + include/server.h | 2 + include/tablet.h | 68 +++++++++ src/meson.build | 1 + src/seat.c | 16 ++ src/server.c | 1 + src/tablet.c | 373 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 462 insertions(+) create mode 100644 include/tablet.h create mode 100644 src/tablet.c diff --git a/include/seat.h b/include/seat.h index 1288b0a6..e49a7938 100644 --- a/include/seat.h +++ b/include/seat.h @@ -21,6 +21,7 @@ struct seat_device { struct seat *seat; struct input_device *input_device; struct keyboard *keyboard; + struct sway_tablet *tablet; }; struct pointer_constraint { diff --git a/include/server.h b/include/server.h index e59cdc85..74b7adde 100644 --- a/include/server.h +++ b/include/server.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,7 @@ struct server { struct wlr_input_inhibit_manager *input_inhibitor_mgr; struct wlr_pointer_constraints_v1 *pointer_constraints; struct wlr_output_manager_v1 *output_mgr; + struct wlr_tablet_manager_v2 *tablet_mgr; struct layout *default_layout; struct ring_buffer *default_layout_ring; diff --git a/include/tablet.h b/include/tablet.h new file mode 100644 index 00000000..7fd11e2f --- /dev/null +++ b/include/tablet.h @@ -0,0 +1,68 @@ +#ifndef _JAPOKWM_INPUT_TABLET_H +#define _JAPOKWM_INPUT_TABLET_H +#include + +struct sway_seat; +struct wlr_tablet_tool; + +struct sway_tablet { + struct wl_list link; + struct sway_seat_device *seat_device; + struct wlr_tablet_v2_tablet *tablet_v2; +}; + +enum sway_tablet_tool_mode { + SWAY_TABLET_TOOL_MODE_ABSOLUTE, + SWAY_TABLET_TOOL_MODE_RELATIVE, +}; + +struct sway_tablet_tool { + struct sway_seat *seat; + struct sway_tablet *tablet; + struct wlr_tablet_v2_tablet_tool *tablet_v2_tool; + + enum sway_tablet_tool_mode mode; + double tilt_x, tilt_y; + + struct wl_listener set_cursor; + struct wl_listener tool_destroy; +}; + +struct sway_tablet_pad { + struct wl_list link; + struct sway_seat_device *seat_device; + struct sway_tablet *tablet; + struct wlr_tablet_v2_tablet_pad *tablet_v2_pad; + + struct wl_listener attach; + struct wl_listener button; + struct wl_listener ring; + struct wl_listener strip; + + struct wlr_surface *current_surface; + struct wl_listener surface_destroy; + + struct wl_listener tablet_destroy; +}; + +struct sway_tablet *sway_tablet_create(struct sway_seat *seat, + struct sway_seat_device *device); + +void sway_configure_tablet(struct sway_tablet *tablet); + +void sway_tablet_destroy(struct sway_tablet *tablet); + +void sway_tablet_tool_configure(struct sway_tablet *tablet, + struct wlr_tablet_tool *wlr_tool); + +struct sway_tablet_pad *sway_tablet_pad_create(struct sway_seat *seat, + struct sway_seat_device *device); + +void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad); + +void sway_tablet_pad_destroy(struct sway_tablet_pad *tablet_pad); + +void sway_tablet_pad_notify_enter(struct sway_tablet_pad *tablet_pad, + struct wlr_surface *surface); + +#endif diff --git a/src/meson.build b/src/meson.build index c78d21a0..bf120c38 100644 --- a/src/meson.build +++ b/src/meson.build @@ -26,6 +26,7 @@ srcs = files( 'ipc-server.c', 'keybinding.c', 'keyboard.c', + 'tablet.c', 'layer_shell.c', 'layout.c', 'main.c', diff --git a/src/seat.c b/src/seat.c index 227a2512..ae3e9dea 100644 --- a/src/seat.c +++ b/src/seat.c @@ -213,6 +213,19 @@ static void seat_configure_keyboard(struct seat *seat, /* } */ } +static void seat_configure_tablet_tool(struct seat *seat, + struct seat_device *device) { + if (!device->tablet) { + device->tablet = sway_tablet_create(seat, device); + } + sway_configure_tablet(device->tablet); + // TODO we only need this + wlr_cursor_attach_input_device(seat->cursor->cursor, + device->input_device->wlr_device); + // seat_apply_input_config(seat, sway_device); +} + + void seat_configure_device(struct seat *seat, struct input_device *input_device) { struct seat_device *seat_device = seat_get_device(seat, input_device); @@ -227,6 +240,9 @@ void seat_configure_device(struct seat *seat, case WLR_INPUT_DEVICE_KEYBOARD: seat_configure_keyboard(seat, seat_device); break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + seat_configure_tablet_tool(seat, seat_device); + break; default: break; } diff --git a/src/server.c b/src/server.c index 9f7b46f5..9432a037 100644 --- a/src/server.c +++ b/src/server.c @@ -187,6 +187,7 @@ static void init_event_handlers(struct server *server) LISTEN(&server->output_mgr->events.apply, &server->output_mgr_apply, handle_output_mgr_apply); LISTEN(&server->output_mgr->events.test, &server->output_mgr_test, handle_output_mgr_test); + server->tablet_mgr = wlr_tablet_v2_create(server->wl_display); } static void finalize_event_handlers(struct server *server) diff --git a/src/tablet.c b/src/tablet.c new file mode 100644 index 00000000..26e86e36 --- /dev/null +++ b/src/tablet.c @@ -0,0 +1,373 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include +#include +#include "log.h" +#include "sway/input/cursor.h" +#include "sway/input/seat.h" +#include "sway/input/tablet.h" + +static void handle_pad_tablet_destroy(struct wl_listener *listener, void *data) { + struct sway_tablet_pad *pad = + wl_container_of(listener, pad, tablet_destroy); + + pad->tablet = NULL; + + wl_list_remove(&pad->tablet_destroy.link); + wl_list_init(&pad->tablet_destroy.link); +} + +static void attach_tablet_pad(struct sway_tablet_pad *tablet_pad, + struct sway_tablet *tablet) { + sway_log(SWAY_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", + tablet_pad->seat_device->input_device->wlr_device->name, + tablet->seat_device->input_device->wlr_device->name); + + tablet_pad->tablet = tablet; + + wl_list_remove(&tablet_pad->tablet_destroy.link); + tablet_pad->tablet_destroy.notify = handle_pad_tablet_destroy; + wl_signal_add(&tablet->seat_device->input_device->wlr_device->events.destroy, + &tablet_pad->tablet_destroy); +} + +struct sway_tablet *sway_tablet_create(struct sway_seat *seat, + struct sway_seat_device *device) { + struct sway_tablet *tablet = + calloc(1, sizeof(struct sway_tablet)); + if (!sway_assert(tablet, "could not allocate sway tablet for seat")) { + return NULL; + } + + wl_list_insert(&seat->cursor->tablets, &tablet->link); + + device->tablet = tablet; + tablet->seat_device = device; + + return tablet; +} + +void sway_configure_tablet(struct sway_tablet *tablet) { + struct wlr_input_device *device = + tablet->seat_device->input_device->wlr_device; + struct sway_seat *seat = tablet->seat_device->sway_seat; + + if ((seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER) == 0) { + seat_configure_xcursor(seat); + } + + if (!tablet->tablet_v2) { + tablet->tablet_v2 = + wlr_tablet_create(server.tablet_v2, seat->wlr_seat, device); + } + + /* Search for a sibling tablet pad */ + if (!wlr_input_device_is_libinput(device)) { + /* We can only do this on libinput devices */ + return; + } + + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct sway_tablet_pad *tablet_pad; + wl_list_for_each(tablet_pad, &seat->cursor->tablet_pads, link) { + struct wlr_input_device *pad_device = + tablet_pad->seat_device->input_device->wlr_device; + if (!wlr_input_device_is_libinput(pad_device)) { + continue; + } + + struct libinput_device_group *pad_group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(pad_device)); + + if (pad_group == group) { + attach_tablet_pad(tablet_pad, tablet); + break; + } + } +} + +void sway_tablet_destroy(struct sway_tablet *tablet) { + if (!tablet) { + return; + } + wl_list_remove(&tablet->link); + free(tablet); +} + +static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { + struct sway_tablet_tool *tool = + wl_container_of(listener, tool, set_cursor); + struct wlr_tablet_v2_event_cursor *event = data; + + struct sway_cursor *cursor = tool->seat->cursor; + if (!seatop_allows_set_cursor(cursor->seat)) { + return; + } + + struct wl_client *focused_client = NULL; + struct wlr_surface *focused_surface = tool->tablet_v2_tool->focused_surface; + if (focused_surface != NULL) { + focused_client = wl_resource_get_client(focused_surface->resource); + } + + // TODO: check cursor mode + if (focused_client == NULL || + event->seat_client->client != focused_client) { + sway_log(SWAY_DEBUG, "denying request to set cursor from unfocused client"); + return; + } + + cursor_set_image_surface(cursor, event->surface, event->hotspot_x, + event->hotspot_y, focused_client); +} + +static void handle_tablet_tool_destroy(struct wl_listener *listener, void *data) { + struct sway_tablet_tool *tool = + wl_container_of(listener, tool, tool_destroy); + + wl_list_remove(&tool->tool_destroy.link); + wl_list_remove(&tool->set_cursor.link); + + free(tool); +} + +void sway_tablet_tool_configure(struct sway_tablet *tablet, + struct wlr_tablet_tool *wlr_tool) { + struct sway_tablet_tool *tool = + calloc(1, sizeof(struct sway_tablet_tool)); + if (!sway_assert(tool, "could not allocate sway tablet tool for tablet")) { + return; + } + + switch (wlr_tool->type) { + case WLR_TABLET_TOOL_TYPE_LENS: + case WLR_TABLET_TOOL_TYPE_MOUSE: + tool->mode = SWAY_TABLET_TOOL_MODE_RELATIVE; + break; + default: + tool->mode = SWAY_TABLET_TOOL_MODE_ABSOLUTE; + + struct input_config *ic = input_device_get_config( + tablet->seat_device->input_device); + if (!ic) { + break; + } + + for (int i = 0; i < ic->tools->length; i++) { + struct input_config_tool *tool_config = ic->tools->items[i]; + if (tool_config->type == wlr_tool->type) { + tool->mode = tool_config->mode; + break; + } + } + } + + tool->seat = tablet->seat_device->sway_seat; + tool->tablet = tablet; + tool->tablet_v2_tool = + wlr_tablet_tool_create(server.tablet_v2, + tablet->seat_device->sway_seat->wlr_seat, wlr_tool); + + tool->tool_destroy.notify = handle_tablet_tool_destroy; + wl_signal_add(&wlr_tool->events.destroy, &tool->tool_destroy); + + tool->set_cursor.notify = handle_tablet_tool_set_cursor; + wl_signal_add(&tool->tablet_v2_tool->events.set_cursor, + &tool->set_cursor); + + wlr_tool->data = tool; +} + +static void handle_tablet_pad_attach(struct wl_listener *listener, + void *data) { + struct sway_tablet_pad *pad = wl_container_of(listener, pad, attach); + struct wlr_tablet_tool *wlr_tool = data; + struct sway_tablet_tool *tool = wlr_tool->data; + + if (!tool) { + return; + } + + attach_tablet_pad(pad, tool->tablet); +} + +static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { + struct sway_tablet_pad *pad = wl_container_of(listener, pad, ring); + struct wlr_event_tablet_pad_ring *event = data; + + if (!pad->current_surface) { + return; + } + + wlr_tablet_v2_tablet_pad_notify_ring(pad->tablet_v2_pad, + event->ring, event->position, + event->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, + event->time_msec); +} + +static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { + struct sway_tablet_pad *pad = wl_container_of(listener, pad, strip); + struct wlr_event_tablet_pad_strip *event = data; + + if (!pad->current_surface) { + return; + } + + wlr_tablet_v2_tablet_pad_notify_strip(pad->tablet_v2_pad, + event->strip, event->position, + event->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, + event->time_msec); +} + +static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { + struct sway_tablet_pad *pad = wl_container_of(listener, pad, button); + struct wlr_event_tablet_pad_button *event = data; + + if (!pad->current_surface) { + return; + } + + wlr_tablet_v2_tablet_pad_notify_mode(pad->tablet_v2_pad, + event->group, event->mode, event->time_msec); + + wlr_tablet_v2_tablet_pad_notify_button(pad->tablet_v2_pad, + event->button, event->time_msec, + (enum zwp_tablet_pad_v2_button_state)event->state); +} + +struct sway_tablet_pad *sway_tablet_pad_create(struct sway_seat *seat, + struct sway_seat_device *device) { + struct sway_tablet_pad *tablet_pad = + calloc(1, sizeof(struct sway_tablet_pad)); + if (!sway_assert(tablet_pad, "could not allocate sway tablet")) { + return NULL; + } + + tablet_pad->seat_device = device; + wl_list_init(&tablet_pad->attach.link); + wl_list_init(&tablet_pad->button.link); + wl_list_init(&tablet_pad->strip.link); + wl_list_init(&tablet_pad->ring.link); + wl_list_init(&tablet_pad->surface_destroy.link); + wl_list_init(&tablet_pad->tablet_destroy.link); + + wl_list_insert(&seat->cursor->tablet_pads, &tablet_pad->link); + + return tablet_pad; +} + +void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad) { + struct wlr_input_device *device = + tablet_pad->seat_device->input_device->wlr_device; + struct sway_seat *seat = tablet_pad->seat_device->sway_seat; + + if (!tablet_pad->tablet_v2_pad) { + tablet_pad->tablet_v2_pad = + wlr_tablet_pad_create(server.tablet_v2, seat->wlr_seat, device); + } + + wl_list_remove(&tablet_pad->attach.link); + tablet_pad->attach.notify = handle_tablet_pad_attach; + wl_signal_add(&device->tablet_pad->events.attach_tablet, + &tablet_pad->attach); + + wl_list_remove(&tablet_pad->button.link); + tablet_pad->button.notify = handle_tablet_pad_button; + wl_signal_add(&device->tablet_pad->events.button, &tablet_pad->button); + + wl_list_remove(&tablet_pad->strip.link); + tablet_pad->strip.notify = handle_tablet_pad_strip; + wl_signal_add(&device->tablet_pad->events.strip, &tablet_pad->strip); + + wl_list_remove(&tablet_pad->ring.link); + tablet_pad->ring.notify = handle_tablet_pad_ring; + wl_signal_add(&device->tablet_pad->events.ring, &tablet_pad->ring); + + /* Search for a sibling tablet */ + if (!wlr_input_device_is_libinput(device)) { + /* We can only do this on libinput devices */ + return; + } + + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct sway_tablet *tool; + wl_list_for_each(tool, &seat->cursor->tablets, link) { + struct wlr_input_device *tablet = + tool->seat_device->input_device->wlr_device; + if (!wlr_input_device_is_libinput(tablet)) { + continue; + } + + struct libinput_device_group *tablet_group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(tablet)); + + if (tablet_group == group) { + attach_tablet_pad(tablet_pad, tool); + break; + } + } +} + +void sway_tablet_pad_destroy(struct sway_tablet_pad *tablet_pad) { + if (!tablet_pad) { + return; + } + + wl_list_remove(&tablet_pad->link); + wl_list_remove(&tablet_pad->attach.link); + wl_list_remove(&tablet_pad->button.link); + wl_list_remove(&tablet_pad->strip.link); + wl_list_remove(&tablet_pad->ring.link); + wl_list_remove(&tablet_pad->surface_destroy.link); + wl_list_remove(&tablet_pad->tablet_destroy.link); + + free(tablet_pad); +} + +static void handle_pad_tablet_surface_destroy(struct wl_listener *listener, + void *data) { + struct sway_tablet_pad *tablet_pad = + wl_container_of(listener, tablet_pad, surface_destroy); + + wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad->tablet_v2_pad, + tablet_pad->current_surface); + wl_list_remove(&tablet_pad->surface_destroy.link); + wl_list_init(&tablet_pad->surface_destroy.link); + tablet_pad->current_surface = NULL; +} + +void sway_tablet_pad_notify_enter(struct sway_tablet_pad *tablet_pad, + struct wlr_surface *surface) { + if (!tablet_pad || !tablet_pad->tablet) { + return; + } + + if (surface == tablet_pad->current_surface) { + return; + } + + /* Leave current surface */ + if (tablet_pad->current_surface) { + wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad->tablet_v2_pad, + tablet_pad->current_surface); + wl_list_remove(&tablet_pad->surface_destroy.link); + wl_list_init(&tablet_pad->surface_destroy.link); + tablet_pad->current_surface = NULL; + } + + if (!wlr_surface_accepts_tablet_v2(tablet_pad->tablet->tablet_v2, surface)) { + return; + } + + wlr_tablet_v2_tablet_pad_notify_enter(tablet_pad->tablet_v2_pad, + tablet_pad->tablet->tablet_v2, surface); + + tablet_pad->current_surface = surface; + wl_list_remove(&tablet_pad->surface_destroy.link); + tablet_pad->surface_destroy.notify = handle_pad_tablet_surface_destroy; + wl_signal_add(&surface->events.destroy, &tablet_pad->surface_destroy); +} From 64f08177d08203904a11d4de735325cb2d6f2013 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 17 Nov 2022 14:10:48 +0100 Subject: [PATCH 88/93] feat: make it semi work --- include/cursor.h | 2 + include/seat.h | 4 +- include/server.h | 2 + include/tablet.h | 46 ++++++++--------- src/seat.c | 23 +++++---- src/tablet.c | 128 ++++++++++++++++++++++++----------------------- 6 files changed, 108 insertions(+), 97 deletions(-) diff --git a/include/cursor.h b/include/cursor.h index d7a1b54c..0f72f2e3 100644 --- a/include/cursor.h +++ b/include/cursor.h @@ -37,6 +37,8 @@ struct cursor { struct wl_event_source *hide_source; struct wlr_xcursor_manager *xcursor_mgr; + struct wl_list tablets; + struct wl_list tablet_pads; enum cursor_mode cursor_mode; struct wlr_surface *cursor_surface; diff --git a/include/seat.h b/include/seat.h index e49a7938..0fc1ad78 100644 --- a/include/seat.h +++ b/include/seat.h @@ -14,6 +14,8 @@ struct seat { struct wl_listener request_set_selection; struct wl_listener request_set_primary_selection; + bool allow_set_cursor; + GPtrArray *devices; }; @@ -21,7 +23,7 @@ struct seat_device { struct seat *seat; struct input_device *input_device; struct keyboard *keyboard; - struct sway_tablet *tablet; + struct tablet *tablet; }; struct pointer_constraint { diff --git a/include/server.h b/include/server.h index 74b7adde..57ed4a99 100644 --- a/include/server.h +++ b/include/server.h @@ -38,6 +38,8 @@ struct server { struct wlr_layer_shell_v1 *layer_shell; struct wlr_xdg_decoration_manager_v1 *xdeco_mgr; + struct wlr_tablet_manager_v2 *tablet_v2; + struct input_manager *input_manager; struct event_handler *event_handler; diff --git a/include/tablet.h b/include/tablet.h index 7fd11e2f..5bc8910e 100644 --- a/include/tablet.h +++ b/include/tablet.h @@ -2,36 +2,36 @@ #define _JAPOKWM_INPUT_TABLET_H #include -struct sway_seat; +struct seat; struct wlr_tablet_tool; -struct sway_tablet { +struct tablet { struct wl_list link; - struct sway_seat_device *seat_device; + struct seat_device *seat_device; struct wlr_tablet_v2_tablet *tablet_v2; }; -enum sway_tablet_tool_mode { - SWAY_TABLET_TOOL_MODE_ABSOLUTE, - SWAY_TABLET_TOOL_MODE_RELATIVE, +enum tablet_tool_mode { + TABLET_TOOL_MODE_ABSOLUTE, + TABLET_TOOL_MODE_RELATIVE, }; -struct sway_tablet_tool { - struct sway_seat *seat; - struct sway_tablet *tablet; +struct tablet_tool { + struct seat *seat; + struct tablet *tablet; struct wlr_tablet_v2_tablet_tool *tablet_v2_tool; - enum sway_tablet_tool_mode mode; + enum tablet_tool_mode mode; double tilt_x, tilt_y; struct wl_listener set_cursor; struct wl_listener tool_destroy; }; -struct sway_tablet_pad { +struct tablet_pad { struct wl_list link; - struct sway_seat_device *seat_device; - struct sway_tablet *tablet; + struct seat_device *seat_device; + struct tablet *tablet; struct wlr_tablet_v2_tablet_pad *tablet_v2_pad; struct wl_listener attach; @@ -45,24 +45,24 @@ struct sway_tablet_pad { struct wl_listener tablet_destroy; }; -struct sway_tablet *sway_tablet_create(struct sway_seat *seat, - struct sway_seat_device *device); +struct tablet *tablet_create(struct seat *seat, + struct seat_device *device); -void sway_configure_tablet(struct sway_tablet *tablet); +void configure_tablet(struct tablet *tablet); -void sway_tablet_destroy(struct sway_tablet *tablet); +void tablet_destroy(struct tablet *tablet); -void sway_tablet_tool_configure(struct sway_tablet *tablet, +void tablet_tool_configure(struct tablet *tablet, struct wlr_tablet_tool *wlr_tool); -struct sway_tablet_pad *sway_tablet_pad_create(struct sway_seat *seat, - struct sway_seat_device *device); +struct tablet_pad *tablet_pad_create(struct seat *seat, + struct seat_device *device); -void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad); +void configure_tablet_pad(struct tablet_pad *tablet_pad); -void sway_tablet_pad_destroy(struct sway_tablet_pad *tablet_pad); +void tablet_pad_destroy(struct tablet_pad *tablet_pad); -void sway_tablet_pad_notify_enter(struct sway_tablet_pad *tablet_pad, +void tablet_pad_notify_enter(struct tablet_pad *tablet_pad, struct wlr_surface *surface); #endif diff --git a/src/seat.c b/src/seat.c index ae3e9dea..ec91aa8e 100644 --- a/src/seat.c +++ b/src/seat.c @@ -12,6 +12,7 @@ #include "server.h" #include "utils/coreUtils.h" #include "keyboard.h" +#include "tablet.h" static void handle_set_selection(struct wl_listener *listener, void *data) { @@ -214,15 +215,15 @@ static void seat_configure_keyboard(struct seat *seat, } static void seat_configure_tablet_tool(struct seat *seat, - struct seat_device *device) { - if (!device->tablet) { - device->tablet = sway_tablet_create(seat, device); - } - sway_configure_tablet(device->tablet); + struct seat_device *device) { + if (!device->tablet) { + device->tablet = tablet_create(seat, device); + } + configure_tablet(device->tablet); // TODO we only need this - wlr_cursor_attach_input_device(seat->cursor->cursor, - device->input_device->wlr_device); - // seat_apply_input_config(seat, sway_device); + wlr_cursor_attach_input_device(seat->cursor->wlr_cursor, + device->input_device->wlr_device); + // seat_apply_input_config(seat, sway_device); } @@ -240,9 +241,9 @@ void seat_configure_device(struct seat *seat, case WLR_INPUT_DEVICE_KEYBOARD: seat_configure_keyboard(seat, seat_device); break; - case WLR_INPUT_DEVICE_TABLET_TOOL: - seat_configure_tablet_tool(seat, seat_device); - break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + seat_configure_tablet_tool(seat, seat_device); + break; default: break; } diff --git a/src/tablet.c b/src/tablet.c index 26e86e36..bfd95dcc 100644 --- a/src/tablet.c +++ b/src/tablet.c @@ -4,13 +4,13 @@ #include #include #include -#include "log.h" -#include "sway/input/cursor.h" -#include "sway/input/seat.h" -#include "sway/input/tablet.h" +#include "cursor.h" +#include "seat.h" +#include "tablet.h" +#include "server.h" static void handle_pad_tablet_destroy(struct wl_listener *listener, void *data) { - struct sway_tablet_pad *pad = + struct tablet_pad *pad = wl_container_of(listener, pad, tablet_destroy); pad->tablet = NULL; @@ -19,9 +19,10 @@ static void handle_pad_tablet_destroy(struct wl_listener *listener, void *data) wl_list_init(&pad->tablet_destroy.link); } -static void attach_tablet_pad(struct sway_tablet_pad *tablet_pad, - struct sway_tablet *tablet) { - sway_log(SWAY_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", +static void attach_tablet_pad(struct tablet_pad *tablet_pad, + struct tablet *tablet) { + + printf( "Attaching tablet pad \"%s\" to tablet tool \"%s\"", tablet_pad->seat_device->input_device->wlr_device->name, tablet->seat_device->input_device->wlr_device->name); @@ -33,13 +34,15 @@ static void attach_tablet_pad(struct sway_tablet_pad *tablet_pad, &tablet_pad->tablet_destroy); } -struct sway_tablet *sway_tablet_create(struct sway_seat *seat, - struct sway_seat_device *device) { - struct sway_tablet *tablet = - calloc(1, sizeof(struct sway_tablet)); - if (!sway_assert(tablet, "could not allocate sway tablet for seat")) { - return NULL; - } +struct tablet *tablet_create(struct seat *seat, + struct seat_device *device) { + struct tablet *tablet = + calloc(1, sizeof(struct tablet)); + + // // TODO: replace me + // if (!assert(tablet, "could not allocate sway tablet for seat")) { + // return NULL; + // } wl_list_insert(&seat->cursor->tablets, &tablet->link); @@ -49,10 +52,10 @@ struct sway_tablet *sway_tablet_create(struct sway_seat *seat, return tablet; } -void sway_configure_tablet(struct sway_tablet *tablet) { +void configure_tablet(struct tablet *tablet) { struct wlr_input_device *device = tablet->seat_device->input_device->wlr_device; - struct sway_seat *seat = tablet->seat_device->sway_seat; + struct seat *seat = tablet->seat_device->seat; if ((seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER) == 0) { seat_configure_xcursor(seat); @@ -71,7 +74,7 @@ void sway_configure_tablet(struct sway_tablet *tablet) { struct libinput_device_group *group = libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); - struct sway_tablet_pad *tablet_pad; + struct tablet_pad *tablet_pad; wl_list_for_each(tablet_pad, &seat->cursor->tablet_pads, link) { struct wlr_input_device *pad_device = tablet_pad->seat_device->input_device->wlr_device; @@ -89,7 +92,7 @@ void sway_configure_tablet(struct sway_tablet *tablet) { } } -void sway_tablet_destroy(struct sway_tablet *tablet) { +void tablet_destroy(struct tablet *tablet) { if (!tablet) { return; } @@ -98,12 +101,12 @@ void sway_tablet_destroy(struct sway_tablet *tablet) { } static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { - struct sway_tablet_tool *tool = + struct tablet_tool *tool = wl_container_of(listener, tool, set_cursor); struct wlr_tablet_v2_event_cursor *event = data; - struct sway_cursor *cursor = tool->seat->cursor; - if (!seatop_allows_set_cursor(cursor->seat)) { + struct cursor *cursor = tool->seat->cursor; + if (!cursor->seat->allow_set_cursor) { return; } @@ -116,7 +119,7 @@ static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *da // TODO: check cursor mode if (focused_client == NULL || event->seat_client->client != focused_client) { - sway_log(SWAY_DEBUG, "denying request to set cursor from unfocused client"); + printf("denying request to set cursor from unfocused client"); return; } @@ -125,7 +128,7 @@ static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *da } static void handle_tablet_tool_destroy(struct wl_listener *listener, void *data) { - struct sway_tablet_tool *tool = + struct tablet_tool *tool = wl_container_of(listener, tool, tool_destroy); wl_list_remove(&tool->tool_destroy.link); @@ -134,42 +137,43 @@ static void handle_tablet_tool_destroy(struct wl_listener *listener, void *data) free(tool); } -void sway_tablet_tool_configure(struct sway_tablet *tablet, +void tablet_tool_configure(struct tablet *tablet, struct wlr_tablet_tool *wlr_tool) { - struct sway_tablet_tool *tool = - calloc(1, sizeof(struct sway_tablet_tool)); - if (!sway_assert(tool, "could not allocate sway tablet tool for tablet")) { + struct tablet_tool *tool = + calloc(1, sizeof(struct tablet_tool)); + if (!tool) { return; } switch (wlr_tool->type) { case WLR_TABLET_TOOL_TYPE_LENS: case WLR_TABLET_TOOL_TYPE_MOUSE: - tool->mode = SWAY_TABLET_TOOL_MODE_RELATIVE; + tool->mode = TABLET_TOOL_MODE_RELATIVE; break; default: - tool->mode = SWAY_TABLET_TOOL_MODE_ABSOLUTE; - - struct input_config *ic = input_device_get_config( - tablet->seat_device->input_device); - if (!ic) { - break; - } - - for (int i = 0; i < ic->tools->length; i++) { - struct input_config_tool *tool_config = ic->tools->items[i]; - if (tool_config->type == wlr_tool->type) { - tool->mode = tool_config->mode; - break; - } - } + tool->mode = TABLET_TOOL_MODE_ABSOLUTE; + + // TODO: add input config to tablets? + // struct input_config *ic = input_device_get_config( + // tablet->seat_device->input_device); + // if (!ic) { + // break; + // } + // + // for (int i = 0; i < ic->tools->length; i++) { + // struct input_config_tool *tool_config = ic->tools->items[i]; + // if (tool_config->type == wlr_tool->type) { + // tool->mode = tool_config->mode; + // break; + // } + // } } - tool->seat = tablet->seat_device->sway_seat; + tool->seat = tablet->seat_device->seat; tool->tablet = tablet; tool->tablet_v2_tool = wlr_tablet_tool_create(server.tablet_v2, - tablet->seat_device->sway_seat->wlr_seat, wlr_tool); + tablet->seat_device->seat->wlr_seat, wlr_tool); tool->tool_destroy.notify = handle_tablet_tool_destroy; wl_signal_add(&wlr_tool->events.destroy, &tool->tool_destroy); @@ -183,9 +187,9 @@ void sway_tablet_tool_configure(struct sway_tablet *tablet, static void handle_tablet_pad_attach(struct wl_listener *listener, void *data) { - struct sway_tablet_pad *pad = wl_container_of(listener, pad, attach); + struct tablet_pad *pad = wl_container_of(listener, pad, attach); struct wlr_tablet_tool *wlr_tool = data; - struct sway_tablet_tool *tool = wlr_tool->data; + struct tablet_tool *tool = wlr_tool->data; if (!tool) { return; @@ -195,7 +199,7 @@ static void handle_tablet_pad_attach(struct wl_listener *listener, } static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { - struct sway_tablet_pad *pad = wl_container_of(listener, pad, ring); + struct tablet_pad *pad = wl_container_of(listener, pad, ring); struct wlr_event_tablet_pad_ring *event = data; if (!pad->current_surface) { @@ -209,7 +213,7 @@ static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { } static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { - struct sway_tablet_pad *pad = wl_container_of(listener, pad, strip); + struct tablet_pad *pad = wl_container_of(listener, pad, strip); struct wlr_event_tablet_pad_strip *event = data; if (!pad->current_surface) { @@ -223,7 +227,7 @@ static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { } static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { - struct sway_tablet_pad *pad = wl_container_of(listener, pad, button); + struct tablet_pad *pad = wl_container_of(listener, pad, button); struct wlr_event_tablet_pad_button *event = data; if (!pad->current_surface) { @@ -238,11 +242,11 @@ static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { (enum zwp_tablet_pad_v2_button_state)event->state); } -struct sway_tablet_pad *sway_tablet_pad_create(struct sway_seat *seat, - struct sway_seat_device *device) { - struct sway_tablet_pad *tablet_pad = - calloc(1, sizeof(struct sway_tablet_pad)); - if (!sway_assert(tablet_pad, "could not allocate sway tablet")) { +struct tablet_pad *tablet_pad_create(struct seat *seat, + struct seat_device *device) { + struct tablet_pad *tablet_pad = + calloc(1, sizeof(struct tablet_pad)); + if (!printf("could not allocate sway tablet")) { return NULL; } @@ -259,10 +263,10 @@ struct sway_tablet_pad *sway_tablet_pad_create(struct sway_seat *seat, return tablet_pad; } -void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad) { +void configure_tablet_pad(struct tablet_pad *tablet_pad) { struct wlr_input_device *device = tablet_pad->seat_device->input_device->wlr_device; - struct sway_seat *seat = tablet_pad->seat_device->sway_seat; + struct seat *seat = tablet_pad->seat_device->seat; if (!tablet_pad->tablet_v2_pad) { tablet_pad->tablet_v2_pad = @@ -294,7 +298,7 @@ void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad) { struct libinput_device_group *group = libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); - struct sway_tablet *tool; + struct tablet *tool; wl_list_for_each(tool, &seat->cursor->tablets, link) { struct wlr_input_device *tablet = tool->seat_device->input_device->wlr_device; @@ -312,7 +316,7 @@ void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad) { } } -void sway_tablet_pad_destroy(struct sway_tablet_pad *tablet_pad) { +void tablet_pad_destroy(struct tablet_pad *tablet_pad) { if (!tablet_pad) { return; } @@ -330,7 +334,7 @@ void sway_tablet_pad_destroy(struct sway_tablet_pad *tablet_pad) { static void handle_pad_tablet_surface_destroy(struct wl_listener *listener, void *data) { - struct sway_tablet_pad *tablet_pad = + struct tablet_pad *tablet_pad = wl_container_of(listener, tablet_pad, surface_destroy); wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad->tablet_v2_pad, @@ -340,7 +344,7 @@ static void handle_pad_tablet_surface_destroy(struct wl_listener *listener, tablet_pad->current_surface = NULL; } -void sway_tablet_pad_notify_enter(struct sway_tablet_pad *tablet_pad, +void tablet_pad_notify_enter(struct tablet_pad *tablet_pad, struct wlr_surface *surface) { if (!tablet_pad || !tablet_pad->tablet) { return; From f11e0ebc8346b8d5461a45fcc895969e0a6613ba Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 18 Nov 2022 00:09:24 +0100 Subject: [PATCH 89/93] feat: add tablet support --- src/cursor.c | 2 + src/server.c | 2 + src/tablet.c | 586 +++++++++++++++++++++++++-------------------------- 3 files changed, 297 insertions(+), 293 deletions(-) diff --git a/src/cursor.c b/src/cursor.c index ce1fc77f..875c1557 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -172,6 +172,8 @@ struct cursor *create_cursor(struct seat *seat) LISTEN(&seat->wlr_seat->events.request_set_cursor, &cursor->request_set_cursor, handle_set_cursor); wl_list_init(&cursor->constraint_commit.link); + wl_list_init(&cursor->tablets); + wl_list_init(&cursor->tablet_pads); return cursor; } diff --git a/src/server.c b/src/server.c index 9432a037..99eba9fd 100644 --- a/src/server.c +++ b/src/server.c @@ -467,6 +467,8 @@ int setup_server(struct server *server) wl_signal_add(&server->output_mgr->events.apply, &server->output_mgr_apply); wl_signal_add(&server->output_mgr->events.test, &server->output_mgr_test); + server->tablet_v2 = wlr_tablet_v2_create(server->wl_display); + #ifdef JAPOKWM_HAS_XWAYLAND init_xwayland(server->wl_display, seat); #endif diff --git a/src/tablet.c b/src/tablet.c index bfd95dcc..40176326 100644 --- a/src/tablet.c +++ b/src/tablet.c @@ -10,368 +10,368 @@ #include "server.h" static void handle_pad_tablet_destroy(struct wl_listener *listener, void *data) { - struct tablet_pad *pad = - wl_container_of(listener, pad, tablet_destroy); + struct tablet_pad *pad = + wl_container_of(listener, pad, tablet_destroy); - pad->tablet = NULL; + pad->tablet = NULL; - wl_list_remove(&pad->tablet_destroy.link); - wl_list_init(&pad->tablet_destroy.link); + wl_list_remove(&pad->tablet_destroy.link); + wl_list_init(&pad->tablet_destroy.link); } static void attach_tablet_pad(struct tablet_pad *tablet_pad, - struct tablet *tablet) { - + struct tablet *tablet) { + printf( "Attaching tablet pad \"%s\" to tablet tool \"%s\"", - tablet_pad->seat_device->input_device->wlr_device->name, - tablet->seat_device->input_device->wlr_device->name); + tablet_pad->seat_device->input_device->wlr_device->name, + tablet->seat_device->input_device->wlr_device->name); - tablet_pad->tablet = tablet; + tablet_pad->tablet = tablet; - wl_list_remove(&tablet_pad->tablet_destroy.link); - tablet_pad->tablet_destroy.notify = handle_pad_tablet_destroy; - wl_signal_add(&tablet->seat_device->input_device->wlr_device->events.destroy, - &tablet_pad->tablet_destroy); + wl_list_remove(&tablet_pad->tablet_destroy.link); + tablet_pad->tablet_destroy.notify = handle_pad_tablet_destroy; + wl_signal_add(&tablet->seat_device->input_device->wlr_device->events.destroy, + &tablet_pad->tablet_destroy); } struct tablet *tablet_create(struct seat *seat, - struct seat_device *device) { - struct tablet *tablet = - calloc(1, sizeof(struct tablet)); + struct seat_device *device) { + struct tablet *tablet = + calloc(1, sizeof(struct tablet)); // // TODO: replace me - // if (!assert(tablet, "could not allocate sway tablet for seat")) { - // return NULL; - // } + // if (!assert(tablet, "could not allocate sway tablet for seat")) { + // return NULL; + // } - wl_list_insert(&seat->cursor->tablets, &tablet->link); + wl_list_insert(&seat->cursor->tablets, &tablet->link); - device->tablet = tablet; - tablet->seat_device = device; + device->tablet = tablet; + tablet->seat_device = device; - return tablet; + return tablet; } void configure_tablet(struct tablet *tablet) { - struct wlr_input_device *device = - tablet->seat_device->input_device->wlr_device; - struct seat *seat = tablet->seat_device->seat; - - if ((seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER) == 0) { - seat_configure_xcursor(seat); - } - - if (!tablet->tablet_v2) { - tablet->tablet_v2 = - wlr_tablet_create(server.tablet_v2, seat->wlr_seat, device); - } - - /* Search for a sibling tablet pad */ - if (!wlr_input_device_is_libinput(device)) { - /* We can only do this on libinput devices */ - return; - } - - struct libinput_device_group *group = - libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); - struct tablet_pad *tablet_pad; - wl_list_for_each(tablet_pad, &seat->cursor->tablet_pads, link) { - struct wlr_input_device *pad_device = - tablet_pad->seat_device->input_device->wlr_device; - if (!wlr_input_device_is_libinput(pad_device)) { - continue; - } - - struct libinput_device_group *pad_group = - libinput_device_get_device_group(wlr_libinput_get_device_handle(pad_device)); - - if (pad_group == group) { - attach_tablet_pad(tablet_pad, tablet); - break; - } - } + struct wlr_input_device *device = + tablet->seat_device->input_device->wlr_device; + struct seat *seat = tablet->seat_device->seat; + + if ((seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER) == 0) { + seat_configure_xcursor(seat); + } + + if (!tablet->tablet_v2) { + tablet->tablet_v2 = + wlr_tablet_create(server.tablet_v2, seat->wlr_seat, device); + } + + /* Search for a sibling tablet pad */ + if (!wlr_input_device_is_libinput(device)) { + /* We can only do this on libinput devices */ + return; + } + + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct tablet_pad *tablet_pad; + wl_list_for_each(tablet_pad, &seat->cursor->tablet_pads, link) { + struct wlr_input_device *pad_device = + tablet_pad->seat_device->input_device->wlr_device; + if (!wlr_input_device_is_libinput(pad_device)) { + continue; + } + + struct libinput_device_group *pad_group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(pad_device)); + + if (pad_group == group) { + attach_tablet_pad(tablet_pad, tablet); + break; + } + } } void tablet_destroy(struct tablet *tablet) { - if (!tablet) { - return; - } - wl_list_remove(&tablet->link); - free(tablet); + if (!tablet) { + return; + } + wl_list_remove(&tablet->link); + free(tablet); } static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { - struct tablet_tool *tool = - wl_container_of(listener, tool, set_cursor); - struct wlr_tablet_v2_event_cursor *event = data; - - struct cursor *cursor = tool->seat->cursor; - if (!cursor->seat->allow_set_cursor) { - return; - } - - struct wl_client *focused_client = NULL; - struct wlr_surface *focused_surface = tool->tablet_v2_tool->focused_surface; - if (focused_surface != NULL) { - focused_client = wl_resource_get_client(focused_surface->resource); - } - - // TODO: check cursor mode - if (focused_client == NULL || - event->seat_client->client != focused_client) { - printf("denying request to set cursor from unfocused client"); - return; - } - - cursor_set_image_surface(cursor, event->surface, event->hotspot_x, - event->hotspot_y, focused_client); + struct tablet_tool *tool = + wl_container_of(listener, tool, set_cursor); + struct wlr_tablet_v2_event_cursor *event = data; + + struct cursor *cursor = tool->seat->cursor; + if (!cursor->seat->allow_set_cursor) { + return; + } + + struct wl_client *focused_client = NULL; + struct wlr_surface *focused_surface = tool->tablet_v2_tool->focused_surface; + if (focused_surface != NULL) { + focused_client = wl_resource_get_client(focused_surface->resource); + } + + // TODO: check cursor mode + if (focused_client == NULL || + event->seat_client->client != focused_client) { + printf("denying request to set cursor from unfocused client"); + return; + } + + cursor_set_image_surface(cursor, event->surface, event->hotspot_x, + event->hotspot_y, focused_client); } static void handle_tablet_tool_destroy(struct wl_listener *listener, void *data) { - struct tablet_tool *tool = - wl_container_of(listener, tool, tool_destroy); + struct tablet_tool *tool = + wl_container_of(listener, tool, tool_destroy); - wl_list_remove(&tool->tool_destroy.link); - wl_list_remove(&tool->set_cursor.link); + wl_list_remove(&tool->tool_destroy.link); + wl_list_remove(&tool->set_cursor.link); - free(tool); + free(tool); } void tablet_tool_configure(struct tablet *tablet, - struct wlr_tablet_tool *wlr_tool) { - struct tablet_tool *tool = - calloc(1, sizeof(struct tablet_tool)); - if (!tool) { - return; - } - - switch (wlr_tool->type) { - case WLR_TABLET_TOOL_TYPE_LENS: - case WLR_TABLET_TOOL_TYPE_MOUSE: - tool->mode = TABLET_TOOL_MODE_RELATIVE; - break; - default: - tool->mode = TABLET_TOOL_MODE_ABSOLUTE; + struct wlr_tablet_tool *wlr_tool) { + struct tablet_tool *tool = + calloc(1, sizeof(struct tablet_tool)); + if (!tool) { + return; + } + + switch (wlr_tool->type) { + case WLR_TABLET_TOOL_TYPE_LENS: + case WLR_TABLET_TOOL_TYPE_MOUSE: + tool->mode = TABLET_TOOL_MODE_RELATIVE; + break; + default: + tool->mode = TABLET_TOOL_MODE_ABSOLUTE; // TODO: add input config to tablets? - // struct input_config *ic = input_device_get_config( - // tablet->seat_device->input_device); - // if (!ic) { - // break; - // } - // - // for (int i = 0; i < ic->tools->length; i++) { - // struct input_config_tool *tool_config = ic->tools->items[i]; - // if (tool_config->type == wlr_tool->type) { - // tool->mode = tool_config->mode; - // break; - // } - // } - } - - tool->seat = tablet->seat_device->seat; - tool->tablet = tablet; - tool->tablet_v2_tool = - wlr_tablet_tool_create(server.tablet_v2, - tablet->seat_device->seat->wlr_seat, wlr_tool); - - tool->tool_destroy.notify = handle_tablet_tool_destroy; - wl_signal_add(&wlr_tool->events.destroy, &tool->tool_destroy); - - tool->set_cursor.notify = handle_tablet_tool_set_cursor; - wl_signal_add(&tool->tablet_v2_tool->events.set_cursor, - &tool->set_cursor); - - wlr_tool->data = tool; + // struct input_config *ic = input_device_get_config( + // tablet->seat_device->input_device); + // if (!ic) { + // break; + // } + // + // for (int i = 0; i < ic->tools->length; i++) { + // struct input_config_tool *tool_config = ic->tools->items[i]; + // if (tool_config->type == wlr_tool->type) { + // tool->mode = tool_config->mode; + // break; + // } + // } + } + + tool->seat = tablet->seat_device->seat; + tool->tablet = tablet; + tool->tablet_v2_tool = + wlr_tablet_tool_create(server.tablet_v2, + tablet->seat_device->seat->wlr_seat, wlr_tool); + + tool->tool_destroy.notify = handle_tablet_tool_destroy; + wl_signal_add(&wlr_tool->events.destroy, &tool->tool_destroy); + + tool->set_cursor.notify = handle_tablet_tool_set_cursor; + wl_signal_add(&tool->tablet_v2_tool->events.set_cursor, + &tool->set_cursor); + + wlr_tool->data = tool; } static void handle_tablet_pad_attach(struct wl_listener *listener, - void *data) { - struct tablet_pad *pad = wl_container_of(listener, pad, attach); - struct wlr_tablet_tool *wlr_tool = data; - struct tablet_tool *tool = wlr_tool->data; + void *data) { + struct tablet_pad *pad = wl_container_of(listener, pad, attach); + struct wlr_tablet_tool *wlr_tool = data; + struct tablet_tool *tool = wlr_tool->data; - if (!tool) { - return; - } + if (!tool) { + return; + } - attach_tablet_pad(pad, tool->tablet); + attach_tablet_pad(pad, tool->tablet); } static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { - struct tablet_pad *pad = wl_container_of(listener, pad, ring); - struct wlr_event_tablet_pad_ring *event = data; + struct tablet_pad *pad = wl_container_of(listener, pad, ring); + struct wlr_event_tablet_pad_ring *event = data; - if (!pad->current_surface) { - return; - } + if (!pad->current_surface) { + return; + } - wlr_tablet_v2_tablet_pad_notify_ring(pad->tablet_v2_pad, - event->ring, event->position, - event->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, - event->time_msec); + wlr_tablet_v2_tablet_pad_notify_ring(pad->tablet_v2_pad, + event->ring, event->position, + event->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, + event->time_msec); } static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { - struct tablet_pad *pad = wl_container_of(listener, pad, strip); - struct wlr_event_tablet_pad_strip *event = data; + struct tablet_pad *pad = wl_container_of(listener, pad, strip); + struct wlr_event_tablet_pad_strip *event = data; - if (!pad->current_surface) { - return; - } + if (!pad->current_surface) { + return; + } - wlr_tablet_v2_tablet_pad_notify_strip(pad->tablet_v2_pad, - event->strip, event->position, - event->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, - event->time_msec); + wlr_tablet_v2_tablet_pad_notify_strip(pad->tablet_v2_pad, + event->strip, event->position, + event->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, + event->time_msec); } static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { - struct tablet_pad *pad = wl_container_of(listener, pad, button); - struct wlr_event_tablet_pad_button *event = data; + struct tablet_pad *pad = wl_container_of(listener, pad, button); + struct wlr_event_tablet_pad_button *event = data; - if (!pad->current_surface) { - return; - } + if (!pad->current_surface) { + return; + } - wlr_tablet_v2_tablet_pad_notify_mode(pad->tablet_v2_pad, - event->group, event->mode, event->time_msec); + wlr_tablet_v2_tablet_pad_notify_mode(pad->tablet_v2_pad, + event->group, event->mode, event->time_msec); - wlr_tablet_v2_tablet_pad_notify_button(pad->tablet_v2_pad, - event->button, event->time_msec, - (enum zwp_tablet_pad_v2_button_state)event->state); + wlr_tablet_v2_tablet_pad_notify_button(pad->tablet_v2_pad, + event->button, event->time_msec, + (enum zwp_tablet_pad_v2_button_state)event->state); } struct tablet_pad *tablet_pad_create(struct seat *seat, - struct seat_device *device) { - struct tablet_pad *tablet_pad = - calloc(1, sizeof(struct tablet_pad)); - if (!printf("could not allocate sway tablet")) { - return NULL; - } - - tablet_pad->seat_device = device; - wl_list_init(&tablet_pad->attach.link); - wl_list_init(&tablet_pad->button.link); - wl_list_init(&tablet_pad->strip.link); - wl_list_init(&tablet_pad->ring.link); - wl_list_init(&tablet_pad->surface_destroy.link); - wl_list_init(&tablet_pad->tablet_destroy.link); - - wl_list_insert(&seat->cursor->tablet_pads, &tablet_pad->link); - - return tablet_pad; + struct seat_device *device) { + struct tablet_pad *tablet_pad = + calloc(1, sizeof(struct tablet_pad)); + if (!printf("could not allocate sway tablet")) { + return NULL; + } + + tablet_pad->seat_device = device; + wl_list_init(&tablet_pad->attach.link); + wl_list_init(&tablet_pad->button.link); + wl_list_init(&tablet_pad->strip.link); + wl_list_init(&tablet_pad->ring.link); + wl_list_init(&tablet_pad->surface_destroy.link); + wl_list_init(&tablet_pad->tablet_destroy.link); + + wl_list_insert(&seat->cursor->tablet_pads, &tablet_pad->link); + + return tablet_pad; } void configure_tablet_pad(struct tablet_pad *tablet_pad) { - struct wlr_input_device *device = - tablet_pad->seat_device->input_device->wlr_device; - struct seat *seat = tablet_pad->seat_device->seat; - - if (!tablet_pad->tablet_v2_pad) { - tablet_pad->tablet_v2_pad = - wlr_tablet_pad_create(server.tablet_v2, seat->wlr_seat, device); - } - - wl_list_remove(&tablet_pad->attach.link); - tablet_pad->attach.notify = handle_tablet_pad_attach; - wl_signal_add(&device->tablet_pad->events.attach_tablet, - &tablet_pad->attach); - - wl_list_remove(&tablet_pad->button.link); - tablet_pad->button.notify = handle_tablet_pad_button; - wl_signal_add(&device->tablet_pad->events.button, &tablet_pad->button); - - wl_list_remove(&tablet_pad->strip.link); - tablet_pad->strip.notify = handle_tablet_pad_strip; - wl_signal_add(&device->tablet_pad->events.strip, &tablet_pad->strip); - - wl_list_remove(&tablet_pad->ring.link); - tablet_pad->ring.notify = handle_tablet_pad_ring; - wl_signal_add(&device->tablet_pad->events.ring, &tablet_pad->ring); - - /* Search for a sibling tablet */ - if (!wlr_input_device_is_libinput(device)) { - /* We can only do this on libinput devices */ - return; - } - - struct libinput_device_group *group = - libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); - struct tablet *tool; - wl_list_for_each(tool, &seat->cursor->tablets, link) { - struct wlr_input_device *tablet = - tool->seat_device->input_device->wlr_device; - if (!wlr_input_device_is_libinput(tablet)) { - continue; - } - - struct libinput_device_group *tablet_group = - libinput_device_get_device_group(wlr_libinput_get_device_handle(tablet)); - - if (tablet_group == group) { - attach_tablet_pad(tablet_pad, tool); - break; - } - } + struct wlr_input_device *device = + tablet_pad->seat_device->input_device->wlr_device; + struct seat *seat = tablet_pad->seat_device->seat; + + if (!tablet_pad->tablet_v2_pad) { + tablet_pad->tablet_v2_pad = + wlr_tablet_pad_create(server.tablet_v2, seat->wlr_seat, device); + } + + wl_list_remove(&tablet_pad->attach.link); + tablet_pad->attach.notify = handle_tablet_pad_attach; + wl_signal_add(&device->tablet_pad->events.attach_tablet, + &tablet_pad->attach); + + wl_list_remove(&tablet_pad->button.link); + tablet_pad->button.notify = handle_tablet_pad_button; + wl_signal_add(&device->tablet_pad->events.button, &tablet_pad->button); + + wl_list_remove(&tablet_pad->strip.link); + tablet_pad->strip.notify = handle_tablet_pad_strip; + wl_signal_add(&device->tablet_pad->events.strip, &tablet_pad->strip); + + wl_list_remove(&tablet_pad->ring.link); + tablet_pad->ring.notify = handle_tablet_pad_ring; + wl_signal_add(&device->tablet_pad->events.ring, &tablet_pad->ring); + + /* Search for a sibling tablet */ + if (!wlr_input_device_is_libinput(device)) { + /* We can only do this on libinput devices */ + return; + } + + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct tablet *tool; + wl_list_for_each(tool, &seat->cursor->tablets, link) { + struct wlr_input_device *tablet = + tool->seat_device->input_device->wlr_device; + if (!wlr_input_device_is_libinput(tablet)) { + continue; + } + + struct libinput_device_group *tablet_group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(tablet)); + + if (tablet_group == group) { + attach_tablet_pad(tablet_pad, tool); + break; + } + } } void tablet_pad_destroy(struct tablet_pad *tablet_pad) { - if (!tablet_pad) { - return; - } - - wl_list_remove(&tablet_pad->link); - wl_list_remove(&tablet_pad->attach.link); - wl_list_remove(&tablet_pad->button.link); - wl_list_remove(&tablet_pad->strip.link); - wl_list_remove(&tablet_pad->ring.link); - wl_list_remove(&tablet_pad->surface_destroy.link); - wl_list_remove(&tablet_pad->tablet_destroy.link); - - free(tablet_pad); + if (!tablet_pad) { + return; + } + + wl_list_remove(&tablet_pad->link); + wl_list_remove(&tablet_pad->attach.link); + wl_list_remove(&tablet_pad->button.link); + wl_list_remove(&tablet_pad->strip.link); + wl_list_remove(&tablet_pad->ring.link); + wl_list_remove(&tablet_pad->surface_destroy.link); + wl_list_remove(&tablet_pad->tablet_destroy.link); + + free(tablet_pad); } static void handle_pad_tablet_surface_destroy(struct wl_listener *listener, - void *data) { - struct tablet_pad *tablet_pad = - wl_container_of(listener, tablet_pad, surface_destroy); - - wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad->tablet_v2_pad, - tablet_pad->current_surface); - wl_list_remove(&tablet_pad->surface_destroy.link); - wl_list_init(&tablet_pad->surface_destroy.link); - tablet_pad->current_surface = NULL; + void *data) { + struct tablet_pad *tablet_pad = + wl_container_of(listener, tablet_pad, surface_destroy); + + wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad->tablet_v2_pad, + tablet_pad->current_surface); + wl_list_remove(&tablet_pad->surface_destroy.link); + wl_list_init(&tablet_pad->surface_destroy.link); + tablet_pad->current_surface = NULL; } void tablet_pad_notify_enter(struct tablet_pad *tablet_pad, - struct wlr_surface *surface) { - if (!tablet_pad || !tablet_pad->tablet) { - return; - } - - if (surface == tablet_pad->current_surface) { - return; - } - - /* Leave current surface */ - if (tablet_pad->current_surface) { - wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad->tablet_v2_pad, - tablet_pad->current_surface); - wl_list_remove(&tablet_pad->surface_destroy.link); - wl_list_init(&tablet_pad->surface_destroy.link); - tablet_pad->current_surface = NULL; - } - - if (!wlr_surface_accepts_tablet_v2(tablet_pad->tablet->tablet_v2, surface)) { - return; - } - - wlr_tablet_v2_tablet_pad_notify_enter(tablet_pad->tablet_v2_pad, - tablet_pad->tablet->tablet_v2, surface); - - tablet_pad->current_surface = surface; - wl_list_remove(&tablet_pad->surface_destroy.link); - tablet_pad->surface_destroy.notify = handle_pad_tablet_surface_destroy; - wl_signal_add(&surface->events.destroy, &tablet_pad->surface_destroy); + struct wlr_surface *surface) { + if (!tablet_pad || !tablet_pad->tablet) { + return; + } + + if (surface == tablet_pad->current_surface) { + return; + } + + /* Leave current surface */ + if (tablet_pad->current_surface) { + wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad->tablet_v2_pad, + tablet_pad->current_surface); + wl_list_remove(&tablet_pad->surface_destroy.link); + wl_list_init(&tablet_pad->surface_destroy.link); + tablet_pad->current_surface = NULL; + } + + if (!wlr_surface_accepts_tablet_v2(tablet_pad->tablet->tablet_v2, surface)) { + return; + } + + wlr_tablet_v2_tablet_pad_notify_enter(tablet_pad->tablet_v2_pad, + tablet_pad->tablet->tablet_v2, surface); + + tablet_pad->current_surface = surface; + wl_list_remove(&tablet_pad->surface_destroy.link); + tablet_pad->surface_destroy.notify = handle_pad_tablet_surface_destroy; + wl_signal_add(&surface->events.destroy, &tablet_pad->surface_destroy); } From fd628702fc393237670ca080071d3194a77c30e2 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 18 Nov 2022 00:25:58 +0100 Subject: [PATCH 90/93] feat: fix stuff related to tablet --- include/seat.h | 3 ++- src/seat.c | 12 ++++++++++++ src/tablet.c | 1 - 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/seat.h b/include/seat.h index 0fc1ad78..7feb00bb 100644 --- a/include/seat.h +++ b/include/seat.h @@ -23,7 +23,8 @@ struct seat_device { struct seat *seat; struct input_device *input_device; struct keyboard *keyboard; - struct tablet *tablet; + struct tablet *tablet; + struct tablet_pad *tablet_pad; }; struct pointer_constraint { diff --git a/src/seat.c b/src/seat.c index ec91aa8e..b3b057da 100644 --- a/src/seat.c +++ b/src/seat.c @@ -221,11 +221,20 @@ static void seat_configure_tablet_tool(struct seat *seat, } configure_tablet(device->tablet); // TODO we only need this + printf("attach tablet\n"); wlr_cursor_attach_input_device(seat->cursor->wlr_cursor, device->input_device->wlr_device); // seat_apply_input_config(seat, sway_device); } +static void seat_configure_tablet_pad(struct seat *seat, + struct seat_device *device) { + if (!device->tablet_pad) { + device->tablet_pad = tablet_pad_create(seat, device); + } + configure_tablet_pad(device->tablet_pad); +} + void seat_configure_device(struct seat *seat, struct input_device *input_device) { @@ -244,6 +253,9 @@ void seat_configure_device(struct seat *seat, case WLR_INPUT_DEVICE_TABLET_TOOL: seat_configure_tablet_tool(seat, seat_device); break; + case WLR_INPUT_DEVICE_TABLET_PAD: + seat_configure_tablet_pad(seat, seat_device); + break; default: break; } diff --git a/src/tablet.c b/src/tablet.c index 40176326..bdf70a22 100644 --- a/src/tablet.c +++ b/src/tablet.c @@ -21,7 +21,6 @@ static void handle_pad_tablet_destroy(struct wl_listener *listener, void *data) static void attach_tablet_pad(struct tablet_pad *tablet_pad, struct tablet *tablet) { - printf( "Attaching tablet pad \"%s\" to tablet tool \"%s\"", tablet_pad->seat_device->input_device->wlr_device->name, tablet->seat_device->input_device->wlr_device->name); From d8610586bf6b6451af4aa426330b00a305246a6a Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sun, 15 Jan 2023 22:37:54 +0100 Subject: [PATCH 91/93] update some stuff --- include/client.h | 3 ++- include/cursor.h | 3 ++- include/keyboard.h | 1 + include/surface.h | 3 ++- include/tablet.h | 1 + src/client.c | 8 ++++---- src/cursor.c | 19 ++++++++++--------- src/input_manager.c | 3 +-- src/keyboard.c | 38 ++++++++++++++++++-------------------- src/monitor.c | 4 ++-- src/popup.c | 10 +++++----- src/seat.c | 2 +- src/tablet.c | 15 ++++++++------- 13 files changed, 57 insertions(+), 53 deletions(-) diff --git a/include/client.h b/include/client.h index 21557a16..60d76361 100644 --- a/include/client.h +++ b/include/client.h @@ -3,7 +3,8 @@ #include #include #include -#include +#include +#include #include "bitset/bitset.h" #include "seat.h" diff --git a/include/cursor.h b/include/cursor.h index 0f72f2e3..805b3110 100644 --- a/include/cursor.h +++ b/include/cursor.h @@ -2,7 +2,8 @@ #define CURSOR_H #include -#include +#include +#include #include #include diff --git a/include/keyboard.h b/include/keyboard.h index 9a7987b3..e0fd30b3 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -13,6 +13,7 @@ struct keyboard { struct seat *seat; struct seat_device *seat_device; + struct wlr_keyboard *wlr; int32_t repeat_rate; int32_t repeat_delay; diff --git a/include/surface.h b/include/surface.h index ecc638b3..3c598a09 100644 --- a/include/surface.h +++ b/include/surface.h @@ -1,7 +1,8 @@ #ifndef SURFACE_H #define SURFACE_H #include -#include +#include +#include struct surface { struct wlr_surface *surface; diff --git a/include/tablet.h b/include/tablet.h index 5bc8910e..03d43401 100644 --- a/include/tablet.h +++ b/include/tablet.h @@ -32,6 +32,7 @@ struct tablet_pad { struct wl_list link; struct seat_device *seat_device; struct tablet *tablet; + struct wlr_tablet_pad *wlr; struct wlr_tablet_v2_tablet_pad *tablet_v2_pad; struct wl_listener attach; diff --git a/src/client.c b/src/client.c index 78f7dd8d..945b7d5d 100644 --- a/src/client.c +++ b/src/client.c @@ -87,8 +87,8 @@ static void unfocus_client(struct client *c) return; switch (c->type) { - case XDG_SHELL: - wlr_xdg_toplevel_set_activated(c->surface.xdg, false); + c->surface.xdg; + wlr_xdg_toplevel_set_activated(c->surface.xdg->toplevel, false); break; case X11_MANAGED: case X11_UNMANAGED: @@ -159,7 +159,7 @@ void focus_client(struct seat *seat, struct client *old, struct client *c) /* Activate the new client */ switch (c->type) { case XDG_SHELL: - wlr_xdg_toplevel_set_activated(c->surface.xdg, true); + wlr_xdg_toplevel_set_activated(c->surface.xdg->toplevel, true); break; case X11_MANAGED: case X11_UNMANAGED: @@ -189,7 +189,7 @@ void kill_client(struct client *c) switch (c->type) { case XDG_SHELL: - wlr_xdg_toplevel_send_close(c->surface.xdg); + wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel); break; case LAYER_SHELL: wlr_layer_surface_v1_destroy(c->surface.layer); diff --git a/src/cursor.c b/src/cursor.c index 875c1557..d93f60c9 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "container.h" #include "keybinding.h" @@ -51,7 +52,7 @@ static void handle_axis_notify(struct wl_listener *listener, void *data) struct cursor *cursor = wl_container_of(listener, cursor, axis); /* This event is forwarded by the cursor when a pointer emits an axis event, * for example when you move the scroll wheel. */ - struct wlr_event_pointer_axis *event = data; + struct wlr_pointer_axis_event *event = data; /* Notify the client with pointer focus of the axis event. */ wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, event->orientation, event->delta, @@ -274,27 +275,27 @@ void cursor_handle_activity_from_device(struct cursor *cursor, struct wlr_input_ void handle_motion_relative(struct wl_listener *listener, void *data) { struct cursor *cursor = wl_container_of(listener, cursor, motion); - struct wlr_event_pointer_motion *event = data; - cursor_handle_activity_from_device(cursor, event->device); + struct wlr_pointer_motion_event *event = data; + cursor_handle_activity_from_device(cursor, &event->pointer->base); - motion_notify(cursor, event->time_msec, event->device, event->delta_x, + motion_notify(cursor, event->time_msec, &event->pointer->base, event->delta_x, event->delta_y, event->unaccel_dx, event->unaccel_dy); } void handle_motion_absolute(struct wl_listener *listener, void *data) { struct cursor *cursor = wl_container_of(listener, cursor, motion_absolute); - struct wlr_event_pointer_motion_absolute *event = data; - cursor_handle_activity_from_device(cursor, event->device); + struct wlr_pointer_motion_absolute_event *event = data; + cursor_handle_activity_from_device(cursor, &event->pointer->base); double lx, ly; - wlr_cursor_absolute_to_layout_coords(cursor->wlr_cursor, event->device, + wlr_cursor_absolute_to_layout_coords(cursor->wlr_cursor, &event->pointer->base, event->x, event->y, &lx, &ly); double dx = lx - cursor->wlr_cursor->x; double dy = ly - cursor->wlr_cursor->y; - motion_notify(cursor, event->time_msec, event->device, dx, dy, dx, dy); + motion_notify(cursor, event->time_msec, &event->pointer->base, dx, dy, dx, dy); } void focus_under_cursor(struct cursor *cursor, uint32_t time) @@ -399,7 +400,7 @@ void motion_notify(struct cursor *cursor, uint32_t time_msec, void handle_cursor_button(struct wl_listener *listener, void *data) { struct cursor *cursor = wl_container_of(listener, cursor, button); - struct wlr_event_pointer_button *event = data; + struct wlr_pointer_button_event *event = data; switch (event->state) { case WLR_BUTTON_PRESSED: diff --git a/src/input_manager.c b/src/input_manager.c index 063e6ebc..6ecf6a9e 100644 --- a/src/input_manager.c +++ b/src/input_manager.c @@ -186,7 +186,7 @@ static void handle_new_virtual_pointer(struct wl_listener *listener, void *data) struct wlr_virtual_pointer_v1_new_pointer_event *event = data; struct wlr_virtual_pointer_v1 *pointer = event->new_pointer; - struct wlr_input_device *device = &pointer->input_device; + struct wlr_input_device *device = &pointer->pointer.base; struct seat *seat = event->suggested_seat ? input_manager_seat_from_wlr_seat(event->suggested_seat) : @@ -300,4 +300,3 @@ char *input_device_get_identifier(struct wlr_input_device *device) free(name); return identifier; } - diff --git a/src/keyboard.c b/src/keyboard.c index 44dc527a..1e932b30 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -8,9 +8,7 @@ static bool handle_VT_keys(struct keyboard *kb, uint32_t keycode) { const xkb_keysym_t *syms; - struct wlr_input_device *wlr_device = kb->seat_device->input_device->wlr_device; - int nsyms = - xkb_state_key_get_syms(wlr_device->keyboard->xkb_state, keycode, &syms); + int nsyms = xkb_state_key_get_syms(kb->wlr->xkb_state, keycode, &syms); bool handled = false; for (int i = 0; i < nsyms; i++) { @@ -35,8 +33,7 @@ static bool handle_VT_keys(struct keyboard *kb, uint32_t keycode) static int handle_keyboard_repeat(void *data) { struct keyboard *keyboard = (struct keyboard *)data; - struct wlr_keyboard *wlr_device = - keyboard->seat_device->input_device->wlr_device->keyboard; + struct wlr_keyboard *wlr_device = keyboard->wlr; if (keyboard->repeat_binding) { if (wlr_device->repeat_info.rate > 0) { // We queue the next event first, as the command might cancel it @@ -66,15 +63,17 @@ void create_keyboard(struct seat *seat, struct seat_device *seat_device) kb->seat_device = seat_device; kb->seat = seat; + kb->wlr = wlr_keyboard_from_input_device(wlr_device); + /* Prepare an XKB keymap and assign it to the keyboard. */ struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_keymap *keymap = xkb_map_new_from_names(context, NULL, XKB_KEYMAP_COMPILE_NO_FLAGS); - wlr_keyboard_set_keymap(wlr_device->keyboard, keymap); + wlr_keyboard_set_keymap(kb->wlr, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); - wlr_keyboard_set_repeat_info(wlr_device->keyboard, + wlr_keyboard_set_repeat_info(kb->wlr, server.default_layout->options->repeat_rate, server.default_layout->options->repeat_delay); @@ -84,11 +83,11 @@ void create_keyboard(struct seat *seat, struct seat_device *seat_device) , kb); /* Here we set up listeners for keyboard events. */ - LISTEN(&wlr_device->keyboard->events.modifiers, &kb->modifiers, keypressmod); - LISTEN(&wlr_device->keyboard->events.key, &kb->key, handle_key_event); + LISTEN(&kb->wlr->events.modifiers, &kb->modifiers, keypressmod); + LISTEN(&kb->wlr->events.key, &kb->key, handle_key_event); LISTEN(&wlr_device->events.destroy, &kb->destroy, cleanupkeyboard); - wlr_seat_set_keyboard(seat->wlr_seat, wlr_device); + wlr_seat_set_keyboard(seat->wlr_seat, kb->wlr); /* And add the keyboard to our list of server.keyboards */ g_ptr_array_add(server.keyboards, kb); @@ -126,21 +125,20 @@ void keyboard_disarm_key_repeat(struct keyboard *kb) { void handle_key_event(struct wl_listener *listener, void *data) { /* This event is raised when a key is pressed or released. */ - struct wlr_event_keyboard_key *event = data; + struct wlr_keyboard_key_event *event = data; struct keyboard *kb = wl_container_of(listener, kb, key); /* Get a list of keysyms based on the keymap for this keyboard */ - struct wlr_input_device *wlr_device = kb->seat_device->input_device->wlr_device; /* Translate libinput keycode -> xkbcommon */ uint32_t keycode = event->keycode + 8; - xkb_state_key_get_one_sym(wlr_device->keyboard->xkb_state, keycode); + xkb_state_key_get_one_sym(kb->wlr->xkb_state, keycode); /* create new state to clear the shift modifier to get a instead of A */ - struct xkb_state *state = xkb_state_new(wlr_device->keyboard->keymap); + struct xkb_state *state = xkb_state_new(kb->wlr->keymap); const xkb_keysym_t *syms; int nsyms = xkb_state_key_get_syms(state, keycode, &syms); - uint32_t mods = wlr_keyboard_get_modifiers(wlr_device->keyboard); + uint32_t mods = wlr_keyboard_get_modifiers(kb->wlr); bool handled = false; /* On _press_, attempt to process a compositor keybinding. */ @@ -167,17 +165,17 @@ void handle_key_event(struct wl_listener *listener, void *data) if (!handled) { struct wlr_seat *wlr_seat = kb->seat_device->seat->wlr_seat; /* Pass unhandled keycodes along to the client. */ - wlr_seat_set_keyboard(wlr_seat, wlr_device); + wlr_seat_set_keyboard(wlr_seat, kb->wlr); wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec, event->keycode, event->state); } // Set up (or clear) keyboard repeat for a pressed binding. Since the // binding may remove the keyboard, the timer needs to be updated first - if (bind && handled && wlr_device->keyboard->repeat_info.delay > 0) { + if (bind && handled && kb->wlr->repeat_info.delay > 0) { kb->repeat_binding = strdup(bind); if (wl_event_source_timer_update(kb->key_repeat_source, - wlr_device->keyboard->repeat_info.delay) < 0) { + kb->wlr->repeat_info.delay) < 0) { printf("failed to set key repeat timer\n"); } } else if (kb->repeat_binding) { @@ -200,8 +198,8 @@ void keypressmod(struct wl_listener *listener, void *data) * and wlr_seat handles this transparently. */ struct wlr_seat *wlr_seat = kb->seat->wlr_seat; - wlr_seat_set_keyboard(wlr_seat, kb->seat_device->input_device->wlr_device); + wlr_seat_set_keyboard(wlr_seat, kb->wlr); /* Send modifiers to the client. */ wlr_seat_keyboard_notify_modifiers(wlr_seat, - &kb->seat_device->input_device->wlr_device->keyboard->modifiers); + &kb->wlr->modifiers); } diff --git a/src/monitor.c b/src/monitor.c index 77412596..8bed65c6 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -82,7 +82,7 @@ void create_monitor(struct wl_listener *listener, void *data) wlr_output_enable(output, true); - m->geom = *wlr_output_layout_get_box(server.output_layout, m->wlr_output); + wlr_output_layout_get_box(server.output_layout, m->wlr_output, &m->geom); m->root = create_root(m, m->geom); if (is_first_monitor) { @@ -183,7 +183,7 @@ static void handle_output_damage_frame(struct wl_listener *listener, void *data) static void handle_output_mode(struct wl_listener *listener, void *data) { struct monitor *m = wl_container_of(listener, m, mode); - m->geom = *wlr_output_layout_get_box(server.output_layout, m->wlr_output); + wlr_output_layout_get_box(server.output_layout, m->wlr_output, &m->geom); arrange_layers(m); } diff --git a/src/popup.c b/src/popup.c index 3159226a..4bda6155 100644 --- a/src/popup.c +++ b/src/popup.c @@ -31,7 +31,7 @@ struct xdg_popup *create_popup(struct monitor *m, struct wlr_xdg_popup *xdg_popu popup->xdg = xdg_popup; popup->toplevel = toplevel; - struct wlr_box box = popup->xdg->geometry; + struct wlr_box box = xdg_popup->current.geometry; box.x = 0; box.y = 0; box.width = m->geom.width; @@ -39,10 +39,10 @@ struct xdg_popup *create_popup(struct monitor *m, struct wlr_xdg_popup *xdg_popu wlr_xdg_popup_unconstrain_from_box(popup->xdg, &box); // the root window may be resized. This must be adjusted - popup->geom.x = popup->xdg->geometry.x + parent_geom.x; - popup->geom.y = popup->xdg->geometry.y + parent_geom.y; - popup->geom.width = popup->xdg->geometry.width; - popup->geom.height = popup->xdg->geometry.height; + popup->geom.x = xdg_popup->current.geometry.x + parent_geom.x; + popup->geom.y = xdg_popup->current.geometry.y + parent_geom.y; + popup->geom.width = xdg_popup->current.geometry.width; + popup->geom.height = xdg_popup->current.geometry.height; popup->m = m; LISTEN(&popup->xdg->base->events.map, &popup->map, popup_handle_map); diff --git a/src/seat.c b/src/seat.c index b3b057da..d23662c9 100644 --- a/src/seat.c +++ b/src/seat.c @@ -205,7 +205,7 @@ static void seat_configure_keyboard(struct seat *seat, create_keyboard(seat, seat_device); } /* sway_keyboard_configure(seat_device->keyboard); */ - wlr_seat_set_keyboard(seat->wlr_seat, seat_device->input_device->wlr_device); + wlr_seat_set_keyboard(seat->wlr_seat, seat_device->keyboard->wlr); /* struct sway_node *focus = seat_get_focus(seat); */ /* if (focus && node_is_view(focus)) { */ /* // force notify reenter to pick up the new configuration */ diff --git a/src/tablet.c b/src/tablet.c index bdf70a22..6e8fe2a1 100644 --- a/src/tablet.c +++ b/src/tablet.c @@ -199,7 +199,7 @@ static void handle_tablet_pad_attach(struct wl_listener *listener, static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { struct tablet_pad *pad = wl_container_of(listener, pad, ring); - struct wlr_event_tablet_pad_ring *event = data; + struct wlr_tablet_pad_ring_event *event = data; if (!pad->current_surface) { return; @@ -213,7 +213,7 @@ static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { struct tablet_pad *pad = wl_container_of(listener, pad, strip); - struct wlr_event_tablet_pad_strip *event = data; + struct wlr_tablet_pad_strip_event *event = data; if (!pad->current_surface) { return; @@ -227,7 +227,7 @@ static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { struct tablet_pad *pad = wl_container_of(listener, pad, button); - struct wlr_event_tablet_pad_button *event = data; + struct wlr_tablet_pad_button_event *event = data; if (!pad->current_surface) { return; @@ -249,6 +249,7 @@ struct tablet_pad *tablet_pad_create(struct seat *seat, return NULL; } + tablet_pad->wlr = wlr_tablet_pad_from_input_device(device->input_device->wlr_device); tablet_pad->seat_device = device; wl_list_init(&tablet_pad->attach.link); wl_list_init(&tablet_pad->button.link); @@ -274,20 +275,20 @@ void configure_tablet_pad(struct tablet_pad *tablet_pad) { wl_list_remove(&tablet_pad->attach.link); tablet_pad->attach.notify = handle_tablet_pad_attach; - wl_signal_add(&device->tablet_pad->events.attach_tablet, + wl_signal_add(&tablet_pad->wlr->events.attach_tablet, &tablet_pad->attach); wl_list_remove(&tablet_pad->button.link); tablet_pad->button.notify = handle_tablet_pad_button; - wl_signal_add(&device->tablet_pad->events.button, &tablet_pad->button); + wl_signal_add(&tablet_pad->wlr->events.button, &tablet_pad->button); wl_list_remove(&tablet_pad->strip.link); tablet_pad->strip.notify = handle_tablet_pad_strip; - wl_signal_add(&device->tablet_pad->events.strip, &tablet_pad->strip); + wl_signal_add(&tablet_pad->wlr->events.strip, &tablet_pad->strip); wl_list_remove(&tablet_pad->ring.link); tablet_pad->ring.notify = handle_tablet_pad_ring; - wl_signal_add(&device->tablet_pad->events.ring, &tablet_pad->ring); + wl_signal_add(&tablet_pad->wlr->events.ring, &tablet_pad->ring); /* Search for a sibling tablet */ if (!wlr_input_device_is_libinput(device)) { From 57c5bae9e813568a743fe21dd2d4344feb8a13d6 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sun, 15 Jan 2023 22:56:55 +0100 Subject: [PATCH 92/93] update to newest wlroots --- src/client.c | 2 +- src/popup.c | 2 +- src/server.c | 5 ++++- src/tile/tileUtils.c | 8 +++++--- src/xdg_shell.c | 2 +- src/xwayland.c | 4 ++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/client.c b/src/client.c index 945b7d5d..2c26edd9 100644 --- a/src/client.c +++ b/src/client.c @@ -87,7 +87,7 @@ static void unfocus_client(struct client *c) return; switch (c->type) { - c->surface.xdg; + case XDG_SHELL: wlr_xdg_toplevel_set_activated(c->surface.xdg->toplevel, false); break; case X11_MANAGED: diff --git a/src/popup.c b/src/popup.c index 4bda6155..7df675c0 100644 --- a/src/popup.c +++ b/src/popup.c @@ -165,7 +165,7 @@ inline void destroy_popups() if (!popup) return; - wlr_xdg_popup_destroy(popup->xdg->base); + wlr_xdg_popup_destroy(popup->xdg); } inline struct xdg_popup *get_latest_popup() diff --git a/src/server.c b/src/server.c index 99eba9fd..ffa250c1 100644 --- a/src/server.c +++ b/src/server.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "layer_shell.h" #include "monitor.h" @@ -39,6 +40,8 @@ #include "keybinding.h" #include "ring_buffer.h" +#define XDG_SHELL_VERSION 2 + struct server server; static void init_event_handlers(struct server *server); @@ -170,7 +173,7 @@ static void init_event_handlers(struct server *server) server->xdeco_mgr = wlr_xdg_decoration_manager_v1_create(server->wl_display); LISTEN(&server->xdeco_mgr->events.new_toplevel_decoration, &server->new_xdeco, createxdeco); - server->xdg_shell = wlr_xdg_shell_create(server->wl_display); + server->xdg_shell = wlr_xdg_shell_create(server->wl_display, XDG_SHELL_VERSION); // remove csd(client side decorations) completely from xdg based windows wlr_server_decoration_manager_set_default_mode( wlr_server_decoration_manager_create(server->wl_display), diff --git a/src/tile/tileUtils.c b/src/tile/tileUtils.c index fb1b968c..4c4b2248 100644 --- a/src/tile/tileUtils.c +++ b/src/tile/tileUtils.c @@ -220,7 +220,7 @@ int get_container_area_count(struct tag *tag) void arrange_monitor(struct monitor *m) { - m->geom = *wlr_output_layout_get_box(server.output_layout, m->wlr_output); + wlr_output_layout_get_box(server.output_layout, m->wlr_output, &m->geom); struct wlr_box active_geom = monitor_get_active_geom(m); struct tag *tag = monitor_get_active_tag(m); @@ -299,13 +299,15 @@ void container_update_size(struct container *con) con->client->resized = true; struct wlr_box con_geom = container_get_current_content_geom(con); - con_geom = apply_bounds(con, *wlr_output_layout_get_box(server.output_layout, NULL)); + struct wlr_box output_geom; + wlr_output_layout_get_box(server.output_layout, NULL, &output_geom); + con_geom = apply_bounds(con, output_geom); /* wlroots makes this a no-op if size hasn't changed */ switch (con->client->type) { case XDG_SHELL: if (con->client->surface.xdg->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { - wlr_xdg_toplevel_set_size(con->client->surface.xdg, + wlr_xdg_toplevel_set_size(con->client->surface.xdg->toplevel, con_geom.width, con_geom.height); } break; diff --git a/src/xdg_shell.c b/src/xdg_shell.c index 396ddd23..60a3ece6 100644 --- a/src/xdg_shell.c +++ b/src/xdg_shell.c @@ -50,7 +50,7 @@ void create_notify_xdg(struct wl_listener *listener, void *data) struct client *c = xdg_surface->data = create_client(XDG_SHELL, surface); /* Tell the client not to try anything fancy */ - wlr_xdg_toplevel_set_tiled(c->surface.xdg, WLR_EDGE_TOP | + wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT); /* Listen to the various events it can emit */ diff --git a/src/xwayland.c b/src/xwayland.c index c22b8235..68863894 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -157,7 +157,7 @@ void maprequestx11(struct wl_listener *listener, void *data) .height = c->surface.xwayland->height, }; - struct wlr_xwayland_surface_size_hints *size_hints = + xcb_size_hints_t *size_hints = c->surface.xwayland->size_hints; if (size_hints) { if (size_hints->width > MIN_CONTAINER_WIDTH @@ -256,7 +256,7 @@ bool x11_wants_floating(struct client *c) } #endif - struct wlr_xwayland_surface_size_hints *size_hints = surface->size_hints; + xcb_size_hints_t *size_hints = surface->size_hints; if (size_hints != NULL && size_hints->min_width > 0 && size_hints->min_height > 0 && (size_hints->max_width == size_hints->min_width || From 48b321d6bb11bbfd212d3f94f66a9ecc2788c50c Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Sun, 15 Jan 2023 23:25:47 +0100 Subject: [PATCH 93/93] add subcompositor --- src/keyboard.c | 2 ++ src/seat.c | 2 -- src/server.c | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 1e932b30..9e03ab9a 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -63,6 +63,8 @@ void create_keyboard(struct seat *seat, struct seat_device *seat_device) kb->seat_device = seat_device; kb->seat = seat; + seat_device->keyboard = kb; + kb->wlr = wlr_keyboard_from_input_device(wlr_device); /* Prepare an XKB keymap and assign it to the keyboard. */ diff --git a/src/seat.c b/src/seat.c index d23662c9..3d9aecfe 100644 --- a/src/seat.c +++ b/src/seat.c @@ -1,5 +1,3 @@ -#include "seat.h" - #include #include #include diff --git a/src/server.c b/src/server.c index ffa250c1..4bfcee0e 100644 --- a/src/server.c +++ b/src/server.c @@ -424,6 +424,9 @@ int setup_server(struct server *server) * the clients cannot set the selection directly without compositor approval, * see the setsel() function. */ server->compositor = wlr_compositor_create(server->wl_display, server->renderer); + + wlr_subcompositor_create(server->wl_display); + wlr_export_dmabuf_manager_v1_create(server->wl_display); wlr_screencopy_manager_v1_create(server->wl_display); wlr_data_control_manager_v1_create(server->wl_display);