X11 Client Window State Management:
- CreateNotify ->Withdrawn:
- Create window detached from any workspace (withdrawn list).
- Place window in withdrawn list.
-
- MapRequest ->Normal:
- Read the window properties
- Reparent the window to a frame if applicable
- Move window to current workspace tiled or floating
- Send expose event to window
+ MapRequest ->Normal/Withdrawn:
+ If window already tracked
+ Show the window and frame
+ Send expose event to window
+ else
+ Create new client struct
+ Read the window properties
+ Reparent the window to a frame if applicable
+ Move window to current workspace tiled or floating
+ Send expose event to window
UnmapNotify ->Withdrawn/Iconified:
if shaded -> Iconified
- Keep window where it is, show only titlebar
+ Iconified: Keep window where it is, show only titlebar
else if unloaded
- Keep window where it is but unmapped
+ Withdrawn: Keep window where it is but unmapped
else
- Remove window from workspace.
- Place window in withdrawn list.
+ Withdrawn: Remove window from workspace.
DestroyNotify ->Destroyed
Window is destroyed. Free all resources.
*/
-static void xcreatenotify(XEvent* e)
-{
- XCreateWindowEvent* ev = &(e->xcreatewindow);
- printf("CREATE(w: 0x%lx)\n", ev->window);
-
- /* add the new window in the withdrawn state */
- Client_Create(ev->window);
-}
static void xmaprequest(XEvent* e)
{
atoms_init();
/* setup window life-cycle management event handlers */
- X.eventfns[CreateNotify] = xcreatenotify;
+// X.eventfns[CreateNotify] = xcreatenotify;
X.eventfns[MapRequest] = xmaprequest;
X.eventfns[UnmapNotify] = xunmapnotify;
X.eventfns[DestroyNotify] = xdestroynotify;
void SetWMState(Client *c, int state)
{
CARD32 data[2] = {state, None};
+ c->state = state;
XChangeProperty(X.disp, c->win, WM_STATE, WM_STATE, 32, PropModeReplace, (unsigned char *)data, 2);
}
// return state;
//}
-void Client_Create(Window win)
+static Client* Create(Window win)
{
- (void)win;
+ Client* c = NULL;
XWindowAttributes attr;
if (XGetWindowAttributes(X.disp, win, &attr) && !attr.override_redirect)
{
/* we care about it, let's add it to withdrawn */
- Client* c = ecalloc(1, sizeof(Client));
+ c = ecalloc(1, sizeof(Client));
c->win = win;
c->x = attr.x;
c->y = attr.y;
XReparentWindow(X.disp, c->win, c->frame, BORDER_WIDTH, MIN_HEIGHT);
SetWMState(c, WithdrawnState);
-// /* set the state now based on attributes and hints */
-// if (attr.map_state == IsUnmapped)
-// {
-// SetWMState(c, WithdrawnState);
-// }
-// else
-// {
-// SetWMState(c, NormalState);
-// XWMHints* hints = XGetWMHints(X.disp, c->win);
-// if (hints)
-// {
-// if (hints->flags & StateHint)
-// {
-// SetWMState(c, hints->initial_state);
-// }
-// XFree(hints);
-// }
-// }
+ /* set the state now based on attributes and hints */
+ if (attr.map_state != IsViewable)
+ {
+ SetWMState(c, NormalState);
+ XWMHints* hints = XGetWMHints(X.disp, c->win);
+ if (hints)
+ {
+ if (hints->flags & StateHint)
+ {
+ SetWMState(c, hints->initial_state);
+ }
+ XFree(hints);
+ }
+ }
}
-}
-
-void Client_Destroy(Window win)
-{
- (void)win;
+ return c;
}
void Client_Show(Window win)
{
+ /* find or create the client structure */
Client* c = FindClient(win);
- printf("%p %p\n", Withdrawn, c);
+ if (!c) { c = Create(win); }
+
+ /* if we have a calid client, show it */
if (c)
{
ReadProps(c);
}
+void Client_Destroy(Window win)
+{
+ (void)win;
+}
+
+void Client_MoveResize(Client* c)
+{
+ int shaded = (c->flags & F_SHADED);
+ int floating = (c->flags & (F_DIALOG|F_FLOATING));
+ int minheight = (shaded || !floating ? MIN_HEIGHT : 3*MIN_HEIGHT);
+ if (c->w < minheight) c->w = minheight;
+ if (c->h < minheight) c->h = minheight;
+ printf("XMoveResize(0x%lx, %d, %d, %d, %d)\n", c->frame, c->x, c->y, c->w, c->h);
+ XMoveResizeWindow(X.disp, c->frame, c->x, c->y, c->w, (shaded ? minheight : c->h));
+ if ( !(c->flags & F_SHADED) )
+ {
+ int child_w = c->w - FRAME_WIDTH_SUM;
+ int child_h = c->h - FRAME_HEIGHT_SUM;
+ if (child_w < 1) c->w = 1;
+ if (child_h < 1) c->h = 1;
+ printf("XResize(0x%lx, %d, %d)\n", c->win, c->w, c->h);
+ XResizeWindow(X.disp, c->win, child_w, child_h);
+ }
+// mons_place(c);
+ Redraw(c);
+}
+
+
static void ReadProps(Client* c)
{
Atom *protos = NULL, actual_type, *wintype;
}
-void client_adjust(Client* c)
-{
- int shaded = (c->flags & F_SHADED);
- int floating = (c->flags & (F_DIALOG|F_FLOATING));
- int minheight = (shaded || !floating ? MIN_HEIGHT : 3*MIN_HEIGHT);
- if (c->w < minheight) c->w = minheight;
- if (c->h < minheight) c->h = minheight;
-printf("XMoveResize(0x%lx, %d, %d, %d, %d)\n", c->frame, c->x, c->y, c->w, c->h);
- XMoveResizeWindow(X.disp, c->frame, c->x, c->y, c->w, (shaded ? minheight : c->h));
- if ( !(c->flags & F_SHADED) )
- {
- int child_w = c->w - FRAME_WIDTH_SUM;
- int child_h = c->h - FRAME_HEIGHT_SUM;
- if (child_w < 1) c->w = 1;
- if (child_h < 1) c->h = 1;
-printf("XResize(0x%lx, %d, %d)\n", c->win, c->w, c->h);
- XResizeWindow(X.disp, c->win, child_w, child_h);
- }
- mons_place(c);
-// Redraw(c);
-}
void client_move(Client* c, int xdiff, int ydiff)
{