Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…3-fe4c-0410-82e9-b9c6d0c95a22
  • Loading branch information
jordansissel committed Dec 24, 2007
1 parent 18e4534 commit 2da4ef7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 27 deletions.
35 changes: 27 additions & 8 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ static void *xmalloc(size_t size) {
return ptr;
}


XContext container_context;
container_t *current_container;

int main(int argc, char **argv) {
wm_t *wm = NULL;
int i;
wm = wm_init(NULL);
wm = wm_create(NULL);
wm_set_log_level(wm, LOG_INFO);

container_context = XUniqueContext();

wm_log(wm, LOG_INFO, "== num screens: %d", wm->num_screens);
for (i = 0; i < wm->num_screens; i++) {
XWindowAttributes attr;
Window root = wm->screens[i]->root;;
container_t *root_container;
XGetWindowAttributes(wm->dpy, root, &attr);
root_container = container_new(wm, root, attr.x, attr.y, attr.width, attr.height);
root_container = container_new(wm, root, attr.x, attr.y,
attr.width, attr.height);
container_show(root_container);
wm_log(wm, LOG_INFO, "Setting current container to %tx", root_container);
current_container = root_container;
}

/* Create workspace */
wm_listener_add(wm, WM_EVENT_MAPREQUEST, addwin);
wm_init(wm);
wm_main(wm);

return 0;
Expand All @@ -60,12 +62,29 @@ Bool container_show(container_t *container) {
return True;
}

Bool container_client_add(container_t *container, client_t *client) {
XWindowAttributes attr;
wm_log(container->wm, LOG_INFO, "%s: client add window %d", __func__, client);
XGetWindowAttributes(container->wm->dpy, client->window, &attr);
XReparentWindow(container->wm->dpy, client->window, container->frame, 0, TITLE_HEIGHT);
XSetWindowBorderWidth(container->wm->dpy, client->window, 0);
XResizeWindow(container->wm->dpy, client->window, attr.width, attr.height);
XMapRaised(container->wm->dpy, client->window);
return True;
}

Bool addwin(wm_t *wm, wm_event_t *event) {
wm_log(wm, LOG_INFO, "%s: %d / %d", __func__, event->event_id, event->client->window);
container_client_add(current_container, event->client);
return True;
}

Bool _addwin(wm_t *wm, wm_event_t *event) {
Window new_window;
Window frame;
wm_log(wm, LOG_INFO, "addwin!");

new_window = event->window;
new_window = event->client->window;

XGrabServer(wm->dpy);
//frame = mkframe(wm, new_window);
Expand Down
3 changes: 1 addition & 2 deletions tsawm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <X11/Xresource.h>
#include <X11/Xutil.h>


#include "wmlib/wmlib.h"

typedef struct container {
Expand All @@ -20,5 +19,5 @@ Window mkframe(wm_t *wm, Window parent, int x, int y, int width, int height);
container_t *container_new(wm_t *wm, Window parent, int x, int y, int width, int height);

Bool container_show(container_t *container);
Bool container_client_add(client_t *client);
Bool container_client_add(container_t *container, client_t *client);

29 changes: 20 additions & 9 deletions wmlib/wmlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ static void *xmalloc(size_t size) {
return ptr;
}

wm_t *wm_init(char *display_name) {
wm_t *wm_create(char *display_name) {
wm_t *wm = NULL;
wm = xmalloc(sizeof(wm_t));

wm_x_open(wm, display_name);
wm_x_init_handlers(wm);
return wm;
wm_x_init_screens(wm);
}

void wm_x_init(wm_t *wm);
wm_x_init_windows(wm);
}

void wm_x_init_screens(wm_t *wm) {
Expand All @@ -67,6 +70,8 @@ void wm_x_init_screens(wm_t *wm) {
| EnterWindowMask | LeaveWindowMask;

num_screens = ScreenCount(wm->dpy);

wm_log(wm, LOG_INFO, "setting num screens: %d", num_screens);
wm->num_screens = num_screens;
wm->screens = xmalloc(num_screens * sizeof(Screen*));
for (i = 0; i < num_screens; i++) {
Expand Down Expand Up @@ -159,8 +164,6 @@ void wm_x_open(wm_t *wm, char *display_name) {

void wm_main(wm_t *wm) {
XEvent ev;
wm_x_init_screens(wm);
wm_x_init_windows(wm);

for (;;) {
XNextEvent(wm->dpy, &ev);
Expand Down Expand Up @@ -279,8 +282,12 @@ void wm_event_maprequest(wm_t *wm, XEvent *ev) {
{ // Call handlers
wm_event_t wmev;
wmev.event_id = WM_EVENT_MAPREQUEST;
wmev.window = mrev.window;
wm_listener_call(wm, &wmev);
wmev.client = c;
if (wmev.client == NULL) {
wm_log(wm, LOG_ERROR, "could not find client for window '%d'", mrev.window);
} else {
wm_listener_call(wm, &wmev);
}
}
XUngrabServer(wm->dpy);
}
Expand Down Expand Up @@ -334,16 +341,19 @@ void wm_listener_add(wm_t *wm, wm_event_id event, wm_event_handler callback) {
"Attempt to register for event '%d' when max event is '%d'",
event, WM_EVENT_MAX);
}

wm->listeners[event] = callback;
}

void wm_listener_call(wm_t *wm, wm_event_t *event) {
int i = 0;
wm_event_handler callback;

wm_log(wm, LOG_INFO, "Calling all listeners for event %d", event->event_id);

callback = wm->listeners[event->event_id];
if (callback == NULL) {
wm_log(wm, LOG_INFO, "No callback registered for event %d", event->event_id);
return;
}
wm_log(wm, LOG_INFO, "Calling func %016tx", callback);
callback(wm, event);
}
Expand Down Expand Up @@ -434,6 +444,7 @@ client_t *wm_get_client(wm_t *wm, Window window, Bool create_if_necessary) {
memcpy(&(c->attr), &attr, sizeof(XWindowAttributes));
c->screen = attr.screen;
XSaveContext(wm->dpy, window, wm->context, (XPointer)c);
XAddToSaveSet(wm->dpy, window);
}

return c;
Expand Down
17 changes: 9 additions & 8 deletions wmlib/wmlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ struct wm {
XContext context;
};

typedef struct client {
Window window;
XWindowAttributes attr;
Screen *screen;
} client_t;

typedef unsigned int wm_event_id;
struct wm_event {
wm_event_id event_id;
Window window;
client_t *client;
int x;
int y;
int width;
int height;
};

typedef struct client {
Window window;
XWindowAttributes attr;
Screen *screen;
} client_t;

#define ButtonEventMask ButtonPressMask|ButtonReleaseMask
#define MouseEventMask ButtonPressMask|ButtonReleaseMask|PointerMotionMask

Expand All @@ -60,7 +60,8 @@ typedef struct client {
/* XXX: Check if we have __FUNCTION__ */
#define __func__ __FUNCTION__

wm_t *wm_init(char *display_name);
wm_t *wm_create(char *display_name);
void wm_init(wm_t *wm);
void wm_main(wm_t *wm);

int wm_get_log_level(wm_t *wm, int log_level);
Expand Down

0 comments on commit 2da4ef7

Please sign in to comment.