Skip to content

Commit

Permalink
feat: reposition darwin traffic-lights in title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Jan 28, 2025
1 parent 83783a3 commit af3f98a
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 3 deletions.
5 changes: 5 additions & 0 deletions crates/gitbutler-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ tauri-plugin-single-instance = "2.2.0"
tauri-plugin-store = "2.2.0"
tauri-plugin-updater = "2.3.0"
tauri-plugin-window-state = "2.2.0"

[target.'cfg(target_os = "macos")'.dependencies]
# tauri-plugin-trafficlights-positioner = { git = "https://github.com/ItsEeleeya/tauri-plugin-trafficlights-positioner/" }
tauri-plugin-traffic-lights = { path = "../" }

parking_lot.workspace = true
log = "^0.4"
# The features here optimize for performance.
Expand Down
4 changes: 4 additions & 0 deletions crates/gitbutler-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fn main() {
)
.expect("Failed to create window");

#[cfg(target_os = "macos")]
// NOTE: Make sure you only call this ONCE per window.
let _ = window.setup_traffic_lights_inset(LogicalPosition::new(20.0, 24.0));

// TODO(mtsgrd): Is there a better way to disable devtools in E2E tests?
#[cfg(debug_assertions)]
if tauri_app.config().product_name != Some("GitButler Test".to_string()) {
Expand Down
18 changes: 15 additions & 3 deletions crates/gitbutler-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
"category": "DeveloperTool",
"copyright": "Copyright © 2023-2024 GitButler. All rights reserved.",
"createUpdaterArtifacts": "v1Compatible",
"targets": ["app", "dmg", "appimage", "deb", "rpm", "msi"],
"targets": [
"app",
"dmg",
"appimage",
"deb",
"rpm",
"msi"
],
"icon": [
"icons/dev/32x32.png",
"icons/dev/128x128.png",
Expand All @@ -25,10 +32,15 @@
},
"linux": {
"rpm": {
"depends": ["webkit2gtk4.1"]
"depends": [
"webkit2gtk4.1"
]
},
"deb": {
"depends": ["libwebkit2gtk-4.1-0", "libgtk-3-0"]
"depends": [
"libwebkit2gtk-4.1-0",
"libgtk-3-0"
]
}
}
},
Expand Down
19 changes: 19 additions & 0 deletions crates/tauri-plugin-traffic-lights/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "tauri-plugin-trafficlights-positioner"
version = "1.0.0"
authors = ["ItsEeleeya"]
description = "A Tauri v2 plugin to help setting the position of the window traffic lights on macOS."
edition = "2021"
rust-version = "1.60"
exclude = ["/example", ".github"]
license = "MIT"
repository = "https://github.com/itseeleeya/tauri-plugin-trafficlights-positioner/"
keywords = ["tauri", "tauri-plugin", "tauri-plugin-macos"]

[dependencies]
tauri = { version = "2.1.1" }

[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.26.0"
objc = "0.2.7"
rand = "0.8.5"
34 changes: 34 additions & 0 deletions crates/tauri-plugin-traffic-lights/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use tauri::{LogicalPosition, Runtime, Window};

#[cfg(target_os = "macos")]
mod positioner;

#[cfg(target_os = "macos")]
#[macro_use]
extern crate cocoa;

#[cfg(target_os = "macos")]
pub trait WindowExt {
fn setup_traffic_lights_inset(&self, offset: LogicalPosition<f64>) -> tauri::Result<()>;
}

#[cfg(target_os = "macos")]
impl<R: Runtime> WindowExt for Window<R> {
fn setup_traffic_lights_inset(&self, inset: LogicalPosition<f64>) -> tauri::Result<()> {
let win = self.clone();
self.on_window_event(move |event| {
if let tauri::WindowEvent::ThemeChanged(_) = event {
let win_clone = win.clone();

let _ = win.clone().run_on_main_thread(move || {
positioner::update(&win_clone, &inset);
});
}
});

let win = self.clone();
self.run_on_main_thread(move || {
positioner::setup_nswindow_delegates(win, inset);
})
}
}
Loading

0 comments on commit af3f98a

Please sign in to comment.