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

feat: smartgaps: Hide gaps if showing a single window #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/config/bismuth_config.kcfg
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
<default>0</default>
</entry>

<entry name="smartGaps" type="Bool">
<label>Hide gaps if showing a single window</label>
<default>false</default>
</entry>

<entry name="limitTileWidth" type="Bool">
<label>Limit the width of tiles</label>
<default>false</default>
Expand Down
2 changes: 1 addition & 1 deletion src/core/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ Surface Engine::activeSurface() const
void Engine::arrangeWindowsOnSurface(const Surface &surface)
{
auto &layout = m_activeLayouts.layoutOnSurface(surface);
auto tilingArea = layout.tilingArea(workingArea(surface));

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

auto tilingArea = layout.tilingArea(workingArea(surface), windowsThatCanBeTiled);
layout.apply(tilingArea, windowsThatCanBeTiled);
}

Expand Down
6 changes: 5 additions & 1 deletion src/core/engine/layout/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ Layout::Layout(const Bismuth::Config &config)
{
}

QRect Layout::tilingArea(QRect workingArea) const
QRect Layout::tilingArea(QRect workingArea, std::vector<Window> &windows) const
{
if (windows.size() == 1 && m_config.smartGaps()) {
return workingArea;
}

auto marginLeft = m_config.screenGapLeft();
auto marginTop = m_config.screenGapTop();
auto marginRight = m_config.screenGapRight();
Expand Down
2 changes: 1 addition & 1 deletion src/core/engine/layout/layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Layout {
/**
* Get the area on which tiled windows could be placed given the general @p workingArea
*/
virtual QRect tilingArea(QRect workingArea) const;
virtual QRect tilingArea(QRect workingArea, std::vector<Window> &windows) const;

protected:
const Bismuth::Config &m_config;
Expand Down
1 change: 1 addition & 0 deletions src/core/ts-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ QJSValue TSProxy::jsConfig()
setProp("screenGapRight", m_config.screenGapRight());
setProp("screenGapTop", m_config.screenGapTop());
setProp("tileLayoutGap", m_config.tileLayoutGap());
setProp("smartGaps", m_config.smartGaps());

setProp("newWindowAsMaster", m_config.newWindowAsMaster());
setProp("layoutPerActivity", m_config.layoutPerActivity());
Expand Down
5 changes: 5 additions & 0 deletions src/kcm/package/contents/ui/Appearance.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Kirigami.FormLayout {
Kirigami.FormData.label: "Inner Gaps"
}

BIC.ConfigCheckBox {
text: i18n("Hide gaps if showing a single window")
settingName: "smartGaps"
}

BIC.PixelsConfigSpinBox {
Kirigami.FormData.label: i18n("All:")
settingName: "tileLayoutGap"
Expand Down
1 change: 1 addition & 0 deletions src/kwinscript/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Config {
screenGapRight: number;
screenGapTop: number;
tileLayoutGap: number;
smartGaps: boolean;
//#endregion

//#region Behavior
Expand Down
53 changes: 31 additions & 22 deletions src/kwinscript/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ export class EngineImpl implements Engine {
const srf = basis.surface;
const layout = this.layouts.getCurrentLayout(srf);
if (layout.adjust) {
const area = srf.workingArea.gap(
this.config.screenGapLeft,
this.config.screenGapRight,
this.config.screenGapTop,
this.config.screenGapBottom
);
const tiles = this.windows.visibleTiledWindowsOn(srf);
const noGaps = tiles.length == 1 && this.config.smartGaps;
const area = noGaps
? srf.workingArea
: srf.workingArea.gap(
this.config.screenGapLeft,
this.config.screenGapRight,
this.config.screenGapTop,
this.config.screenGapBottom
);
layout.adjust(area, tiles, basis, basis.geometryDelta);
}
}
Expand Down Expand Up @@ -285,18 +288,17 @@ export class EngineImpl implements Engine {

const layout = this.layouts.getCurrentLayout(srf);
if (layout.adjust) {
const area = srf.workingArea.gap(
this.config.screenGapLeft,
this.config.screenGapRight,
this.config.screenGapTop,
this.config.screenGapBottom
);
layout.adjust(
area,
this.windows.visibleTileableWindowsOn(srf),
basis,
delta
);
const tiles = this.windows.visibleTiledWindowsOn(srf);
const noGaps = tiles.length == 1 && this.config.smartGaps;
const area = noGaps
? srf.workingArea
: srf.workingArea.gap(
this.config.screenGapLeft,
this.config.screenGapRight,
this.config.screenGapTop,
this.config.screenGapBottom
);
layout.adjust(area, tiles, basis, delta);
}
}

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

const workingArea = screenSurface.workingArea;
const tilingArea = this.getTilingArea(workingArea, layout);

const visibleWindows = this.windows.visibleWindowsOn(screenSurface);
const tilingArea = this.getTilingArea(workingArea, layout, visibleWindows);

// Set correct window state for new windows
visibleWindows.forEach((win: EngineWindow) => {
Expand Down Expand Up @@ -740,9 +741,17 @@ export class EngineImpl implements Engine {
*
* @param workingArea area in which we are allowed to work. @see DriverSurface#workingArea
* @param layout windows layout used
* @param visibleWindows the windows visible in the working area.
*/
private getTilingArea(workingArea: Rect, layout: WindowsLayout): Rect {
if (this.config.monocleMaximize && layout instanceof MonocleLayout) {
private getTilingArea(
workingArea: Rect,
layout: WindowsLayout,
visibleWindows: EngineWindow[]
): Rect {
if (
(this.config.monocleMaximize && layout instanceof MonocleLayout) ||
(visibleWindows.length == 1 && this.config.smartGaps)
) {
return workingArea;
} else {
return workingArea.gap(
Expand Down