summaryrefslogtreecommitdiff
path: root/openbox/actions/tiling.c
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-10-02 00:29:58 +0200
committeraura <nw@moneybot.cc>2026-10-02 00:29:58 +0200
commitfc25ef5568291528f6e1c3463b3b142139eb8e8d (patch)
treef8df598fb171bf30c0939244372c487d0e017961 /openbox/actions/tiling.c
parent87e8271068ea3bccf1daf4e7e4b3667379c054bf (diff)
add tilingHEADmaster
Diffstat (limited to 'openbox/actions/tiling.c')
-rw-r--r--openbox/actions/tiling.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/openbox/actions/tiling.c b/openbox/actions/tiling.c
new file mode 100644
index 00000000..91aa7ded
--- /dev/null
+++ b/openbox/actions/tiling.c
@@ -0,0 +1,134 @@
+#include "openbox/actions.h"
+#include "openbox/client.h"
+#include "openbox/screen.h"
+#include "openbox/tiling.h"
+
+typedef struct {
+ gboolean main_stack;
+ gint delta;
+ guint key;
+} Options;
+
+static gpointer setup(xmlNodePtr node)
+{
+ Options *options = g_new0(Options, 1);
+ xmlNodePtr child;
+
+ options->main_stack = TRUE;
+ options->delta = 1;
+ if ((child = obt_xml_find_node(node, "stack")))
+ options->main_stack = !obt_xml_node_contains(child, "side");
+ if ((child = obt_xml_find_node(node, "delta")))
+ options->delta = obt_xml_node_int(child);
+ if ((child = obt_xml_find_node(node, "key")))
+ options->key = obt_xml_node_int(child);
+ return options;
+}
+
+#define KEY_SETUP(number) \
+ static gpointer setup_key_##number(xmlNodePtr node) \
+ { \
+ Options *options = g_new0(Options, 1); \
+ options->key = number; \
+ return options; \
+ }
+
+KEY_SETUP(0)
+KEY_SETUP(1)
+KEY_SETUP(2)
+KEY_SETUP(3)
+KEY_SETUP(4)
+KEY_SETUP(5)
+KEY_SETUP(6)
+KEY_SETUP(7)
+KEY_SETUP(8)
+KEY_SETUP(9)
+KEY_SETUP(10)
+KEY_SETUP(11)
+KEY_SETUP(12)
+
+#undef KEY_SETUP
+
+static guint monitor(ObActionsData *data)
+{
+ return data->client ? client_monitor(data->client) : screen_monitor_pointer();
+}
+
+static gboolean toggle(ObActionsData *data, gpointer options)
+{
+ actions_client_move(data, TRUE);
+ tiling_toggle(monitor(data));
+ actions_client_move(data, FALSE);
+ return FALSE;
+}
+
+static gboolean flip(ObActionsData *data, gpointer options)
+{
+ actions_client_move(data, TRUE);
+ tiling_flip(monitor(data));
+ actions_client_move(data, FALSE);
+ return FALSE;
+}
+
+static gboolean count(ObActionsData *data, gpointer options)
+{
+ Options *o = options;
+
+ actions_client_move(data, TRUE);
+ tiling_change_count(monitor(data), o->main_stack, o->delta);
+ actions_client_move(data, FALSE);
+ return FALSE;
+}
+
+static gboolean promote(ObActionsData *data, gpointer options)
+{
+ actions_client_move(data, TRUE);
+ tiling_promote(data->client);
+ actions_client_move(data, FALSE);
+ return FALSE;
+}
+
+static gboolean assign(ObActionsData *data, gpointer options)
+{
+ Options *o = options;
+
+ tiling_assign(data->client, o->key);
+ return FALSE;
+}
+
+static gboolean recall(ObActionsData *data, gpointer options)
+{
+ Options *o = options;
+
+ actions_client_move(data, TRUE);
+ tiling_recall(o->key);
+ actions_client_move(data, FALSE);
+ return FALSE;
+}
+
+void action_tiling_startup(void)
+{
+ static const ObActionsDataSetupFunc key_setups[] = {
+ setup_key_0, setup_key_1, setup_key_2, setup_key_3, setup_key_4,
+ setup_key_5, setup_key_6, setup_key_7, setup_key_8, setup_key_9,
+ setup_key_10, setup_key_11, setup_key_12
+ };
+ guint key;
+
+ actions_register("ToggleTiling", NULL, NULL, toggle);
+ actions_register("FlipTiling", NULL, NULL, flip);
+ actions_register("ChangeTileCount", setup, g_free, count);
+ actions_register("MakeMainTile", NULL, NULL, promote);
+ actions_register("AssignWindowKey", setup, g_free, assign);
+ actions_register("RecallWindowKey", setup, g_free, recall);
+ actions_register("AssignWindow0", setup_key_0, g_free, assign);
+ for (key = 1; key < G_N_ELEMENTS(key_setups); ++key) {
+ gchar *name = g_strdup_printf("AssignWindow%u", key);
+
+ actions_register(name, key_setups[key], g_free, assign);
+ g_free(name);
+ name = g_strdup_printf("RecallWindow%u", key);
+ actions_register(name, key_setups[key], g_free, recall);
+ g_free(name);
+ }
+}