# Phase 4 — Input & Focus --- ## Step 4.1 — Click-to-focus and raise On `ButtonPress` events on managed windows, set focus with `XSetInputFocus(dpy, win->xwin, RevertToParent, CurrentTime)` and raise the window with `XRaiseWindow()`. Register for `ButtonPressMask` on all managed windows using a passive grab: ```c XGrabButton(dpy, AnyButton, AnyModifier, win->xwin, True, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); ``` On `ButtonPress`, set focus, raise, then `XAllowEvents(dpy, ReplayPointer, CurrentTime)` to pass the click through to the client. **Verify:** Click on `xterm` — it receives focus and comes to front. Type in it. Click `xeyes` — it comes to front. Focus switching works. --- ## Step 4.2 — Window dragging with Mod+Click Grab `Mod4 + Button1` (Super+Click) on the root window. On press, start tracking a drag. On motion, `XMoveWindow()` the client and update the stored position. On release, stop. ```c XGrabButton(dpy, Button1, Mod4Mask, root, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None); ``` **Verify:** Super+Click and drag moves windows around inside Xephyr. Release drops them. The composited view updates in real-time. --- ## Step 4.3 — Window resizing with Mod+RightClick Same pattern as dragging but with `Mod4 + Button3`. On motion, call `XResizeWindow()`. Re-obtain the pixmap and texture after resize. **Verify:** Super+RightClick and drag resizes windows. The texture updates to show the new content.