PDA

View Full Version : setting EWM (extended window manager) hints via Qt4 (X11)



nupul
28th March 2006, 09:09
In the Qt Namespace we can set a myriad Qt::WindowFlags. However is it possible to set some flags which are not mentioned/provided....eg. setting the EWM hints (extended window manager hints) a.k.a NETWM hints as per the ICCCM specification on:

www.freedesktop.org/wiki/standards/wm-spec.html

eg

_NET_WM_WINDOW_TYPE_DOCK indicates a dock or panel feature. Typically a Window Manager would keep such windows on top of all other windows....i.e. what i want to know whether i can set NETWM hints via Qt especially which don't have a mention in the Qt4 Doc.

:(

Thanks

Nupul

Chicken Blood Machine
28th March 2006, 18:13
You can use XSetWMHints like this :



#include <X11/Xlib.h>
#include <Q11Info>

// In widget constructor

// Allocate a hint structure - don't forget to XFree() in destructor!
XWMHints* hints(XAllocWMHints());

// Populate the hints structure with the hints you want to activate here.
// hints->flags = ...etc.

// Set the hints on the X11 window for the widget.
XSetWMHints(QX11Info::display(), static_cast<Window>(this->winId()), hints);


Be careful though, it will hardly be portable...

Chicken Blood Machine
28th March 2006, 18:29
Actually, if you have problems with that, I've just found some code I implemented a long time ago when using Qt3. It created a non-resizable border for dialogs (now not required in Qt4 as it is done automatically). If you modify this to set your specific EWM hints, it should work:


#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

#include <QX11Info>

void MyWidget::callIfWidgetIsTopLevelAndNonResizeable()
{
struct PropMotifWmHints
{
unsigned long flags;
unsigned long functions;
unsigned long decorations;
long inputMode;
unsigned long status;
};
#define QT_XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS"
#define QT_MWM_HINTS_FUNCTIONS 0x01
#define QT_MWM_HINTS_DECORATIONS 0x10
#define QT_MWM_ALL_FUNCS_WITHOUT_RESIZE 0x3C
#define QT_MWM_ALL_DECOR_WITHOUT_RESIZE_HANDLE 0x7A

PropMotifWmHints prop = {0};
prop.flags |= QT_MWM_HINTS_FUNCTIONS | QT_MWM_HINTS_DECORATIONS;
prop.functions |= QT_MWM_ALL_FUNCS_WITHOUT_RESIZE;
prop.decorations |= QT_MWM_ALL_DECOR_WITHOUT_RESIZE_HANDLE;

Atom atom = XInternAtom(x11Display(), QT_XA_MOTIF_WM_HINTS, false);
XChangeProperty(QX11Info::display(),
winId(),
atom, atom,
32,
PropModeReplace,
(u_char*) &prop,
sizeof(PropMotifWmHints) / sizeof(long));
}

nupul
29th March 2006, 05:05
hey chicken blood machine (CBM)!!,

THANKS A MILLION FOR THE HELP!!!
:D

Well I just want to know a few things in your code.

1.
XSetWMHints(QX11Info::display(), static_cast<Window>(this->winId()), hints);

Please elaborate on the use of QX11Info::display(), and static_cast...
w.r.t. the given function XSetWMHints();

2.
#define QT_XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS"
#define QT_MWM_HINTS_FUNCTIONS 0x01
#define QT_MWM_HINTS_DECORATIONS 0x10
#define QT_MWM_ALL_FUNCS_WITHOUT_RESIZE 0x3C
#define QT_MWM_ALL_DECOR_WITHOUT_RESIZE_HANDLE 0x7A

These are all user defined Macros, right? and why the specific Hex values, where did you get these from?

Do reply,

Thanks once again

Nupul

Chicken Blood Machine
29th March 2006, 23:44
1.
XSetWMHints(QX11Info::display(), static_cast<Window>(this->winId()), hints);

Please elaborate on the use of QX11Info::display(), and static_cast...
w.r.t. the given function XSetWMHints();


The first arg is the X11 display id being used by your application. This can be accessed with QX11Info::display().

The second arg to XSetWMHints expects an X11 window id. QWidget::winId() returns the correct value to use here, but out of laziness, I added the cast, because I wasn't sure how the Qt WId type had been defined. Actually, I've just checked and it's defined as an int. A X11 'Window' is defined as an integral type on most implementations, but the cast is just there for thoroughness.



#define QT_XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS"
#define QT_MWM_HINTS_FUNCTIONS 0x01
#define QT_MWM_HINTS_DECORATIONS 0x10
#define QT_MWM_ALL_FUNCS_WITHOUT_RESIZE 0x3C
#define QT_MWM_ALL_DECOR_WITHOUT_RESIZE_HANDLE 0x7A

These are all user defined Macros, right? and why the specific Hex values, where did you get these from?


I actually copied these values from a Motif header. I wanted to know the values of the MWM (Motif Window manager) hints that I needed, but I did not want my program to rely on Motif in any way. You can ignore these defines and just replace them with the NETWM values that you need to define.

Let me know how you get on.