From 336095739e2de94109e55e544c806770316c822c Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Tue, 19 Jun 2018 10:14:09 +0200 Subject: [PATCH] Add node descriptor: `smallest` Fixes #815. --- contrib/zsh_completion | 2 +- doc/bspwm.1 | 19 ++++++++++++------- doc/bspwm.1.asciidoc | 11 +++++++---- src/query.c | 4 +++- src/tree.c | 14 ++++++++++---- src/tree.h | 2 +- src/types.h | 5 +++++ 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/contrib/zsh_completion b/contrib/zsh_completion index 3e92a01..d66b9b2 100644 --- a/contrib/zsh_completion +++ b/contrib/zsh_completion @@ -134,7 +134,7 @@ _bspc() { dir=(north west south east) \ cycle_dir=(next prev) local -a jump=($dir first second brother parent 1 2) \ - node_desc=($dir $cycle_dir any last newest older newer focused pointed biggest) \ + node_desc=($dir $cycle_dir any last newest older newer focused pointed biggest smallest) \ node_mod=($node_state $flag $layer focused automatic local \ active leaf window same_class descendant_of ancestor_of) \ desktop_desc=($cycle_dir any last newest older newer focused) \ diff --git a/doc/bspwm.1 b/doc/bspwm.1 index 43bfc5e..ca04ae6 100644 --- a/doc/bspwm.1 +++ b/doc/bspwm.1 @@ -2,12 +2,12 @@ .\" Title: bspwm .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.79.1 -.\" Date: 04/25/2018 +.\" Date: 06/19/2018 .\" Manual: Bspwm Manual -.\" Source: Bspwm 0.9.5 +.\" Source: Bspwm 0.9.5-3-gdb5b0cd .\" Language: English .\" -.TH "BSPWM" "1" "04/25/2018" "Bspwm 0\&.9\&.5" "Bspwm Manual" +.TH "BSPWM" "1" "06/19/2018" "Bspwm 0\&.9\&.5\-3\-gdb5b0cd" "Bspwm Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -101,10 +101,10 @@ Select a node\&. .\} .nf NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|last|newest| - older|newer|focused|pointed| - biggest|)[\&.[!]focused][\&.[!]automatic][\&.[!]local][\&.[!]active] - [\&.[!]leaf][\&.[!]window][\&.[!]STATE][\&.[!]FLAG][\&.[!]LAYER] - [\&.[!]same_class][\&.[!]descendant_of][\&.[!]ancestor_of] + older|newer|focused|pointed|biggest|smallest + )[\&.[!]focused][\&.[!]automatic][\&.[!]local][\&.[!]active] + [\&.[!]leaf][\&.[!]window][\&.[!]STATE][\&.[!]FLAG][\&.[!]LAYER] + [\&.[!]same_class][\&.[!]descendant_of][\&.[!]ancestor_of] STATE := tiled|pseudo_tiled|floating|fullscreen @@ -183,6 +183,11 @@ biggest Selects the biggest window\&. .RE .PP +smallest +.RS 4 +Selects the smallest window\&. +.RE +.PP .RS 4 Selects the node with the given ID\&. diff --git a/doc/bspwm.1.asciidoc b/doc/bspwm.1.asciidoc index 48f0769..18b3264 100644 --- a/doc/bspwm.1.asciidoc +++ b/doc/bspwm.1.asciidoc @@ -75,10 +75,10 @@ Select a node. ---- NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|last|newest| - older|newer|focused|pointed| - biggest|)[.[!]focused][.[!]automatic][.[!]local][.[!]active] - [.[!]leaf][.[!]window][.[!]STATE][.[!]FLAG][.[!]LAYER] - [.[!]same_class][.[!]descendant_of][.[!]ancestor_of] + older|newer|focused|pointed|biggest|smallest + )[.[!]focused][.[!]automatic][.[!]local][.[!]active] + [.[!]leaf][.[!]window][.[!]STATE][.[!]FLAG][.[!]LAYER] + [.[!]same_class][.[!]descendant_of][.[!]ancestor_of] STATE := tiled|pseudo_tiled|floating|fullscreen @@ -127,6 +127,9 @@ pointed:: biggest:: Selects the biggest window. +smallest:: + Selects the smallest window. + :: Selects the node with the given ID. diff --git a/src/query.c b/src/query.c index f679593..3d99a17 100644 --- a/src/query.c +++ b/src/query.c @@ -533,7 +533,9 @@ int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst) } else if (streq("newest", desc)) { history_find_newest_node(ref, dst, &sel); } else if (streq("biggest", desc)) { - find_biggest(ref, dst, &sel); + find_by_area(AREA_BIGGEST, ref, dst, &sel); + } else if (streq("smallest", desc)) { + find_by_area(AREA_SMALLEST, ref, dst, &sel); } else if (streq("pointed", desc)) { xcb_window_t win = XCB_NONE; query_pointer(&win, NULL); diff --git a/src/tree.c b/src/tree.c index 2d0cc98..3af5b66 100644 --- a/src/tree.c +++ b/src/tree.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "bspwm.h" #include "desktop.h" #include "ewmh.h" @@ -1042,9 +1043,14 @@ int tiled_count(node_t *n) return cnt; } -void find_biggest(coordinates_t *ref, coordinates_t *dst, node_select_t *sel) +void find_by_area(area_peak_t ap, coordinates_t *ref, coordinates_t *dst, node_select_t *sel) { - unsigned int b_area = 0; + unsigned int p_area; + if (ap == AREA_BIGGEST) { + p_area = 0; + } else { + p_area = UINT_MAX; + } for (monitor_t *m = mon_head; m != NULL; m = m->next) { for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { @@ -1054,9 +1060,9 @@ void find_biggest(coordinates_t *ref, coordinates_t *dst, node_select_t *sel) continue; } unsigned int f_area = node_area(d, f); - if (f_area > b_area) { + if ((ap == AREA_BIGGEST && f_area > p_area) || (ap == AREA_SMALLEST && f_area < p_area)) { *dst = loc; - b_area = f_area; + p_area = f_area; } } } diff --git a/src/tree.h b/src/tree.h index 05501f4..8e0293a 100644 --- a/src/tree.h +++ b/src/tree.h @@ -71,7 +71,7 @@ bool find_any_node_in(monitor_t *m, desktop_t *d, node_t *n, coordinates_t *ref, void find_nearest_neighbor(coordinates_t *ref, coordinates_t *dst, direction_t dir, node_select_t *sel); unsigned int node_area(desktop_t *d, node_t *n); int tiled_count(node_t *n); -void find_biggest(coordinates_t *ref, coordinates_t *dst, node_select_t *sel); +void find_by_area(area_peak_t ap, coordinates_t *ref, coordinates_t *dst, node_select_t *sel); void rotate_tree(node_t *n, int deg); void rotate_tree_rec(node_t *n, int deg); void rotate_brother(node_t *n); diff --git a/src/types.h b/src/types.h index 1703d21..4f936b5 100644 --- a/src/types.h +++ b/src/types.h @@ -144,6 +144,11 @@ typedef enum { TIGHTNESS_HIGH, } tightness_t; +typedef enum { + AREA_BIGGEST, + AREA_SMALLEST, +} area_peak_t; + typedef enum { STATE_TRANSITION_ENTER = 1 << 0, STATE_TRANSITION_EXIT = 1 << 1, -- 2.44.0