Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Window Controls Overlay #8707

Merged
merged 12 commits into from
Jul 16, 2023
25 changes: 25 additions & 0 deletions app/lib/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,19 @@ export class Window {
} else {
if (process.platform === 'darwin') {
bwOptions.titleBarStyle = 'hidden'
// If not macOS and native appearance is not toggled, use WCO.
} else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does WCO work on Linux? This code path implies it does, the comment in titleBar.component.scss implies it doesn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't, but good catch, will fix

bwOptions.titleBarStyle = 'hidden'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be moved out of the if

bwOptions.titleBarOverlay = {
color: '#00000000',
}
}
}

if (process.platform === 'darwin') {
this.window = new BrowserWindow(bwOptions) as GlasstronWindow
} else {
// this.window = new BrowserWindow(bwOptions) as GlasstronWindow
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean up commented code across the PR

this.window = new glasstron.BrowserWindow(bwOptions)
}

Expand Down Expand Up @@ -186,6 +193,7 @@ export class Window {
} catch (error) {
console.error('Failed to set window blur', error)
}
// }
} else {
DwmEnableBlurBehindWindow(this.window.getNativeWindowHandle(), enabled)
}
Expand Down Expand Up @@ -384,6 +392,23 @@ export class Window {
this.setVibrancy(enabled, type)
})

ipcMain.on('window-set-window-controls-color', (event, theme) => {
if (!this.window || event.sender !== this.window.webContents) {
return
}

// let color: string = theme.backgroundMore
const symbolColor: string = theme.foreground

this.window.setTitleBarOverlay(
{
// color: '#00000000',
symbolColor: symbolColor,
height: 32,
},
)
})

ipcMain.on('window-set-title', (event, title) => {
if (!this.window || event.sender !== this.window.webContents) {
return
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"cross-env": "7.0.3",
"css-loader": "^6.7.3",
"deep-equal": "2.0.5",
"electron": "22.3.1",
"electron": "^25.3.0",
"electron-builder": "^24.0.0-alpha.1",
"electron-download": "^4.1.1",
"electron-installer-snap": "^5.1.0",
Expand Down
11 changes: 9 additions & 2 deletions tabby-core/src/components/appRoot.component.pug
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
title-bar(
*ngIf='ready && !hostWindow.isFullscreen && config.store.appearance.frame == "full" && config.store.appearance.dock == "off"',
(dblclick)='hostWindow.toggleMaximize()',
[class.hide-controls]='hostApp.platform !== Platform.Linux && !hostWindow.isFullscreen',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be controlled via an @input on TitleBarComponent, not a class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the latest commit, window controls in the titlebar component is an ngIf now ✨

[class.inset]='hostApp.platform == Platform.macOS && !hostWindow.isFullscreen'
)

.content(
*ngIf='ready',
[class.tabs-on-top]='config.store.appearance.tabsLocation == "top" || config.store.appearance.tabsLocation == "left"',
[class.tabs-on-side]='hasVerticalTabs()',
[class.tabs-on-left]='hasVerticalTabs() && config.store.appearance.tabsLocation == "left"',
[class.tabs-titlebar-enabled]='config.store.appearance.frame == "full"',
[class.tabs-on-right]='hasVerticalTabs() && config.store.appearance.tabsLocation == "right"',
)
.tab-bar(
*ngIf='!hostWindow.isFullscreen || config.store.appearance.tabsInFullscreen',
[class.tab-bar-no-controls-overlay]='hostApp.platform == Platform.macOS',
(dblclick)='hostWindow.toggleMaximize()'
)
.inset.background(*ngIf='hostApp.platform == Platform.macOS \
Expand Down Expand Up @@ -81,9 +85,12 @@ title-bar(

window-controls.background(
*ngIf='config.store.appearance.frame == "thin" \
&& (hostApp.platform == Platform.Windows || hostApp.platform == Platform.Linux)',
&& (hostApp.platform == Platform.Linux)',
)

div.window-controls-spacer(
*ngIf='config.store.appearance.frame == "thin" && (hostApp.platform == Platform.Windows) && (config.store.appearance.tabsLocation == "top")',
)
.content
start-page.content-tab.content-tab-active(*ngIf='ready && app.tabs.length == 0')

Expand Down
32 changes: 25 additions & 7 deletions tabby-core/src/components/appRoot.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ $tab-border-radius: 4px;
flex-direction: column;
}

&.tabs-on-side {
&.tabs-on-right {
flex-direction: row-reverse;

&.tabs-on-top {
flex-direction: row;
}
}

&.tabs-on-left {
flex-direction: row;
}
}

.content.tabs-on-side > .tab-bar {
.content.tabs-on-left > .tab-bar, .content.tabs-on-right > .tab-bar {
height: 100%;
width: var(--side-tab-width);
overflow-y: auto;
Expand Down Expand Up @@ -76,6 +75,18 @@ $tab-border-radius: 4px;
}
}

.content.tabs-on-left > .tab-bar.tab-bar-no-controls-overlay, .content.tabs-titlebar-enabled {
.tabs {
padding-top: 0 !important;
}
}

.content.tabs-on-right > .tab-bar {
.tabs {
// Account for WCO on Windows.
padding-top: 36px;
}
}

.tab-bar {
flex: none;
Expand Down Expand Up @@ -125,10 +136,17 @@ $tab-border-radius: 4px;
}

&.persistent {
min-width: 72px; // 2 x 36 px height, ie 2 squares
// min-width: 72px; // 2 x 36 px height, ie 2 squares
// Given WCO on Windows, the min-width of the window buttons is about 138px.
min-width: 138px;
}
}

&>.window-controls-spacer {
min-width: 138px;
height: 100%;
}

& > .inset {
width: calc(70px + 15px * var(--spaciness));
height: var(--tabs-height);
Expand Down
7 changes: 7 additions & 0 deletions tabby-core/src/components/titleBar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ $titlebar-height: 30px;
display: none;
}
}

// Account for WCO on Windows.
&.hide-controls {
window-controls {
display: none;
}
}
}
12 changes: 12 additions & 0 deletions tabby-electron/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default class ElectronModule {
})
this.registerGlobalHotkey()
this.updateVibrancy()
this.updateWindowControlsColor()
})

config.changed$.subscribe(() => {
Expand Down Expand Up @@ -131,6 +132,8 @@ export default class ElectronModule {

config.changed$.subscribe(() => this.updateVibrancy())

config.changed$.subscribe(() => this.updateWindowControlsColor())

config.ready$.toPromise().then(() => {
dockMenu.update()
})
Expand Down Expand Up @@ -169,6 +172,15 @@ export default class ElectronModule {

this.hostWindow.setOpacity(this.config.store.appearance.opacity)
}

private updateWindowControlsColor () {
// if windows and not using native frame, WCO does not exist, return.
if (this.hostApp.platform === Platform.Windows && this.config.store.appearance.frame === 'native') {
return
}

this.electron.ipcRenderer.send('window-set-window-controls-color', this.config.store.terminal.colorScheme)
}
}

export { ElectronHostWindow, ElectronHostAppService, ElectronService }
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.3.1.tgz#e8a83f1aa8b649377bb1fb5d7bac5cb90e784dfe"
integrity sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==

"@types/node@^16.11.26":
version "16.11.26"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.26.tgz#63d204d136c9916fb4dcd1b50f9740fe86884e47"
integrity sha512-GZ7bu5A6+4DtG7q9GsoHXy3ALcgeIHP4NnL0Vv2wu0uUB/yQex26v0tf6/na1mm0+bS9Uw+0DFex7aaKr2qawQ==
"@types/node@^18.11.18":
version "18.16.19"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.16.19.tgz#cb03fca8910fdeb7595b755126a8a78144714eea"
integrity sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==

"@types/parse5@^5":
version "5.0.3"
Expand Down Expand Up @@ -3066,13 +3066,13 @@ electron-to-chromium@^1.4.284:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.286.tgz#0e039de59135f44ab9a8ec9025e53a9135eba11f"
integrity sha512-Vp3CVhmYpgf4iXNKAucoQUDcCrBQX3XLBtwgFqP9BUXuucgvAV9zWp1kYU7LL9j4++s9O+12cb3wMtN4SJy6UQ==

electron@22.3.1:
version "22.3.1"
resolved "https://registry.yarnpkg.com/electron/-/electron-22.3.1.tgz#a09769e6592cadbf45d7629c9143ffa2ef8a3842"
integrity sha512-iDltL9j12bINK3aOp8ZoGq4NFBFjJhw1AYHelbWj93XUCAIT4fdA+PRsq0aaTHg3bthLLlLRvIZVgNsZPqWcqg==
electron@^25.3.0:
version "25.3.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-25.3.0.tgz#e818ab3ebd3e7a45f8fca0f47e607c9af2dc92c7"
integrity sha512-cyqotxN+AroP5h2IxUsJsmehYwP5LrFAOO7O7k9tILME3Sa1/POAg3shrhx4XEnaAMyMqMLxzGvkzCVxzEErnA==
dependencies:
"@electron/get" "^2.0.0"
"@types/node" "^16.11.26"
"@types/node" "^18.11.18"
extract-zip "^2.0.1"

elliptic@^6.5.3:
Expand Down