Skip to content

Commit 229ec70

Browse files
committed
tree: don't nest redundant containers on repeated split
Splitting a toplevel that is the only child of its parent container wrapped it in yet another single-child container. Repeating the action produced a chain of redundant nesting levels. Change the split direction of the existing container instead.
1 parent c89df00 commit 229ec70

17 files changed

Lines changed: 147 additions & 0 deletions

File tree

book/src/configuration/misc.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ window-management-key = "Alt_L"
214214
The value should be a keysym name from
215215
[KBVM](https://docs.rs/kbvm/latest/kbvm/syms/index.html).
216216

217+
## Split Reuses Container
218+
219+
Controls whether splitting a window that is the only window in its container
220+
reuses that container.
221+
222+
If this is disabled, splitting such a window wraps it in another container,
223+
creating a redundant nesting level. If this is enabled, the split direction of
224+
the existing container is changed instead.
225+
226+
```toml
227+
split-reuses-container = false # default
228+
```
229+
217230
## Middle-Click Paste
218231

219232
Controls whether middle-clicking pastes the primary selection. Changing this

jay-config/src/_private/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,16 @@ impl ConfigClient {
11251125
above
11261126
}
11271127

1128+
pub fn set_split_reuses_container(&self, reuse: bool) {
1129+
self.send(&ClientMessage::SetSplitReusesContainer { reuse });
1130+
}
1131+
1132+
pub fn get_split_reuses_container(&self) -> bool {
1133+
let res = self.send_with_response(&ClientMessage::GetSplitReusesContainer);
1134+
get_response!(res, false, GetSplitReusesContainer { reuse });
1135+
reuse
1136+
}
1137+
11281138
pub fn set_show_bar(&self, show: bool) {
11291139
self.send(&ClientMessage::SetShowBar { show });
11301140
}

jay-config/src/_private/ipc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,10 @@ pub enum ClientMessage<'a> {
10081008
GetPlaneColorPipelinesEnabled {
10091009
device: DrmDevice,
10101010
},
1011+
SetSplitReusesContainer {
1012+
reuse: bool,
1013+
},
1014+
GetSplitReusesContainer,
10111015
}
10121016

10131017
#[derive(Serialize, Deserialize, Debug)]
@@ -1282,6 +1286,9 @@ pub enum Response {
12821286
GetPlaneColorPipelinesEnabled {
12831287
enabled: bool,
12841288
},
1289+
GetSplitReusesContainer {
1290+
reuse: bool,
1291+
},
12851292
}
12861293

12871294
#[derive(Serialize, Deserialize, Debug)]

jay-config/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,31 @@ pub fn set_show_float_pin_icon(show: bool) {
473473
get!().set_show_float_pin_icon(show);
474474
}
475475

476+
/// Sets whether splitting a window that is the only child of its container reuses
477+
/// that container.
478+
///
479+
/// If disabled, splitting such a window wraps it in another container, creating a
480+
/// redundant nesting level. If enabled, the split direction of the existing container
481+
/// is changed instead.
482+
///
483+
/// The default is `false`.
484+
pub fn set_split_reuses_container(reuse: bool) {
485+
get!().set_split_reuses_container(reuse)
486+
}
487+
488+
/// Returns whether splitting a window that is the only child of its container reuses
489+
/// that container.
490+
pub fn get_split_reuses_container() -> bool {
491+
get!(false).get_split_reuses_container()
492+
}
493+
494+
/// Toggles whether splitting a window that is the only child of its container reuses
495+
/// that container.
496+
pub fn toggle_split_reuses_container() {
497+
let get = get!();
498+
get.set_split_reuses_container(!get.get_split_reuses_container());
499+
}
500+
476501
/// Sets whether the built-in bar is shown.
477502
///
478503
/// The default is `true`.

src/compositor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ fn start_compositor2(
449449
backend_connector_state_serials: Default::default(),
450450
head_names: Default::default(),
451451
show_bar: Cell::new(true),
452+
split_reuses_container: Cell::new(false),
452453
enable_primary_selection: Cell::new(true),
453454
workspace_display_order: Cell::new(WorkspaceDisplayOrder::Manual),
454455
outputs_without_hc: Default::default(),

src/config/handler.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,16 @@ impl ConfigProxyHandler {
18161816
});
18171817
}
18181818

1819+
fn handle_set_split_reuses_container(&self, reuse: bool) {
1820+
self.state.split_reuses_container.set(reuse);
1821+
}
1822+
1823+
fn handle_get_split_reuses_container(&self) {
1824+
self.respond(Response::GetSplitReusesContainer {
1825+
reuse: self.state.split_reuses_container.get(),
1826+
});
1827+
}
1828+
18191829
fn handle_set_show_bar(&self, show: bool) {
18201830
self.state.set_show_bar(show);
18211831
}
@@ -3832,6 +3842,10 @@ impl ConfigProxyHandler {
38323842
ClientMessage::GetContentType { window } => self
38333843
.handle_get_content_type(window)
38343844
.wrn("get_content_type")?,
3845+
ClientMessage::SetSplitReusesContainer { reuse } => {
3846+
self.handle_set_split_reuses_container(reuse)
3847+
}
3848+
ClientMessage::GetSplitReusesContainer => self.handle_get_split_reuses_container(),
38353849
ClientMessage::SetShowBar { show } => self.handle_set_show_bar(show),
38363850
ClientMessage::GetShowBar => self.handle_get_show_bar(),
38373851
ClientMessage::SetShowTitles { show } => self.handle_set_show_titles(show),

src/control_center/cc_look_and_feel.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ impl LookAndFeelPane {
119119
self.state.float_above_fullscreen.get(),
120120
|v| self.state.set_float_above_fullscreen(v),
121121
);
122+
bool_ui(
123+
ui,
124+
"Split Reuses Container",
125+
|ui| {
126+
tip(ui, |ui| {
127+
ui.label(
128+
"Splitting the only window in a container changes the split \
129+
direction of that container.",
130+
);
131+
ui.label("Otherwise the window is wrapped in a new container.");
132+
});
133+
},
134+
self.state.split_reuses_container.get(),
135+
|v| self.state.split_reuses_container.set(v),
136+
);
122137
row(ui, "Font", |ui| {
123138
let mut v = self.state.theme.font.get().to_string();
124139
if text_edit(ui, &mut v).changed() {

src/it/test_config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@ impl TestConfig {
324324
self.send(ClientMessage::SetBarPosition { position })
325325
}
326326

327+
pub fn set_split_reuses_container(&self, reuse: bool) -> TestResult {
328+
self.send(ClientMessage::SetSplitReusesContainer { reuse })
329+
}
330+
331+
pub fn get_split_reuses_container(&self) -> Result<bool, TestError> {
332+
let reply = self.send_with_reply(ClientMessage::GetSplitReusesContainer)?;
333+
get_response!(reply, GetSplitReusesContainer { reuse });
334+
Ok(reuse)
335+
}
336+
327337
pub fn set_show_bar(&self, show: bool) -> TestResult {
328338
self.send(ClientMessage::SetShowBar { show })
329339
}

src/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ pub struct State {
402402
pub backend_connector_state_serials: BackendConnectorStateSerials,
403403
pub head_names: HeadNames,
404404
pub show_bar: Cell<bool>,
405+
pub split_reuses_container: Cell<bool>,
405406
pub enable_primary_selection: Cell<bool>,
406407
pub workspace_display_order: Cell<WorkspaceDisplayOrder>,
407408
pub outputs_without_hc: NumCell<usize>,

src/tree/container.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,10 @@ impl ContainerNode {
12311231
self.update_title();
12321232
}
12331233

1234+
pub fn num_children(&self) -> usize {
1235+
self.num_children.get()
1236+
}
1237+
12341238
pub fn set_split(self: &Rc<Self>, split: ContainerSplit) {
12351239
if self.set_ns_split(split) != split {
12361240
self.update_content_size();

0 commit comments

Comments
 (0)