-1

I just want to make a sample app when the only possible action is close. Is this possible with Unity(Ubuntu) ? Do i make a mistake ?

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
static void only_close(Display *display, Window window)
{

    int retval;
    Atom aa = XInternAtom(display, "_NET_WM_ALLOWED_ACTIONS", False);
    Atom close = XInternAtom(display, " _NET_WM_ACTION_CLOSE", False);

    retval = XChangeProperty(display, window, aa, XA_ATOM, 32, PropModeReplace, (unsigned char*)close,  1);

    printf("###### XChangeProperty() reted %d\n", retval);
}

int main()
{

    Display *dis;
    Window win;

    dis = XOpenDisplay(NULL);
    win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 500, 500, \
                              0, BlackPixel (dis, 0), BlackPixel(dis, 0));
    XMapWindow(dis, win);
    printf("window %i\n", (int)win);
    only_close(dis, win);
    XFlush(dis);
    sleep(10);
    return(0);
}
  • You're asking us if you've made a mistake, have you tried compiling the code in the first place? If so, what error are you getting? Please refer to the help on [How to ask a good question](http://stackoverflow.com/help/how-to-ask). – Enfyve Oct 28 '16 at 14:10
  • I have actually no error. To be totally explicit nothing append. All action (resize, minimize, full screen ...) are allowed – Preovaleo Oct 28 '16 at 14:13
  • Requires more detail, what's the error? See first comment – Ol1v3r Oct 28 '16 at 14:14
  • @Preovaleo as Oliver said, more detail is needed. Also, update your question to include the fact that a window was created but but that all actions are still enabled. **edit -** refer to the documentation, xlib likely has default properties, so you'd need to override them all to false and only enable `_NET_WM_ACTION_CLOSE` – Enfyve Oct 28 '16 at 14:29

1 Answers1

0

First, you need (unsigned char*)&close (an address of the data)

Second, you are setting the property too early, before WM has a chance to manage the window. A WM must discard the old value of this property when it first manages the window. Try after the first expose event, or just after a delay of 1 second.

Third, it is not guaranteed to work. On my machine (not Unity) the window actions in the taskbar are indeed disabled, but the window frame still has them the WM still allows them. I don't know if it's a bug in my WM or not.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • I tried setting the _NET_WM_ALLOWED_ACTIONS property on every redraw of my window, and the window manager (XFCE) didn't seem to care. – Aaron Wright Feb 17 '22 at 23:58