How can I move application's window between virtual desktops in OS X?
I have found answer by my self. This could be done by adjusting window behaviour.
let window = NSWindow...
Window is shown on all virtual desktops:
window.collectionBehavior = NSWindowCollectionBehavior.CanJoinAllSpaces
Window follows active virtual desktop:
window.collectionBehavior = NSWindowCollectionBehavior.MoveToActiveSpace
Keeping a window on the active OS X desktop
If you set the window flag Qt::Popup
it should display on the active desktop space, it's how QMessageBox works IIRC and that definitely displays on the active desktop space.
Edit; https://stackoverflow.com/a/16882717/741595 shows how to do it using the Cocoa bridge.
Keep a application window always on current desktop on linux and mac
Thanks to Jan Kundrát for his help (Previous comment https://stackoverflow.com/a/16777496/1045832 ).
Solution for linux X11 :
#ifdef Q_WS_X11 //only define on Qt 4.X
#include <QX11Info> //Only on Qt 4.X , return expected in Qt 5.1
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
YourWidget::YourWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::YourWidget)
{
#ifdef Q_WS_X11 //only define on Qt 4.X
unsigned long data = 0xFFFFFFFF;
XChangeProperty (QX11Info::display(),
winId(),
XInternAtom(QX11Info::display(), "_NET_WM_DESKTOP", False),
XA_CARDINAL,
32,
PropModeReplace,
reinterpret_cast<unsigned char *>(&data), // all desktop
1);
#endif
}
Put this on your .pro
unix:!macx {
LIBS += -lX11
}
Solution for macos X :
#include <objc/objc-runtime.h>
WId windowObject = this->winId();
objc_object * nsviewObject = reinterpret_cast<objc_object *>(windowObject);
objc_object * nsWindowObject = objc_msgSend(nsviewObject, sel_registerName("window"));
int NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0;
objc_msgSend(nsWindowObject, sel_registerName("setCollectionBehavior:"), NSWindowCollectionBehaviorCanJoinAllSpaces);
Put this on your .pro
macx {
LIBS += -lobjc
}
Related Topics
Type of Expression Is Ambiguous Without More Context in Xcode 11
Zoom to Fit Current Location and Annotation on Map
Convert Optional String to Int in Swift
File Couldn't Be Opened Because You Don't Have Permission to View It Error
Compile Time Key Path Checking in Swift
How to Insert a Sublayer in Swift
Swift Struct with Lazy, Private Property Conforming to Protocol
Using Uilexicon to Implement Autocorrect in iOS 8 Keyboard Extension
How to Restrict an Enum to Certain Cases of Another Enum
How to Switch to Swift 4.0 in Xcode 9.3
Core Image Filter Cisourceovercompositing Not Appearing as Expected with Alpha Overlay
How to 'Addtarget' to Uilabel in Swift
Swift Change the Tableviewcell Border Color According to Data
How to Split a String into a [String] and Not [Substring]
Codable Enum with Multiple Keys and Associated Values