Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.

Commit d49a2f8

Browse files
committed
[feat] smartgaps: Hide gaps if showing a single window
Currently disabled by default but adds a toggle that will hide gaps if only a single window is visible. The feature is implemented both in the cpp and ts engines.
1 parent df033fd commit d49a2f8

File tree

8 files changed

+50
-25
lines changed

8 files changed

+50
-25
lines changed

src/config/bismuth_config.kcfg

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
<default>0</default>
164164
</entry>
165165

166+
<entry name="smartGaps" type="Bool">
167+
<label>Hide gaps if showing a single window</label>
168+
<default>false</default>
169+
</entry>
170+
166171
<entry name="limitTileWidth" type="Bool">
167172
<label>Limit the width of tiles</label>
168173
<default>false</default>

src/core/engine/engine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ Surface Engine::activeSurface() const
230230
void Engine::arrangeWindowsOnSurface(const Surface &surface)
231231
{
232232
auto &layout = m_activeLayouts.layoutOnSurface(surface);
233-
auto tilingArea = layout.tilingArea(workingArea(surface));
234233

235234
auto visibleWindows = m_windows.visibleWindowsOn(surface);
236235
auto windowsThatCanBeTiled = visibleWindows; // TODO: Filter windows
237236

237+
auto tilingArea = layout.tilingArea(workingArea(surface), windowsThatCanBeTiled);
238238
layout.apply(tilingArea, windowsThatCanBeTiled);
239239
}
240240

src/core/engine/layout/layout.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ Layout::Layout(const Bismuth::Config &config)
1010
{
1111
}
1212

13-
QRect Layout::tilingArea(QRect workingArea) const
13+
QRect Layout::tilingArea(QRect workingArea, std::vector<Window> &windows) const
1414
{
15+
if (windows.size() == 1 && m_config.smartGaps()) {
16+
return workingArea;
17+
}
18+
1519
auto marginLeft = m_config.screenGapLeft();
1620
auto marginTop = m_config.screenGapTop();
1721
auto marginRight = m_config.screenGapRight();

src/core/engine/layout/layout.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Layout {
2424
/**
2525
* Get the area on which tiled windows could be placed given the general @p workingArea
2626
*/
27-
virtual QRect tilingArea(QRect workingArea) const;
27+
virtual QRect tilingArea(QRect workingArea, std::vector<Window> &windows) const;
2828

2929
protected:
3030
const Bismuth::Config &m_config;

src/core/ts-proxy.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ QJSValue TSProxy::jsConfig()
7575
setProp("screenGapRight", m_config.screenGapRight());
7676
setProp("screenGapTop", m_config.screenGapTop());
7777
setProp("tileLayoutGap", m_config.tileLayoutGap());
78+
setProp("smartGaps", m_config.smartGaps());
7879

7980
setProp("newWindowAsMaster", m_config.newWindowAsMaster());
8081
setProp("layoutPerActivity", m_config.layoutPerActivity());

src/kcm/package/contents/ui/Appearance.qml

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Kirigami.FormLayout {
4141
Kirigami.FormData.label: "Inner Gaps"
4242
}
4343

44+
BIC.ConfigCheckBox {
45+
text: i18n("Hide gaps if showing a single window")
46+
settingName: "smartGaps"
47+
}
48+
4449
BIC.PixelsConfigSpinBox {
4550
Kirigami.FormData.label: i18n("All:")
4651
settingName: "tileLayoutGap"

src/kwinscript/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface Config {
2626
screenGapRight: number;
2727
screenGapTop: number;
2828
tileLayoutGap: number;
29+
smartGaps: boolean;
2930
//#endregion
3031

3132
//#region Behavior

src/kwinscript/engine/index.ts

+31-22
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@ export class EngineImpl implements Engine {
191191
const srf = basis.surface;
192192
const layout = this.layouts.getCurrentLayout(srf);
193193
if (layout.adjust) {
194-
const area = srf.workingArea.gap(
195-
this.config.screenGapLeft,
196-
this.config.screenGapRight,
197-
this.config.screenGapTop,
198-
this.config.screenGapBottom
199-
);
200194
const tiles = this.windows.visibleTiledWindowsOn(srf);
195+
const noGaps = tiles.length == 1 && this.config.smartGaps;
196+
const area = noGaps
197+
? srf.workingArea
198+
: srf.workingArea.gap(
199+
this.config.screenGapLeft,
200+
this.config.screenGapRight,
201+
this.config.screenGapTop,
202+
this.config.screenGapBottom
203+
);
201204
layout.adjust(area, tiles, basis, basis.geometryDelta);
202205
}
203206
}
@@ -285,18 +288,17 @@ export class EngineImpl implements Engine {
285288

286289
const layout = this.layouts.getCurrentLayout(srf);
287290
if (layout.adjust) {
288-
const area = srf.workingArea.gap(
289-
this.config.screenGapLeft,
290-
this.config.screenGapRight,
291-
this.config.screenGapTop,
292-
this.config.screenGapBottom
293-
);
294-
layout.adjust(
295-
area,
296-
this.windows.visibleTileableWindowsOn(srf),
297-
basis,
298-
delta
299-
);
291+
const tiles = this.windows.visibleTiledWindowsOn(srf);
292+
const noGaps = tiles.length == 1 && this.config.smartGaps;
293+
const area = noGaps
294+
? srf.workingArea
295+
: srf.workingArea.gap(
296+
this.config.screenGapLeft,
297+
this.config.screenGapRight,
298+
this.config.screenGapTop,
299+
this.config.screenGapBottom
300+
);
301+
layout.adjust(area, tiles, basis, delta);
300302
}
301303
}
302304

@@ -330,9 +332,8 @@ export class EngineImpl implements Engine {
330332
const layout = this.layouts.getCurrentLayout(screenSurface);
331333

332334
const workingArea = screenSurface.workingArea;
333-
const tilingArea = this.getTilingArea(workingArea, layout);
334-
335335
const visibleWindows = this.windows.visibleWindowsOn(screenSurface);
336+
const tilingArea = this.getTilingArea(workingArea, layout, visibleWindows);
336337

337338
// Set correct window state for new windows
338339
visibleWindows.forEach((win: EngineWindow) => {
@@ -740,9 +741,17 @@ export class EngineImpl implements Engine {
740741
*
741742
* @param workingArea area in which we are allowed to work. @see DriverSurface#workingArea
742743
* @param layout windows layout used
744+
* @param visibleWindows the windows visible in the working area.
743745
*/
744-
private getTilingArea(workingArea: Rect, layout: WindowsLayout): Rect {
745-
if (this.config.monocleMaximize && layout instanceof MonocleLayout) {
746+
private getTilingArea(
747+
workingArea: Rect,
748+
layout: WindowsLayout,
749+
visibleWindows: EngineWindow[]
750+
): Rect {
751+
if (
752+
(this.config.monocleMaximize && layout instanceof MonocleLayout) ||
753+
(visibleWindows.length == 1 && this.config.smartGaps)
754+
) {
746755
return workingArea;
747756
} else {
748757
return workingArea.gap(

0 commit comments

Comments
 (0)