Skip to content

Commit 0aa2176

Browse files
authored
feat: add set_visible_on_all_workspaces, closes #185 (#666)
* feat: add `set_visible_on_all_workspaces`, closes #185 * fix macOS implementation * fix macOS * remove moveToActiveSpace flag
1 parent 9927c3a commit 0aa2176

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tao": "patch"
3+
---
4+
5+
Add `WindowBuilder::with_visible_on_all_workspaces` and `Window::set_visible_on_all_workspaces`.

src/platform_impl/linux/event_loop.rs

+7
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ impl<T: 'static> EventLoop<T> {
262262
window.set_skip_taskbar_hint(skip);
263263
window.set_skip_pager_hint(skip)
264264
}
265+
WindowRequest::SetVisibleOnAllWorkspaces(visible) => {
266+
if visible {
267+
window.stick();
268+
} else {
269+
window.unstick();
270+
}
271+
}
265272
WindowRequest::CursorIcon(cursor) => {
266273
if let Some(gdk_window) = window.window() {
267274
let display = window.display();

src/platform_impl/linux/window.rs

+14
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ impl Window {
222222
window.set_keep_above(attributes.always_on_top);
223223
}
224224

225+
if attributes.visible_on_all_workspaces {
226+
window.stick();
227+
}
228+
225229
if let Some(icon) = attributes.window_icon {
226230
window.set_icon(Some(&icon.inner.into()));
227231
}
@@ -681,6 +685,15 @@ impl Window {
681685
self.menu_bar.get_visible()
682686
}
683687

688+
pub fn set_visible_on_all_workspaces(&self, visible: bool) {
689+
if let Err(e) = self.window_requests_tx.send((
690+
self.window_id,
691+
WindowRequest::SetVisibleOnAllWorkspaces(visible),
692+
)) {
693+
log::warn!("Fail to send visible on all workspaces request: {}", e);
694+
}
695+
}
696+
684697
pub fn set_cursor_icon(&self, cursor: CursorIcon) {
685698
if let Err(e) = self
686699
.window_requests_tx
@@ -867,6 +880,7 @@ pub enum WindowRequest {
867880
Menu((Option<MenuItem>, Option<MenuId>)),
868881
SetMenu((Option<menu::Menu>, AccelGroup, gtk::MenuBar)),
869882
GlobalHotKey(u16),
883+
SetVisibleOnAllWorkspaces(bool),
870884
}
871885

872886
pub fn hit_test(window: &gdk::Window, cx: f64, cy: f64) -> WindowEdge {

src/platform_impl/macos/window.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use crate::{
4141
use cocoa::{
4242
appkit::{
4343
self, CGFloat, NSApp, NSApplication, NSApplicationPresentationOptions, NSColor, NSEvent,
44-
NSRequestUserAttentionType, NSScreen, NSView, NSWindow, NSWindowButton, NSWindowOrderingMode,
45-
NSWindowStyleMask,
44+
NSRequestUserAttentionType, NSScreen, NSView, NSWindow, NSWindowButton,
45+
NSWindowCollectionBehavior, NSWindowOrderingMode, NSWindowStyleMask,
4646
},
4747
base::{id, nil},
4848
foundation::{
@@ -519,6 +519,7 @@ impl UnownedWindow {
519519
let visible = win_attribs.visible;
520520
let focused = win_attribs.focused;
521521
let decorations = win_attribs.decorations;
522+
let visible_on_all_workspaces = win_attribs.visible_on_all_workspaces;
522523
let inner_rect = win_attribs
523524
.inner_size
524525
.map(|size| size.to_physical(scale_factor));
@@ -551,6 +552,7 @@ impl UnownedWindow {
551552

552553
// Set fullscreen mode after we setup everything
553554
window.set_fullscreen(fullscreen);
555+
window.set_visible_on_all_workspaces(visible_on_all_workspaces);
554556

555557
// Setting the window as key has to happen *after* we set the fullscreen
556558
// state, since otherwise we'll briefly see the window at normal size
@@ -1360,6 +1362,20 @@ impl UnownedWindow {
13601362
let _: () = msg_send![*self.ns_window, setSharingType: !enabled as i32];
13611363
}
13621364
}
1365+
1366+
pub fn set_visible_on_all_workspaces(&self, visible: bool) {
1367+
unsafe {
1368+
let mut collection_behavior = self.ns_window.collectionBehavior();
1369+
if visible {
1370+
collection_behavior |=
1371+
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces;
1372+
} else {
1373+
collection_behavior &=
1374+
!NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces;
1375+
};
1376+
self.ns_window.setCollectionBehavior_(collection_behavior)
1377+
}
1378+
}
13631379
}
13641380

13651381
impl WindowExtMacOS for UnownedWindow {

src/window.rs

+29
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ pub struct WindowAttributes {
243243
///
244244
/// - **iOS / Android / Linux:** Unsupported.
245245
pub content_protection: bool,
246+
247+
/// Sets whether the window should be visible on all workspaces.
248+
///
249+
/// ## Platform-specific
250+
///
251+
/// - **iOS / Android / Windows:** Unsupported.
252+
pub visible_on_all_workspaces: bool,
246253
}
247254

248255
impl Default for WindowAttributes {
@@ -270,6 +277,7 @@ impl Default for WindowAttributes {
270277
preferred_theme: None,
271278
focused: true,
272279
content_protection: false,
280+
visible_on_all_workspaces: false,
273281
}
274282
}
275283
}
@@ -505,6 +513,17 @@ impl WindowBuilder {
505513
self
506514
}
507515

516+
/// Sets whether the window should be visible on all workspaces.
517+
///
518+
/// ## Platform-specific
519+
///
520+
/// - **iOS / Android / Windows:** Unsupported.
521+
#[inline]
522+
pub fn with_visible_on_all_workspaces(mut self, visible: bool) -> WindowBuilder {
523+
self.window.visible_on_all_workspaces = visible;
524+
self
525+
}
526+
508527
/// Builds the window.
509528
///
510529
/// Possible causes of error include denied permission, incompatible system, and lack of memory.
@@ -1089,6 +1108,16 @@ impl Window {
10891108
#[cfg(any(target_os = "macos", target_os = "windows"))]
10901109
self.window.set_content_protection(enabled);
10911110
}
1111+
1112+
/// Sets whether the window should be visible on all workspaces.
1113+
///
1114+
/// ## Platform-specific
1115+
///
1116+
/// - **iOS / Android / Windows:** Unsupported.
1117+
pub fn set_visible_on_all_workspaces(&self, #[allow(unused)] visible: bool) {
1118+
#[cfg(any(target_os = "macos", target_os = "linux"))]
1119+
self.window.set_visible_on_all_workspaces(visible)
1120+
}
10921121
}
10931122

10941123
/// Cursor functions.

0 commit comments

Comments
 (0)