/** Toggle maximized state. */ void ToggleMaximized(ClientNode *np, MaxFlags flags) { if(np) { if(np->state.maxFlags == flags) { MaximizeClient(np, MAX_NONE); } else { MaximizeClient(np, flags); } } }
/** Stop move. */ void StopMove(ClientNode *np, int doMove, int oldx, int oldy, MaxFlags maxFlags) { int north, south, east, west; Assert(np); Assert(np->controller); (np->controller)(0); np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); if(!doMove) { np->x = oldx; np->y = oldy; /* Restore maximized status. */ if(maxFlags) { MaximizeClient(np, maxFlags); } return; } GetBorderSize(&np->state, &north, &south, &east, &west); if(np->parent != None) { JXMoveWindow(display, np->parent, np->x - west, np->y - north); } else { JXMoveWindow(display, np->window, np->x - west, np->y - north); } SendConfigureEvent(np); /* Restore maximized status. */ if(maxFlags) { MaximizeClient(np, maxFlags); } }
/** Stop move. */ void StopMove(ClientNode *np, int doMove, int oldx, int oldy, int hmax, int vmax) { int north, south, east, west; Assert(np); Assert(np->controller); (np->controller)(0); np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); if(!doMove) { np->x = oldx; np->y = oldy; /* Restore maximized status if only maximized in one direction. */ if((hmax || vmax) && !(hmax && vmax)) { MaximizeClient(np, hmax, vmax); } return; } GetBorderSize(&np->state, &north, &south, &east, &west); JXMoveWindow(display, np->parent, np->x - west, np->y - north); SendConfigureEvent(np); /* Restore maximized status. */ if((hmax || vmax) && !(hmax && vmax)) { MaximizeClient(np, hmax, vmax); } }
/** Maximize a client using its default maximize settings. */ void MaximizeClientDefault(ClientNode *np) { MaxFlags flags = MAX_NONE; Assert(np); if(np->state.maxFlags == MAX_NONE) { if(np->state.border & BORDER_MAX_H) { flags |= MAX_HORIZ; } if(np->state.border & BORDER_MAX_V) { flags |= MAX_VERT; } } MaximizeClient(np, flags); }
/** Move a client window. */ char MoveClient(ClientNode *np, int startx, int starty, int snap) { XEvent event; int oldx, oldy; int doMove; int north, south, east, west; int height; int hmax, vmax; Assert(np); if(!(np->state.border & BORDER_MOVE)) { return 0; } if(np->state.status & STAT_FULLSCREEN) { return 0; } GrabMouseForMove(); RegisterCallback(0, SignalMove, NULL); np->controller = MoveController; shouldStopMove = 0; oldx = np->x; oldy = np->y; vmax = 0; hmax = 0; if(!(GetMouseMask() & (Button1Mask | Button2Mask))) { StopMove(np, 0, oldx, oldy, 0, 0); return 0; } GetBorderSize(&np->state, &north, &south, &east, &west); startx -= west; starty -= north; currentClient = np; atTop = 0; atBottom = 0; atLeft = 0; atRight = 0; doMove = 0; for(;;) { WaitForEvent(&event); if(shouldStopMove) { np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); return doMove; } switch(event.type) { case ButtonRelease: if(event.xbutton.button == Button1 || event.xbutton.button == Button2) { StopMove(np, doMove, oldx, oldy, hmax, vmax); return doMove; } break; case MotionNotify: DiscardMotionEvents(&event, np->window); np->x = event.xmotion.x_root - startx; np->y = event.xmotion.y_root - starty; GetCurrentTime(&moveTime); atLeft = 0; atTop = 0; atRight = 0; atBottom = 0; if(event.xmotion.x_root == 0) { atLeft = 1; } else if(event.xmotion.x_root == rootWidth - 1) { atRight = 1; } if(event.xmotion.y_root == 0) { atTop = 1; } else if(event.xmotion.y_root == rootHeight - 1) { atBottom = 1; } if(snap) { DoSnap(np); } if(!doMove && (abs(np->x - oldx) > MOVE_DELTA || abs(np->y - oldy) > MOVE_DELTA)) { if(np->state.status & (STAT_HMAX | STAT_VMAX)) { if(np->state.status & STAT_HMAX) { hmax = 1; } if(np->state.status & STAT_VMAX) { vmax = 1; } MaximizeClient(np, 0, 0); startx = np->width / 2; starty = -north / 2; MoveMouse(np->parent, startx, starty); } CreateMoveWindow(np); doMove = 1; } if(doMove) { if(settings.moveMode == MOVE_OUTLINE) { ClearOutline(); height = north + south; if(!(np->state.status & STAT_SHADED)) { height += np->height; } DrawOutline(np->x - west, np->y - north, np->width + west + east, height); } else { JXMoveWindow(display, np->parent, np->x - west, np->y - north); SendConfigureEvent(np); } UpdateMoveWindow(np); UpdatePager(); } break; default: break; } } }
/** Window menu action callback. */ void RunWindowCommand(const MenuAction *action) { switch(action->type) { case MA_STICK: if(client->state.status & STAT_STICKY) { SetClientSticky(client, 0); } else { SetClientSticky(client, 1); } break; case MA_MAXIMIZE: if(client->state.maxFlags) { MaximizeClient(client, MAX_NONE); } else { MaximizeClient(client, MAX_VERT | MAX_HORIZ); } break; case MA_MAXIMIZE_H: MaximizeClient(client, MAX_HORIZ); break; case MA_MAXIMIZE_V: MaximizeClient(client, MAX_VERT); break; case MA_MINIMIZE: MinimizeClient(client, 1); break; case MA_RESTORE: RestoreClient(client, 1); break; case MA_CLOSE: DeleteClient(client); break; case MA_SENDTO: case MA_DESKTOP: SetClientDesktop(client, action->data.i); break; case MA_SHADE: if(client->state.status & STAT_SHADED) { UnshadeClient(client); } else { ShadeClient(client); } break; case MA_MOVE: MoveClientKeyboard(client); break; case MA_RESIZE: ResizeClientKeyboard(client); break; case MA_KILL: KillClient(client); break; case MA_LAYER: SetClientLayer(client, action->data.i); break; default: Debug("unknown window command: %d", action->type); break; } }
/** Window menu action callback. */ void RunWindowCommand(MenuAction *action, unsigned button) { ClientNode *client = action->context; switch(action->type) { case MA_STICK: if(client->state.status & STAT_STICKY) { SetClientSticky(client, 0); } else { SetClientSticky(client, 1); } break; case MA_MAXIMIZE: if((client->state.maxFlags & MAX_HORIZ) && (client->state.maxFlags & MAX_VERT) && !(client->state.status & STAT_MINIMIZED)) { MaximizeClient(client, MAX_NONE); } else { MaximizeClient(client, MAX_VERT | MAX_HORIZ); } break; case MA_MAXIMIZE_H: if((client->state.maxFlags & MAX_HORIZ) && !(client->state.maxFlags & MAX_VERT) && !(client->state.status & STAT_MINIMIZED)) { MaximizeClient(client, MAX_NONE); } else { MaximizeClient(client, MAX_HORIZ); } break; case MA_MAXIMIZE_V: if((client->state.maxFlags & MAX_VERT) && !(client->state.maxFlags & MAX_HORIZ) && !(client->state.status & STAT_MINIMIZED)) { MaximizeClient(client, MAX_NONE); } else { MaximizeClient(client, MAX_VERT); } break; case MA_MINIMIZE: MinimizeClient(client, 1); break; case MA_RESTORE: RestoreClient(client, 1); break; case MA_CLOSE: DeleteClient(client); break; case MA_SENDTO: case MA_DESKTOP: SetClientDesktop(client, action->value); break; case MA_SHADE: if(client->state.status & STAT_SHADED) { UnshadeClient(client); } else { ShadeClient(client); } break; case MA_MOVE: MoveClientKeyboard(client); break; case MA_RESIZE: ResizeClientKeyboard(client); break; case MA_KILL: KillClient(client); break; case MA_LAYER: SetClientLayer(client, action->value); break; default: break; } }
/** Process a configure request. */ void HandleConfigureRequest(const XConfigureRequestEvent *event) { XWindowChanges wc; ClientNode *np; if(HandleDockConfigureRequest(event)) { return; } np = FindClientByWindow(event->window); if(np) { int deltax, deltay; char changed = 0; char resized = 0; GetGravityDelta(np, np->gravity, &deltax, &deltay); if((event->value_mask & CWWidth) && (event->width != np->width)) { switch(np->gravity) { case EastGravity: case NorthEastGravity: case SouthEastGravity: /* Right side should not move. */ np->x -= event->width - np->width; break; case WestGravity: case NorthWestGravity: case SouthWestGravity: /* Left side should not move. */ break; case CenterGravity: /* Center of the window should not move. */ np->x -= (event->width - np->width) / 2; break; default: break; } np->width = event->width; changed = 1; resized = 1; } if((event->value_mask & CWHeight) && (event->height != np->height)) { switch(np->gravity) { case NorthGravity: case NorthEastGravity: case NorthWestGravity: /* Top should not move. */ break; case SouthGravity: case SouthEastGravity: case SouthWestGravity: /* Bottom should not move. */ np->y -= event->height - np->height; break; case CenterGravity: /* Center of the window should not move. */ np->y -= (event->height - np->height) / 2; break; default: break; } np->height = event->height; changed = 1; resized = 1; } if((event->value_mask & CWX) && (event->x - deltax != np->x)) { np->x = event->x - deltax; changed = 1; } if((event->value_mask & CWY) && (event->y - deltay != np->y)) { np->y = event->y - deltay; changed = 1; } /* Update stacking. */ if((event->value_mask & CWStackMode)) { Window above = None; if(event->value_mask & CWSibling) { above = event->above; } RestackClient(np, above, event->detail); } /* Return early if there's nothing to do. */ if(!changed) { return; } if(np->controller) { (np->controller)(0); } if(np->state.maxFlags) { MaximizeClient(np, MAX_NONE); } if(np->state.border & BORDER_CONSTRAIN) { resized = 1; } if(resized) { ConstrainSize(np); ConstrainPosition(np); ResetBorder(np); } else { int north, south, east, west; GetBorderSize(&np->state, &north, &south, &east, &west); if(np->parent != None) { JXMoveWindow(display, np->parent, np->x - west, np->y - north); } else { JXMoveWindow(display, np->window, np->x, np->y); } } SendConfigureEvent(np); RequirePagerUpdate(); } else { /* We don't know about this window, just let the configure through. */ wc.stack_mode = event->detail; wc.sibling = event->above; wc.border_width = event->border_width; wc.x = event->x; wc.y = event->y; wc.width = event->width; wc.height = event->height; JXConfigureWindow(display, event->window, event->value_mask, &wc); } }
/** Process a key press event. */ void HandleKeyPress(const XKeyEvent *event) { ClientNode *np; KeyType key; SetMousePosition(event->x_root, event->y_root, event->window); key = GetKey(event); np = GetActiveClient(); switch(key & 0xFF) { case KEY_EXEC: RunKeyCommand(event); break; case KEY_DESKTOP: ChangeDesktop((key >> 8) - 1); break; case KEY_RDESKTOP: RightDesktop(); break; case KEY_LDESKTOP: LeftDesktop(); break; case KEY_UDESKTOP: AboveDesktop(); break; case KEY_DDESKTOP: BelowDesktop(); break; case KEY_SHOWDESK: ShowDesktop(); break; case KEY_SHOWTRAY: ShowAllTrays(); break; case KEY_NEXT: StartWindowWalk(); FocusNext(); break; case KEY_NEXTSTACK: StartWindowStackWalk(); WalkWindowStack(1); break; case KEY_PREV: StartWindowWalk(); FocusPrevious(); break; case KEY_PREVSTACK: StartWindowStackWalk(); WalkWindowStack(0); break; case KEY_CLOSE: if(np) { DeleteClient(np); } break; case KEY_SHADE: if(np) { if(np->state.status & STAT_SHADED) { UnshadeClient(np); } else { ShadeClient(np); } } break; case KEY_STICK: if(np) { if(np->state.status & STAT_STICKY) { SetClientSticky(np, 0); } else { SetClientSticky(np, 1); } } break; case KEY_MOVE: if(np) { MoveClientKeyboard(np); } break; case KEY_RESIZE: if(np) { ResizeClientKeyboard(np); } break; case KEY_MIN: if(np) { MinimizeClient(np, 1); } break; case KEY_MAX: if(np) { if(np->state.maxFlags) { MaximizeClient(np, MAX_NONE); } else { MaximizeClient(np, MAX_HORIZ | MAX_VERT); } } break; case KEY_MAXTOP: ToggleMaximized(np, MAX_TOP | MAX_HORIZ); break; case KEY_MAXBOTTOM: ToggleMaximized(np, MAX_BOTTOM | MAX_HORIZ); break; case KEY_MAXLEFT: ToggleMaximized(np, MAX_LEFT | MAX_VERT); break; case KEY_MAXRIGHT: ToggleMaximized(np, MAX_RIGHT | MAX_VERT); break; case KEY_MAXV: ToggleMaximized(np, MAX_VERT); break; case KEY_MAXH: ToggleMaximized(np, MAX_HORIZ); break; case KEY_ROOT: ShowKeyMenu(event); break; case KEY_WIN: if(np) { RaiseClient(np); ShowWindowMenu(np, np->x, np->y, 1); } break; case KEY_RESTART: Restart(); break; case KEY_EXIT: Exit(); break; case KEY_FULLSCREEN: if(np) { if(np->state.status & STAT_FULLSCREEN) { SetClientFullScreen(np, 0); } else { SetClientFullScreen(np, 1); } } break; case KEY_SENDR: if(np) { SetClientDesktop(np, GetRightDesktop(np->state.desktop)); } break; case KEY_SENDL: if(np) { SetClientDesktop(np, GetLeftDesktop(np->state.desktop)); } break; case KEY_SENDU: if(np) { SetClientDesktop(np, GetAboveDesktop(np->state.desktop)); } break; case KEY_SENDD: if(np) { SetClientDesktop(np, GetBelowDesktop(np->state.desktop)); } break; default: break; } DiscardEnterEvents(); }
/** Take the appropriate action for a click on a client border. */ void DispatchBorderButtonEvent(const XButtonEvent *event, ClientNode *np) { static Time lastClickTime = 0; static int lastX = 0, lastY = 0; static char doubleClickActive = 0; BorderActionType action; int bsize; /* Middle click starts a move unless it's over the maximize button. */ action = GetBorderActionType(np, event->x, event->y); if(event->button == Button2 && action != BA_MAXIMIZE) { MoveClient(np, event->x, event->y); return; } /* Determine the size of the border. */ if(np->state.border & BORDER_OUTLINE) { bsize = settings.borderWidth; } else { bsize = 0; } /* Other buttons are context sensitive. */ switch(action & 0x0F) { case BA_RESIZE: /* Border */ if(event->type == ButtonPress) { if(event->button == Button1) { ResizeClient(np, action, event->x, event->y); } else if(event->button == Button3) { const int x = np->x + event->x - bsize; const int y = np->y + event->y - settings.titleHeight - bsize; ShowWindowMenu(np, x, y, 0); } } break; case BA_MOVE: /* Title bar */ if(event->button == Button1) { if(event->type == ButtonPress) { if(doubleClickActive && event->time != lastClickTime && event->time - lastClickTime <= settings.doubleClickSpeed && abs(event->x - lastX) <= settings.doubleClickDelta && abs(event->y - lastY) <= settings.doubleClickDelta) { MaximizeClientDefault(np); doubleClickActive = 0; } else { if(MoveClient(np, event->x, event->y)) { doubleClickActive = 0; } else { doubleClickActive = 1; lastClickTime = event->time; lastX = event->x; lastY = event->y; } } } } else if(event->button == Button3) { const int x = np->x + event->x - bsize; const int y = np->y + event->y - settings.titleHeight - bsize; ShowWindowMenu(np, x, y, 0); } else if(event->button == Button4) { ShadeClient(np); } else if(event->button == Button5) { UnshadeClient(np); } break; case BA_MENU: /* Menu button */ if(event->button == Button4) { ShadeClient(np); } else if(event->button == Button5) { UnshadeClient(np); } else if(event->type == ButtonPress) { const int x = np->x + event->x - bsize; const int y = np->y + event->y - settings.titleHeight - bsize; ShowWindowMenu(np, x, y, 0); } break; case BA_CLOSE: /* Close button */ if(event->type == ButtonRelease && (event->button == Button1 || event->button == Button3)) { DeleteClient(np); } break; case BA_MAXIMIZE: /* Maximize button */ if(event->type == ButtonRelease) { switch(event->button) { case Button1: MaximizeClientDefault(np); break; case Button2: MaximizeClient(np, np->state.maxFlags ^ MAX_VERT); break; case Button3: MaximizeClient(np, np->state.maxFlags ^ MAX_HORIZ); break; default: break; } } break; case BA_MINIMIZE: /* Minimize button */ if(event->type == ButtonRelease) { if(event->button == Button3) { if(np->state.status & STAT_SHADED) { UnshadeClient(np); } else { ShadeClient(np); } } else if(event->button == Button1) { MinimizeClient(np, 1); } } break; default: break; } DiscardEnterEvents(); }
/** Handle a _NET_WM_STATE request. */ void HandleNetWMState(const XClientMessageEvent *event, ClientNode *np) { unsigned int x; MaxFlags maxFlags; char actionStick; char actionShade; char actionFullScreen; char actionMinimize; char actionNolist; char actionNopager; char actionBelow; char actionAbove; /* Up to two actions to be applied together. */ maxFlags = MAX_NONE; actionStick = 0; actionShade = 0; actionFullScreen = 0; actionMinimize = 0; actionNolist = 0; actionNopager = 0; actionBelow = 0; actionAbove = 0; for(x = 1; x <= 2; x++) { if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_STICKY]) { actionStick = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_MAXIMIZED_VERT]) { maxFlags |= MAX_VERT; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_MAXIMIZED_HORZ]) { maxFlags |= MAX_HORIZ; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_SHADED]) { actionShade = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_FULLSCREEN]) { actionFullScreen = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_HIDDEN]) { actionMinimize = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_SKIP_TASKBAR]) { actionNolist = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_SKIP_PAGER]) { actionNopager = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_BELOW]) { actionBelow = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_ABOVE]) { actionAbove = 1; } } switch(event->data.l[0]) { case 0: /* Remove */ if(actionStick) { SetClientSticky(np, 0); } if(maxFlags != MAX_NONE && np->state.maxFlags) { MaximizeClient(np, np->state.maxFlags & ~maxFlags); } if(actionShade) { UnshadeClient(np); } if(actionFullScreen) { SetClientFullScreen(np, 0); } if(actionMinimize) { RestoreClient(np, 0); } if(actionNolist) { np->state.status &= ~STAT_NOLIST; RequireTaskUpdate(); } if(actionNopager) { np->state.status &= ~STAT_NOPAGER; RequirePagerUpdate(); } if(actionBelow && np->state.layer == LAYER_BELOW) { SetClientLayer(np, np->state.defaultLayer); } if(actionAbove && np->state.layer == LAYER_ABOVE) { SetClientLayer(np, np->state.defaultLayer); } break; case 1: /* Add */ if(actionStick) { SetClientSticky(np, 1); } if(maxFlags != MAX_NONE) { MaximizeClient(np, np->state.maxFlags | maxFlags); } if(actionShade) { ShadeClient(np); } if(actionFullScreen) { SetClientFullScreen(np, 1); } if(actionMinimize) { MinimizeClient(np, 1); } if(actionNolist) { np->state.status |= STAT_NOLIST; RequireTaskUpdate(); } if(actionNopager) { np->state.status |= STAT_NOPAGER; RequirePagerUpdate(); } if(actionBelow) { SetClientLayer(np, LAYER_BELOW); } if(actionAbove) { SetClientLayer(np, LAYER_ABOVE); } break; case 2: /* Toggle */ if(actionStick) { if(np->state.status & STAT_STICKY) { SetClientSticky(np, 0); } else { SetClientSticky(np, 1); } } if(maxFlags) { MaximizeClient(np, np->state.maxFlags ^ maxFlags); } if(actionShade) { if(np->state.status & STAT_SHADED) { UnshadeClient(np); } else { ShadeClient(np); } } if(actionFullScreen) { if(np->state.status & STAT_FULLSCREEN) { SetClientFullScreen(np, 0); } else { SetClientFullScreen(np, 1); } } if(actionBelow) { if(np->state.layer == LAYER_BELOW) { SetClientLayer(np, np->state.defaultLayer); } else { SetClientLayer(np, LAYER_BELOW); } } if(actionAbove) { if(np->state.layer == LAYER_ABOVE) { SetClientLayer(np, np->state.defaultLayer); } else { SetClientLayer(np, LAYER_ABOVE); } } /* Note that we don't handle toggling of hidden per EWMH * recommendations. */ if(actionNolist) { np->state.status ^= STAT_NOLIST; RequireTaskUpdate(); } if(actionNopager) { np->state.status ^= STAT_NOPAGER; RequirePagerUpdate(); } break; default: Debug("bad _NET_WM_STATE action: %ld", event->data.l[0]); break; } /* Update _NET_WM_STATE if needed. * The state update is handled elsewhere for the other actions. */ if(actionNolist | actionNopager | actionAbove | actionBelow) { WriteState(np); } }
/** Handle a _NET_MOVERESIZE_WINDOW request. */ void HandleNetMoveResize(const XClientMessageEvent *event, ClientNode *np) { long flags; int gravity; int deltax, deltay; Assert(event); Assert(np); flags = event->data.l[0] >> 8; gravity = event->data.l[0] & 0xFF; if(gravity == 0) { gravity = np->gravity; } GetGravityDelta(np, gravity, &deltax, &deltay); if(flags & (1 << 2)) { const long width = event->data.l[3]; switch(gravity) { case EastGravity: case NorthEastGravity: case SouthEastGravity: /* Right side should not move. */ np->x -= width - np->width; break; case WestGravity: case NorthWestGravity: case SouthWestGravity: /* Left side should not move. */ break; case CenterGravity: /* Center of the window should not move. */ np->x -= (width - np->width) / 2; break; default: break; } np->width = width; } if(flags & (1 << 3)) { const long height = event->data.l[4]; switch(gravity) { case NorthGravity: case NorthEastGravity: case NorthWestGravity: /* Top should not move. */ break; case SouthGravity: case SouthEastGravity: case SouthWestGravity: /* Bottom should not move. */ np->y -= height - np->height; break; case CenterGravity: /* Center of the window should not move. */ np->y -= (height - np->height) / 2; break; default: break; } np->height = height; } if(flags & (1 << 0)) { np->x = event->data.l[1] - deltax; } if(flags & (1 << 1)) { np->y = event->data.l[2] - deltay; } /* Don't let maximized clients be moved or resized. */ if(JUNLIKELY(np->state.status & STAT_FULLSCREEN)) { SetClientFullScreen(np, 0); } if(JUNLIKELY(np->state.maxFlags)) { MaximizeClient(np, MAX_NONE); } ConstrainSize(np); ResetBorder(np); SendConfigureEvent(np); RequirePagerUpdate(); }
/** Add a window to management. */ ClientNode *AddClientWindow(Window w, char alreadyMapped, char notOwner) { XWindowAttributes attr; ClientNode *np; Assert(w != None); /* Get window attributes. */ if(JXGetWindowAttributes(display, w, &attr) == 0) { return NULL; } /* Determine if we should care about this window. */ if(attr.override_redirect == True) { return NULL; } if(attr.class == InputOnly) { return NULL; } /* Prepare a client node for this window. */ np = Allocate(sizeof(ClientNode)); memset(np, 0, sizeof(ClientNode)); np->window = w; np->owner = None; np->state.desktop = currentDesktop; np->x = attr.x; np->y = attr.y; np->width = attr.width; np->height = attr.height; np->cmap = attr.colormap; np->state.status = STAT_NONE; np->state.maxFlags = MAX_NONE; np->state.layer = LAYER_NORMAL; np->state.defaultLayer = LAYER_NORMAL; np->state.border = BORDER_DEFAULT; np->borderAction = BA_NONE; ReadClientInfo(np, alreadyMapped); if(!notOwner) { np->state.border = BORDER_OUTLINE | BORDER_TITLE | BORDER_MOVE; np->state.status |= STAT_WMDIALOG | STAT_STICKY; np->state.layer = LAYER_ABOVE; np->state.defaultLayer = LAYER_ABOVE; } ApplyGroups(np); if(np->icon == NULL) { LoadIcon(np); } /* We now know the layer, so insert */ np->prev = NULL; np->next = nodes[np->state.layer]; if(np->next) { np->next->prev = np; } else { nodeTail[np->state.layer] = np; } nodes[np->state.layer] = np; SetDefaultCursor(np->window); ReparentClient(np, notOwner); PlaceClient(np, alreadyMapped); if(!((np->state.status & STAT_FULLSCREEN) || np->state.maxFlags)) { int north, south, east, west; GetBorderSize(&np->state, &north, &south, &east, &west); if(np->parent != None) { JXMoveResizeWindow(display, np->parent, np->x - west, np->y - north, np->width + east + west, np->height + north + south); JXMoveResizeWindow(display, np->window, west, north, np->width, np->height); } else { JXMoveResizeWindow(display, np->window, np->x, np->y, np->width, np->height); } } /* If one of these fails we are SOL, so who cares. */ XSaveContext(display, np->window, clientContext, (void*)np); if(np->parent != None) { XSaveContext(display, np->parent, frameContext, (void*)np); } if(np->state.status & STAT_MAPPED) { JXMapWindow(display, np->window); if(np->parent != None) { JXMapWindow(display, np->parent); } } clientCount += 1; if(!alreadyMapped) { RaiseClient(np); } if(np->state.status & STAT_OPACITY) { SetOpacity(np, np->state.opacity, 1); } else { SetOpacity(np, settings.inactiveClientOpacity, 1); } if(np->state.status & STAT_STICKY) { SetCardinalAtom(np->window, ATOM_NET_WM_DESKTOP, ~0UL); } else { SetCardinalAtom(np->window, ATOM_NET_WM_DESKTOP, np->state.desktop); } /* Shade the client if requested. */ if(np->state.status & STAT_SHADED) { np->state.status &= ~STAT_SHADED; ShadeClient(np); } /* Minimize the client if requested. */ if(np->state.status & STAT_MINIMIZED) { np->state.status &= ~STAT_MINIMIZED; MinimizeClient(np, 0); } /* Maximize the client if requested. */ if(np->state.maxFlags) { const MaxFlags flags = np->state.maxFlags; np->state.maxFlags = MAX_NONE; MaximizeClient(np, flags); } if(np->state.status & STAT_URGENT) { RegisterCallback(URGENCY_DELAY, SignalUrgent, np); } /* Update task bars. */ AddClientToTaskBar(np); /* Make sure we're still in sync */ WriteState(np); SendConfigureEvent(np); /* Hide the client if we're not on the right desktop. */ if(np->state.desktop != currentDesktop && !(np->state.status & STAT_STICKY)) { HideClient(np); } ReadClientStrut(np); /* Focus transients if their parent has focus. */ if(np->owner != None) { if(activeClient && np->owner == activeClient->window) { FocusClient(np); } } /* Make the client fullscreen if requested. */ if(np->state.status & STAT_FULLSCREEN) { np->state.status &= ~STAT_FULLSCREEN; SetClientFullScreen(np, 1); } ResetBorder(np); return np; }
/** Process a key press event. */ void HandleKeyPress(const XKeyEvent *event) { ClientNode *np; KeyType key; key = GetKey(event); np = GetActiveClient(); switch(key & 0xFF) { case KEY_EXEC: RunKeyCommand(event); break; case KEY_DESKTOP: ChangeDesktop((key >> 8) - 1); break; case KEY_RDESKTOP: RightDesktop(); break; case KEY_LDESKTOP: LeftDesktop(); break; case KEY_UDESKTOP: AboveDesktop(); break; case KEY_DDESKTOP: BelowDesktop(); break; case KEY_SHOWDESK: ShowDesktop(); break; case KEY_SHOWTRAY: ShowAllTrays(); break; case KEY_NEXT: StartWindowWalk(); FocusNext(); break; case KEY_NEXTSTACK: StartWindowStackWalk(); WalkWindowStack(1); break; case KEY_PREV: StartWindowWalk(); FocusPrevious(); break; case KEY_PREVSTACK: StartWindowStackWalk(); WalkWindowStack(0); break; case KEY_CLOSE: if(np) { DeleteClient(np); } break; case KEY_SHADE: if(np) { if(np->state.status & STAT_SHADED) { UnshadeClient(np); } else { ShadeClient(np); } } break; case KEY_STICK: if(np) { if(np->state.status & STAT_STICKY) { SetClientSticky(np, 0); } else { SetClientSticky(np, 1); } } break; case KEY_MOVE: if(np) { MoveClientKeyboard(np); } break; case KEY_RESIZE: if(np) { ResizeClientKeyboard(np); } break; case KEY_MIN: if(np) { MinimizeClient(np, 1); } break; case KEY_MAX: if(np) { MaximizeClient(np, 1, 1); } break; case KEY_ROOT: ShowKeyMenu(event); break; case KEY_WIN: if(np) { ShowWindowMenu(np, np->x, np->y); } break; case KEY_RESTART: Restart(); break; case KEY_EXIT: Exit(); break; case KEY_FULLSCREEN: if(np) { if(np->state.status & STAT_FULLSCREEN) { SetClientFullScreen(np, 0); } else { SetClientFullScreen(np, 1); } } break; case KEY_SENDR: if(np) { SetClientDesktop(np, GetRightDesktop(np->state.desktop)); } break; case KEY_SENDL: if(np) { SetClientDesktop(np, GetLeftDesktop(np->state.desktop)); } break; case KEY_SENDU: if(np) { SetClientDesktop(np, GetAboveDesktop(np->state.desktop)); } break; case KEY_SENDD: if(np) { SetClientDesktop(np, GetBelowDesktop(np->state.desktop)); } break; default: break; } }
/** Move a client window (keyboard or menu initiated). */ char MoveClientKeyboard(ClientNode *np) { XEvent event; int oldx, oldy; int moved; int height; int north, south, east, west; MaxFlags maxFlags; Assert(np); if(!(np->state.border & BORDER_MOVE)) { return 0; } if(np->state.status & STAT_FULLSCREEN) { return 0; } maxFlags = np->state.maxFlags; if(np->state.maxFlags != MAX_NONE) { MaximizeClient(np, MAX_NONE); } if(JUNLIKELY(JXGrabKeyboard(display, np->parent, True, GrabModeAsync, GrabModeAsync, CurrentTime))) { Debug("MoveClient: could not grab keyboard"); return 0; } GrabMouseForMove(); GetBorderSize(&np->state, &north, &south, &east, &west); oldx = np->x; oldy = np->y; RegisterCallback(0, SignalMove, NULL); np->controller = MoveController; shouldStopMove = 0; CreateMoveWindow(np); UpdateMoveWindow(np); MoveMouse(rootWindow, np->x, np->y); DiscardMotionEvents(&event, np->window); if(np->state.status & STAT_SHADED) { height = 0; } else { height = np->height; } for(;;) { WaitForEvent(&event); if(shouldStopMove) { np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); return 1; } moved = 0; if(event.type == KeyPress) { DiscardKeyEvents(&event, np->window); switch(GetKey(&event.xkey) & 0xFF) { case KEY_UP: if(np->y + height > 0) { np->y -= 10; } break; case KEY_DOWN: if(np->y < rootHeight) { np->y += 10; } break; case KEY_RIGHT: if(np->x < rootWidth) { np->x += 10; } break; case KEY_LEFT: if(np->x + np->width > 0) { np->x -= 10; } break; default: StopMove(np, 1, oldx, oldy, maxFlags); return 1; } MoveMouse(rootWindow, np->x, np->y); DiscardMotionEvents(&event, np->window); moved = 1; } else if(event.type == MotionNotify) { DiscardMotionEvents(&event, np->window); np->x = event.xmotion.x; np->y = event.xmotion.y; moved = 1; } else if(event.type == ButtonRelease) { StopMove(np, 1, oldx, oldy, maxFlags); return 1; } if(moved) { if(settings.moveMode == MOVE_OUTLINE) { ClearOutline(); DrawOutline(np->x - west, np->y - west, np->width + west + east, height + north + west); } else { JXMoveWindow(display, np->parent, np->x - west, np->y - north); SendConfigureEvent(np); } UpdateMoveWindow(np); RequirePagerUpdate(); } } }
/** Move a client window. */ char MoveClient(ClientNode *np, int startx, int starty) { XEvent event; int oldx, oldy; int doMove; int north, south, east, west; int height; MaxFlags maxFlags; Assert(np); if(!(np->state.border & BORDER_MOVE)) { return 0; } if(np->state.status & STAT_FULLSCREEN) { return 0; } GrabMouseForMove(); RegisterCallback(0, SignalMove, NULL); np->controller = MoveController; shouldStopMove = 0; oldx = np->x; oldy = np->y; maxFlags = np->state.maxFlags; if(!(GetMouseMask() & (Button1Mask | Button2Mask))) { StopMove(np, 0, oldx, oldy, maxFlags); return 0; } GetBorderSize(&np->state, &north, &south, &east, &west); startx -= west; starty -= north; currentClient = np; atTop = atBottom = atLeft = atRight = 0; doMove = 0; for(;;) { WaitForEvent(&event); if(shouldStopMove) { np->controller = NULL; SetDefaultCursor(np->parent); UnregisterCallback(SignalMove, NULL); return doMove; } switch(event.type) { case ButtonRelease: if(event.xbutton.button == Button1 || event.xbutton.button == Button2) { StopMove(np, doMove, oldx, oldy, maxFlags); return doMove; } break; case MotionNotify: DiscardMotionEvents(&event, np->window); np->x = event.xmotion.x_root - startx; np->y = event.xmotion.y_root - starty; /* Get the move time used for desktop switching. */ if(!(atLeft | atTop | atRight | atBottom)) { if(event.xmotion.state & Mod1Mask) { moveTime.seconds = 0; moveTime.ms = 0; } else { GetCurrentTime(&moveTime); } } /* Determine if we are at a border for desktop switching. */ atLeft = atTop = atRight = atBottom = 0; if(event.xmotion.x_root == 0) { atLeft = 1; } else if(event.xmotion.x_root == rootWidth - 1) { atRight = 1; } if(event.xmotion.y_root == 0) { atTop = 1; } else if(event.xmotion.y_root == rootHeight - 1) { atBottom = 1; } if(event.xmotion.state & Mod1Mask) { /* Switch desktops immediately if alt is pressed. */ if(atLeft | atRight | atTop | atBottom) { TimeType now; GetCurrentTime(&now); UpdateDesktop(&now); } } else { /* If alt is not pressed, snap to borders. */ DoSnap(np); } if(!doMove && (abs(np->x - oldx) > MOVE_DELTA || abs(np->y - oldy) > MOVE_DELTA)) { if(np->state.maxFlags) { MaximizeClient(np, MAX_NONE); startx = np->width / 2; starty = -north / 2; MoveMouse(np->parent, startx, starty); } CreateMoveWindow(np); doMove = 1; } if(doMove) { if(settings.moveMode == MOVE_OUTLINE) { ClearOutline(); height = north + south; if(!(np->state.status & STAT_SHADED)) { height += np->height; } DrawOutline(np->x - west, np->y - north, np->width + west + east, height); } else { JXMoveWindow(display, np->parent, np->x - west, np->y - north); SendConfigureEvent(np); } UpdateMoveWindow(np); RequirePagerUpdate(); } break; default: break; } } }
/** Handle a _NET_WM_STATE request. */ void HandleNetWMState(const XClientMessageEvent *event, ClientNode *np) { int actionMaxH; int actionMaxV; int actionStick; int actionShade; int actionFullScreen; int actionMinimize; int actionNolist; int x; /* Up to two actions to be applied together, figure it out. */ actionMaxH = 0; actionMaxV = 0; actionStick = 0; actionShade = 0; actionFullScreen = 0; actionMinimize = 0; actionNolist = 0; for(x = 1; x <= 2; x++) { if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_STICKY]) { actionStick = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_MAXIMIZED_VERT]) { actionMaxV = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_MAXIMIZED_HORZ]) { actionMaxH = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_SHADED]) { actionShade = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_FULLSCREEN]) { actionFullScreen = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_HIDDEN]) { actionMinimize = 1; } else if(event->data.l[x] == (long)atoms[ATOM_NET_WM_STATE_SKIP_TASKBAR]) { actionNolist = 1; } } switch(event->data.l[0]) { case 0: /* Remove */ if(actionStick) { SetClientSticky(np, 0); } if(actionMaxH || actionMaxV) { if(np->state.status & (STAT_HMAX | STAT_VMAX)) { MaximizeClient(np, 0, 0); } } if(actionShade) { UnshadeClient(np); } if(actionFullScreen) { SetClientFullScreen(np, 0); } if(actionMinimize) { RestoreClient(np, 0); } if(actionNolist) { np->state.status &= ~STAT_NOLIST; UpdateTaskBar(); } break; case 1: /* Add */ if(actionStick) { SetClientSticky(np, 1); } if(!(np->state.status & (STAT_HMAX | STAT_VMAX))) { MaximizeClient(np, actionMaxH, actionMaxV); } if(actionShade) { ShadeClient(np); } if(actionFullScreen) { SetClientFullScreen(np, 1); } if(actionMinimize) { MinimizeClient(np); } if(actionNolist) { np->state.status |= STAT_NOLIST; UpdateTaskBar(); } break; case 2: /* Toggle */ if(actionStick) { if(np->state.status & STAT_STICKY) { SetClientSticky(np, 0); } else { SetClientSticky(np, 1); } } if(actionMaxH || actionMaxV) { MaximizeClient(np, actionMaxH, actionMaxV); } if(actionShade) { if(np->state.status & STAT_SHADED) { UnshadeClient(np); } else { ShadeClient(np); } } if(actionFullScreen) { if(np->state.status & STAT_FULLSCREEN) { SetClientFullScreen(np, 0); } else { SetClientFullScreen(np, 1); } } /* Note that we don't handle toggling of hidden per EWMH * recommendations. */ if(actionNolist) { np->state.status ^= STAT_NOLIST; UpdateTaskBar(); } break; default: Debug("bad _NET_WM_STATE action: %ld", event->data.l[0]); break; } }