保持应用程序窗口总是在当前桌面上的linux和mac [英] Keep a application window always on current desktop on linux and mac

查看:353
本文介绍了保持应用程序窗口总是在当前桌面上的linux和mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索一种方式,将Qt应用程序的QWidget窗口始终放在当前桌面/工作区上。
当我更改虚拟桌面时,我需要在新的当前虚拟桌面上自动显示我的窗口。



我搜索一个解决方案, gnome,kde on linux和mac os。



我认为第一步是检测虚拟桌面是否发生变化,我不知道Qt是否有API



预先感谢所有帮助。

解决方案

感谢JanKundrát的帮助(上一则评论 http://stackoverflow.com/a/16777496) / 1045832 )。



针对linux X11的解决方案:

  #ifdef Q_WS_X11 //只定义Qt 4.X 
#include< QX11Info> //只在Qt 4.X,返回预期在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 //只定义Qt 4.X
无符号长数据= 0xFFFFFFFF;
XChangeProperty(QX11Info :: display(),
winId(),
XInternAtom(QX11Info :: display(),_NET_WM_DESKTOP,False),
XA_CARDINAL,
32,
PropModeReplace,
reinterpret_cast< unsigned char *>(& data),//所有桌面
1);
#endif
}



  unix:!macx {
LIBS + = -lX11
}



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);

将这个放在您的.pro

  macx {
LIBS + = -lobjc
}


I search a way to put a QWidget window of a Qt application always on the current desktop/workspace. When I change the virtual desktop, I need my window to be automatically visible on the new current virtual desktop.

I search a solution that works at minimum on gnome, kde on linux and mac os.

I think the first step is to detect when virtual desktop is change, I don't know if Qt have a API for that or if I need to implement it for each desktop solution.

Thanks in advance for all help.

解决方案

Thanks to Jan Kundrát for his help (Previous comment http://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
}

这篇关于保持应用程序窗口总是在当前桌面上的linux和mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆