commit 23eef476404d2a2b1456cb09bf45c37c8f8c2bf0
parent 22704901286c3517da3ca54dd37c2215e4d6e951
Author: deurzen <max@deurzen.net>
Date: Sat, 28 May 2022 05:37:13 +0200
adds layout data modifiers
Diffstat:
10 files changed, 187 insertions(+), 69 deletions(-)
diff --git a/include/kranewl/input/keybindings.hh b/include/kranewl/input/keybindings.hh
@@ -225,6 +225,77 @@ static const KeyBindings key_bindings = {
{ { XKB_KEY_Return, MODKEY },
CALL_EXTERNAL(alacritty)
},
+
+// workspace layout data modifiers
+{ { XKB_KEY_equal, MODKEY },
+ CALL(change_gap_size(2))
+},
+{ { XKB_KEY_minus, MODKEY },
+ CALL(change_gap_size(-2))
+},
+{ { XKB_KEY_equal, MODKEY | SHIFT },
+ CALL(reset_gap_size())
+},
+{ { XKB_KEY_i, MODKEY },
+ CALL(change_main_count(1))
+},
+{ { XKB_KEY_d, MODKEY },
+ CALL(change_main_count(-1))
+},
+{ { XKB_KEY_l, MODKEY },
+ CALL(change_main_factor(.05f))
+},
+{ { XKB_KEY_h, MODKEY },
+ CALL(change_main_factor(-.05f))
+},
+{ { XKB_KEY_Page_Up, MODKEY | SHIFT },
+ CALL(change_margin(5))
+},
+{ { XKB_KEY_Page_Down, MODKEY | SHIFT },
+ CALL(change_margin(-5))
+},
+{ { XKB_KEY_Left, MODKEY | SHIFT },
+ CALL(change_margin(Edge::Left, 5))
+},
+{ { XKB_KEY_Left, MODKEY | CTRL | SHIFT },
+ CALL(change_margin(Edge::Left, -5))
+},
+{ { XKB_KEY_Up, MODKEY | SHIFT },
+ CALL(change_margin(Edge::Top, 5))
+},
+{ { XKB_KEY_Up, MODKEY | CTRL | SHIFT },
+ CALL(change_margin(Edge::Top, -5))
+},
+{ { XKB_KEY_Right, MODKEY | SHIFT },
+ CALL(change_margin(Edge::Right, 5))
+},
+{ { XKB_KEY_Right, MODKEY | CTRL | SHIFT },
+ CALL(change_margin(Edge::Right, -5))
+},
+{ { XKB_KEY_Down, MODKEY | SHIFT },
+ CALL(change_margin(Edge::Bottom, 5))
+},
+{ { XKB_KEY_Down, MODKEY | CTRL | SHIFT },
+ CALL(change_margin(Edge::Bottom, -5))
+},
+{ { XKB_KEY_comma, MODKEY | CTRL | SHIFT },
+ CALL(cycle_layout_data(Direction::Backward))
+},
+{ { XKB_KEY_period, MODKEY | CTRL | SHIFT },
+ CALL(cycle_layout_data(Direction::Forward))
+},
+{ { XKB_KEY_slash, MODKEY | CTRL | SHIFT },
+ CALL(toggle_layout_data())
+},
+{ { XKB_KEY_Delete, MODKEY | CTRL | SHIFT },
+ CALL(copy_data_from_prev_layout())
+},
+{ { XKB_KEY_equal, MODKEY | CTRL | SHIFT },
+ CALL(reset_margin())
+},
+{ { XKB_KEY_equal, MODKEY | SECKEY | CTRL | SHIFT },
+ CALL(reset_layout_data())
+},
};
}
diff --git a/include/kranewl/layers.hh b/include/kranewl/layers.hh
@@ -1,6 +1,8 @@
#pragma once
struct Layer {
+ typedef short type;
+ static constexpr short None = -1;
static constexpr short Background = 0;
static constexpr short Bottom = 1;
static constexpr short Tile = 2;
diff --git a/include/kranewl/tree/view.hh b/include/kranewl/tree/view.hh
@@ -3,6 +3,7 @@
#include <kranewl/common.hh>
#include <kranewl/decoration.hh>
#include <kranewl/geometry.hh>
+#include <kranewl/layers.hh>
#include <kranewl/model.hh>
#include <kranewl/tree/surface.hh>
@@ -73,8 +74,6 @@ typedef struct View {
virtual bool prefers_floating() = 0;
virtual View_ptr is_transient_for() = 0;
- virtual void map() = 0;
- virtual void unmap() = 0;
virtual void focus(Toggle) = 0;
virtual void activate(Toggle) = 0;
virtual void set_tiled(Toggle) = 0;
@@ -86,6 +85,13 @@ typedef struct View {
virtual void close_popups() = 0;
virtual void destroy() = 0;
+ void map();
+ void unmap();
+ void tile(Toggle);
+ void relayer(Layer::type);
+ void raise() const;
+ void lower() const;
+
void render_decoration();
bool activated() const { return m_activated; }
@@ -210,6 +216,8 @@ private:
bool m_iconified;
bool m_disowned;
+ Layer::type m_layer;
+
OutsideState m_outside_state;
void set_inner_region(Region const&);
diff --git a/include/kranewl/tree/xdg_view.hh b/include/kranewl/tree/xdg_view.hh
@@ -27,8 +27,6 @@ typedef struct XDGView final : public View {
bool prefers_floating() override;
View_ptr is_transient_for() override;
- void map() override;
- void unmap() override;
void focus(Toggle) override;
void activate(Toggle) override;
void set_tiled(Toggle) override;
diff --git a/include/kranewl/tree/xwayland_view.hh b/include/kranewl/tree/xwayland_view.hh
@@ -26,8 +26,6 @@ typedef struct XWaylandView final : public View {
bool prefers_floating() override;
View_ptr is_transient_for() override;
- void map() override;
- void unmap() override;
void focus(Toggle) override;
void activate(Toggle) override;
void set_tiled(Toggle) override;
diff --git a/src/kranewl/exec.cc b/src/kranewl/exec.cc
@@ -7,8 +7,9 @@ extern "C" {
void
exec_external(std::string& command) {
if (!fork()) {
+ dup2(STDERR_FILENO, STDOUT_FILENO);
setsid();
execl("/bin/sh", "/bin/sh", "-c", ("exec " + command).c_str(), nullptr);
- std::exit(EXIT_SUCCESS);
+ _exit(EXIT_FAILURE);
}
}
diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc
@@ -194,20 +194,6 @@ Model::unregister_output(Output_ptr output)
}
void
-Model::map_view(View_ptr)
-{
- TRACE();
-
-}
-
-void
-Model::unmap_view(View_ptr)
-{
- TRACE();
-
-}
-
-void
Model::iconify_view(View_ptr)
{
TRACE();
@@ -285,7 +271,7 @@ Model::place_view(Placement& placement)
}
}
- unmap_view(view);
+ view->unmap();
return;
}
@@ -307,7 +293,7 @@ Model::place_view(Placement& placement)
spdlog::info("Placing view {} at {}", view->m_uid, std::to_string(view->active_region()));
- map_view(view);
+ view->map();
view->configure(
view->active_region(),
view->active_decoration().extents(),
@@ -372,7 +358,6 @@ Model::reverse_views()
return;
mp_workspace->reverse();
- /* mp_workspace->active()->focus(true); */
sync_focus();
apply_layout(mp_workspace);
@@ -387,7 +372,6 @@ Model::rotate_views(Direction direction)
return;
mp_workspace->rotate(direction);
- /* mp_workspace->active()->focus(true); */
sync_focus();
apply_layout(mp_workspace);
@@ -504,9 +488,9 @@ Model::move_view_to_workspace(View_ptr view, Workspace_ptr workspace_to)
apply_layout(workspace_to);
if (output_to)
- map_view(view);
+ view->map();
else
- unmap_view(view);
+ view->unmap();
sync_focus();
}
@@ -547,9 +531,9 @@ Model::move_view_to_context(View_ptr view, Context_ptr context_to)
apply_layout(workspace_to);
if (output_to)
- map_view(view);
+ view->map();
else
- unmap_view(view);
+ view->unmap();
sync_focus();
}
@@ -598,9 +582,9 @@ Model::move_view_to_output(View_ptr view, Output_ptr output_to)
if (output_to) {
wlr_surface_send_enter(view->mp_wlr_surface, output_to->mp_wlr_output);
- map_view(view);
+ view->map();
} else
- unmap_view(view);
+ view->unmap();
sync_focus();
}
@@ -837,8 +821,7 @@ Model::apply_layout(Workspace_ptr workspace)
{
TRACE();
- Context_ptr context = workspace->context();
- Output_ptr output = context->output();
+ Output_ptr output = workspace->context()->output();
if (!output)
return;
@@ -880,9 +863,9 @@ Model::set_floating_view(Toggle toggle, View_ptr view)
TRACE();
switch (toggle) {
- case Toggle::On: view->set_floating(true); break;
- case Toggle::Off: view->set_floating(false); break;
- case Toggle::Reverse: view->set_floating(!view->floating()); break;
+ case Toggle::On: view->tile(Toggle::Off); break;
+ case Toggle::Off: view->tile(Toggle::On); break;
+ case Toggle::Reverse: view->tile(Toggle::Reverse); break;
default: return;
}
@@ -1166,7 +1149,7 @@ Model::set_iconify_view(Toggle toggle, View_ptr view)
// TODO: set iconify state
- unmap_view(view);
+ view->unmap();
apply_layout(workspace);
sync_focus();
diff --git a/src/kranewl/tree/view.cc b/src/kranewl/tree/view.cc
@@ -65,6 +65,7 @@ View::View(
m_iconifyable(true),
m_iconified(false),
m_disowned(false),
+ m_layer(Layer::None),
m_last_focused(std::chrono::steady_clock::now()),
m_last_touched(std::chrono::steady_clock::now()),
m_managed_since(std::chrono::steady_clock::now()),
@@ -116,6 +117,7 @@ View::View(
m_iconifyable(true),
m_iconified(false),
m_disowned(false),
+ m_layer(Layer::None),
m_last_focused(std::chrono::steady_clock::now()),
m_last_touched(std::chrono::steady_clock::now()),
m_managed_since(std::chrono::steady_clock::now())
@@ -262,6 +264,92 @@ View::set_disowned(bool disowned)
}
void
+View::map()
+{
+ if (!m_mapped) {
+ wlr_scene_node_set_enabled(mp_scene, true);
+ m_mapped = true;
+ }
+}
+
+void
+View::unmap()
+{
+ if (m_mapped) {
+ focus(Toggle::Off);
+ wlr_scene_node_set_enabled(mp_scene, false);
+ m_mapped = false;
+ }
+}
+
+void
+View::tile(Toggle toggle)
+{
+ TRACE();
+
+ switch (toggle) {
+ case Toggle::On:
+ {
+ if (!m_floating)
+ return;
+
+ set_floating(false);
+ if (!m_fullscreen)
+ relayer(Layer::Tile);
+
+ break;
+ }
+ case Toggle::Off:
+ {
+ if (m_floating)
+ return;
+
+ set_floating(true);
+ if (!m_fullscreen)
+ relayer(Layer::Free);
+
+ break;
+ }
+ case Toggle::Reverse:
+ {
+ tile(
+ floating()
+ ? Toggle::On
+ : Toggle::Off
+ );
+ return;
+ }
+ default: break;
+ }
+}
+
+void
+View::relayer(Layer::type layer)
+{
+ if (layer == m_layer)
+ return;
+
+ m_layer = layer;
+
+ wlr_scene_node_reparent(
+ mp_scene,
+ mp_server->m_layers[layer]
+ );
+}
+
+void
+View::raise() const
+{
+ wlr_scene_node_raise_to_top(mp_scene);
+}
+
+void
+View::lower() const
+{
+ wlr_scene_node_lower_to_bottom(mp_scene);
+}
+
+void
View::render_decoration()
{
TRACE();
diff --git a/src/kranewl/tree/xdg_view.cc b/src/kranewl/tree/xdg_view.cc
@@ -98,20 +98,6 @@ XDGView::is_transient_for()
}
void
-XDGView::map()
-{
- TRACE();
-
-}
-
-void
-XDGView::unmap()
-{
- TRACE();
-
-}
-
-void
XDGView::focus(Toggle toggle)
{
TRACE();
@@ -395,10 +381,7 @@ XDGView::handle_map(struct wl_listener* listener, void* data)
);
view->mp_scene_surface->data = view;
- wlr_scene_node_reparent(
- view->mp_scene,
- server->m_layers[view->floating() ? Layer::Free : Layer::Tile]
- );
+ view->relayer(view->floating() ? Layer::Free : Layer::Tile);
for (std::size_t i = 0; i < 4; ++i) {
view->m_protrusions[i] = wlr_scene_rect_create(
diff --git a/src/kranewl/tree/xwayland_view.cc b/src/kranewl/tree/xwayland_view.cc
@@ -86,20 +86,6 @@ XWaylandView::is_transient_for()
}
void
-XWaylandView::map()
-{
- TRACE();
-
-}
-
-void
-XWaylandView::unmap()
-{
- TRACE();
-
-}
-
-void
XWaylandView::focus(Toggle)
{
TRACE();