Compare commits

...

2 Commits

3 changed files with 80 additions and 60 deletions

View File

@ -21,6 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "wm.h"
#include <X11/X.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
// TODO
XWindowChanges wm_client_to_xwchanges(Client c)
@ -93,6 +96,49 @@ Client* wm_client_create(Wm *wm, Window w)
return c;
}
void wm_client_handle_window_types(Wm *wm, Client *c, XMapRequestEvent e)
{
DEBUG_PRINT("%s\n", __func__);
RETURN_IF_NULL(c);
unsigned char *prop_ret;
unsigned long nitems_ret;
Atom type;
bool is_normal = false;
type = wm_client_get_atom(wm, c, "_NET_WM_WINDOW_TYPE", &prop_ret, &nitems_ret);
if (type == ULONG_MAX) {
fprintf(stderr, "wm_client_get_atom failed\n");
return;
}
for (size_t i = 0; i < nitems_ret; i++) {
DEBUG_PRINT("ConfigureRequest handler: window %d has property %s\n",
(int)e.window, XGetAtomName(wm->display, ((Atom*)prop_ret)[i]));
if (strcmp(XGetAtomName(wm->display, ((Atom*)prop_ret)[i]),
"_NET_WM_WINDOW_TYPE_NORMAL") == 0) {
is_normal = true;
} else if (strcmp(XGetAtomName(wm->display, ((Atom*)prop_ret)[i]),
"_NET_WM_WINDOW_TYPE_DOCK") == 0) {
// wm->dock = e.window;
fprintf(stderr, "client should not have _NET_WM_WINDOW_TYPE_DOCK type\n");
// todo function to exit
exit(1);
} else if (strcmp(XGetAtomName(wm->display, ((Atom*)prop_ret)[i]),
"_NET_WM_WINDOW_TYPE_DIALOG") == 0) {
c->is_floating = true;
}
}
if (!is_normal) {
DEBUG_PRINT("configure handler: window %d is not normal\n",
(int)e.window)
// wm_client_kill(wm, c);
return;
}
}
void wm_client_hide(Wm *wm, Client *c)
{
RETURN_IF_NULL(c);
@ -212,13 +258,13 @@ Atom wm_client_get_atom(Wm *wm, Client *c, const char *name, unsigned char **ato
unsigned long *nitems_ret)
{
if (!c)
return -1;
return ULONG_MAX;
if (!name)
return -1;
return ULONG_MAX;
if (!atom_ret)
return -1;
return ULONG_MAX;
if (!nitems_ret)
return -1;
return ULONG_MAX;
Atom type_ret;
int format_ret;
@ -232,7 +278,7 @@ Atom wm_client_get_atom(Wm *wm, Client *c, const char *name, unsigned char **ato
if (ret != Success || (nitems_ret == 0 && type_ret == 0)) {
fprintf(stderr, "wm: XGetWindowProperty failed\n");
return -1;
return ULONG_MAX;
}
DEBUG_PRINT("XGetWindowProperty return values, window %d:\n", (int)c->window);

View File

@ -26,6 +26,7 @@ XWindowChanges wm_client_to_xwchanges(Client c);
Client* wm_client_find(Wm* wm, Window w);
Client *wm_get_last_client(Wm *wm, Monitor m);
Client* wm_client_create(Wm *wm, Window w);
void wm_client_handle_window_types(Wm *wm, Client *c, XMapRequestEvent e);
void wm_client_hide(Wm *wm, Client *c);
void wm_client_show(Wm* wm, Client *c);
void wm_client_focus(Wm* wm, Client *c);

View File

@ -149,13 +149,23 @@ void wm_keypress_handler(Wm *wm, XKeyPressedEvent e)
void wm_maprequest_handler(Wm *wm, XMapRequestEvent e)
{
DEBUG_PRINT("MapRequest event\n")
DEBUG_PRINT("MapRequest event\n");
if (e.window == wm->root.window)
fprintf(stderr, "%s e.window was root\n", __func__);
if (e.window == wm->root.window) {
fprintf(stderr, "%s e.window was root, returning\n", __func__);
return;
}
Client *c;
if (wm_window_is_dock(wm, e.window))
{
DEBUG_PRINT("%s: window is dock, mapping window\n", __func__)
wm->dock = e.window;
XMapWindow(wm->display, e.window);
return;
}
c = wm_client_find(wm, e.window);
if (c) {
DEBUG_PRINT("%s: client found, mapping window\n", __func__)
@ -164,18 +174,14 @@ void wm_maprequest_handler(Wm *wm, XMapRequestEvent e)
return;
}
if (wm_window_is_dock(wm, e.window))
{
DEBUG_PRINT("%s: window is dock, mapping window\n", __func__)
XMapWindow(wm->display, e.window);
return;
}
DEBUG_PRINT("%s: client not found, creating client\n", __func__)
c = wm_client_create(wm, e.window);
RETURN_IF_NULL(c)
//XMapWindow(wm->display, c->window);
RETURN_IF_NULL(c);
wm_client_handle_window_types(wm, c, e);
wm_layout(wm, c->m);
}
@ -194,50 +200,17 @@ void wm_motion_handler(Wm *wm, XMotionEvent e)
void wm_configure_handler(Wm *wm, XConfigureRequestEvent e)
{
DEBUG_PRINT("ConfigureRequest event\n");
Client *c;
unsigned char *prop_ret;
unsigned long nitems_ret;
Atom type;
bool is_normal = false;
XTextProperty xtp;
c = wm_client_create(wm, e.window);
Client *c;
XWindowChanges wc;
XGetWMName(wm->display, e.window, &xtp);
DEBUG_PRINT("%s: created window %d name: %s\n", __func__, (int)e.window, xtp.value);
//XFree(xtp);
char *name = "_NET_WM_WINDOW_TYPE";
type = wm_client_get_atom(wm, c, "_NET_WM_WINDOW_TYPE", &prop_ret, &nitems_ret);
if (type == -1) {
fprintf(stderr, "wm_client_get_atom failed\n");
return;
}
for (int i = 0; i < nitems_ret; i++) {
DEBUG_PRINT("ConfigureRequest handler: window %d has property %s\n",
(int)e.window, XGetAtomName(wm->display, ((Atom*)prop_ret)[i]));
if (strcmp(XGetAtomName(wm->display, ((Atom*)prop_ret)[i]),
"_NET_WM_WINDOW_TYPE_NORMAL") == 0) {
is_normal = true;
} else if (strcmp(XGetAtomName(wm->display, ((Atom*)prop_ret)[i]),
"_NET_WM_WINDOW_TYPE_DOCK") == 0) {
wm->dock = e.window;
} else if (strcmp(XGetAtomName(wm->display, ((Atom*)prop_ret)[i]),
"_NET_WM_WINDOW_TYPE_DIALOG") == 0) {
c->is_floating = true;
}
}
if (!is_normal) {
DEBUG_PRINT("configure handler: window %d is not normal, returning\n",
(int)e.window)
wm_client_free(wm, c);
return;
}
wm_layout(wm, c->m);
wc.x = e.x;
wc.y = e.y;
wc.width = e.width;
wc.height = e.height;
wc.border_width = e.border_width;
wc.sibling = e.above;
wc.stack_mode = e.detail;
XConfigureWindow(wm->display, e.window, e.value_mask, &wc);
XSync(wm->display, False);
}