2 * NanoWM - Window Manager for Nano-X
4 * Copyright (C) 2000 Greg Haerr <greg@censoft.com>
5 * Copyright (C) 2000 Alex Holden <alex@linuxhacker.org>
9 #define MWINCLUDECOLORS
12 /* Uncomment this if you want debugging output from this file */
17 /* uncomment this line to perform outline move operations*/
18 /*#define OUTLINE_MOVE*/
20 void redraw_ncarea(win *window)
23 GR_WM_PROPERTIES props;
26 Dprintf("container_exposure window %d\n", window->wid);
28 GrGetWindowInfo(window->wid, &info);
30 GrGetWMProperties(window->clientid, &props);
33 * Check for invalid window. This will be the
34 * case if the client exited, and we're just
35 * getting the paint notification for our parent.
40 active = (window->clientid == GrGetFocus());
41 nxPaintNCArea(window->wid, info.width, info.height, props.title,
45 void container_exposure(win *window, GR_EVENT_EXPOSURE *event)
47 Dprintf("container_exposure window %d\n", window->wid);
49 redraw_ncarea(window);
53 PtInRect(GR_RECT *prc, GR_SIZE x, GR_SIZE y)
55 return (x >= prc->x && x < (prc->x+prc->width) &&
56 y >= prc->y && y < (prc->y+prc->height));
59 void container_buttondown(win *window, GR_EVENT_BUTTON *event)
63 GR_COORD cxborder = 0, cyborder = 0;
66 Dprintf("container_buttondown window %d\n", window->wid);
68 if(window->active) return;
70 GrGetWindowInfo(window->wid, &info);
72 /* calc border sizes*/
73 if (info.props & GR_WM_PROPS_BORDER) {
77 if (info.props & GR_WM_PROPS_APPFRAME) {
82 /* Check for close box press*/
83 if ((info.props & (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) ==
84 (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) {
86 /* Get close box rect*/
87 r.x = info.width - CXCLOSEBOX - cxborder - 2;
90 r.height = CYCLOSEBOX;
92 /* Check mousedn in close box*/
93 if (PtInRect(&r, event->x, event->y)) {
94 /* this may or not close the window...*/
95 GrCloseWindow(window->clientid);
100 /* Set focus on button down*/
101 GrSetFocus(window->clientid);
103 * Note: Resize seems to cause lots of trouble since the resize "handle"
104 * does not seem to be visible/advertized. Thus at any touch, the window
105 * may get resized and it is often impossible to recover
108 /* check for corner resize */
109 r.x = info.width - 5;
110 r.y = info.height - 5;
114 if(PtInRect(&r,event->x, event->y)) {
116 struct pos_size * pos;
119 if(!(window->data = malloc(sizeof(struct pos_size)))) return;
121 window->sizing = GR_TRUE;
122 pos = (struct pos_size*)window->data;
124 /* save off the width/height offset from the window manager */
125 GrGetWindowInfo(window->clientid,&info);
126 pos->xoff = -info.width;
127 pos->yoff = -info.height;
129 GrGetWindowInfo(window->wid,&info);
130 pos->xoff += info.width;
131 pos->yoff += info.height;
134 GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
135 GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, info.width, info.height);
138 /* save this rectangle's width/height so we can erase it later */
139 pos->width = info.width;
140 pos->height = info.height;
145 /* if not in caption, return (FIXME, not calc'd exactly)*/
146 if (!(info.props & GR_WM_PROPS_CAPTION))
149 /* Get caption box rect*/
152 r.width = info.width - cxborder*2;
153 r.height = CYCAPTION;
155 /* Check for mousedn in caption box*/
156 if (!PtInRect(&r, event->x, event->y))
159 /* Raise window if mouse down and allowed*/
160 if (!(info.props & GR_WM_PROPS_NORAISE))
161 GrRaiseWindow(window->wid);
163 /* Don't allow window move if NOMOVE property set*/
164 if (info.props & GR_WM_PROPS_NOMOVE)
168 if(!(window->data = malloc(sizeof(struct pos_size)))) return;
170 pos = (struct pos_size *) window->data;
172 GrGetWindowInfo(window->wid,&info);
174 pos->xoff = event->x;
175 pos->yoff = event->y;
180 pos->width = info.width;
181 pos->height = info.height;
184 GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
185 GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, info.width, info.height);
188 window->active = GR_TRUE;
191 void container_buttonup(win *window, GR_EVENT_BUTTON *event)
193 Dprintf("container_buttonup window %d\n", window->wid);
196 struct pos_size * pos = (struct pos_size *)window->data;
200 GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
201 GrRect(GR_ROOT_WINDOW_ID,gc,pos->xorig, pos->yorig, pos->width, pos->height);
203 GrMoveWindow(window->wid, pos->xorig, pos->yorig);
207 window->active = GR_FALSE;
215 struct pos_size * pos = (struct pos_size *)window->data;
218 GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
220 GrGetWindowInfo(window->wid, &info);
222 GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, pos->width, pos->height);
224 GrResizeWindow(window->wid,event->rootx - info.x, event->rooty - info.y);
225 GrResizeWindow(window->clientid,event->rootx - info.x - pos->xoff,
226 event->rooty - info.y - pos->yoff);
229 window->sizing = GR_FALSE;
234 void container_mousemoved(win *window, GR_EVENT_MOUSE *event)
236 struct pos_size *pos;
240 Dprintf("container_mousemoved window %d\n", window->wid);
244 struct pos_size * pos = (struct pos_size*)window->data;
245 GrGetWindowInfo(window->wid, &info);
248 GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
250 /* erase old rectangle */
251 GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, pos->width, pos->height);
253 GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y,
254 event->rootx - info.x, event->rooty - info.y);
257 /* save this new rectangle's width, height */
258 /* I know, this shouldn't be stored in x/y, but... */
259 pos->width = event->rootx - info.x;
260 pos->height = event->rooty - info.y;
265 if(!window->active) return;
267 pos = (struct pos_size *) window->data;
271 GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
272 GrRect(GR_ROOT_WINDOW_ID,gc,pos->xorig, pos->yorig, pos->width, pos->height);
273 GrRect(GR_ROOT_WINDOW_ID,gc,event->rootx - pos->xoff, event->rooty - pos->yoff,
274 pos->width, pos->height);
276 pos->xorig = event->rootx - pos->xoff;
277 pos->yorig = event->rooty - pos->yoff;
281 GrMoveWindow(window->wid, event->rootx - pos->xoff,
282 event->rooty - pos->yoff);
287 void topbar_exposure(win *window, GR_EVENT_EXPOSURE *event)
289 win *pwin = find_window(window->pid);
290 struct clientinfo *ci = pwin->data;
291 GR_WM_PROPERTIES prop;
293 Dprintf("topbar_exposure window %d\n", window->wid);
295 GrGetWMProperties(ci->cid, &prop);
297 GrText(window->wid, buttonsgc, 0, 0, prop.title, -1,
298 GR_TFASCII|GR_TFTOP);
301 void closebutton_exposure(win *window, GR_EVENT_EXPOSURE *event)
303 Dprintf("closebutton_exposure window %d\n", window->wid);
305 GrBitmap(window->wid, buttonsgc, 0, 0, TITLE_BAR_HEIGHT,
306 TITLE_BAR_HEIGHT, window->active ? closebutton_pressed :
307 closebutton_notpressed);
310 void topbar_buttondown(win *window, GR_EVENT_BUTTON *event)
312 struct position *pos;
314 Dprintf("topbar_buttondown window %d\n", window->wid);
316 GrRaiseWindow(window->pid);
318 if(window->active) return;
321 if(!(window->data = malloc(sizeof(struct position)))) return;
323 pos = (struct position *) window->data;
325 pos->x = event->x + TITLE_BAR_HEIGHT; /* actually width*/
328 window->active = GR_TRUE;
331 void resizebar_buttondown(win *window, GR_EVENT_BUTTON *event)
334 struct pos_size *pos;
336 Dprintf("resizebar_buttondown window %d\n", window->wid);
338 GrRaiseWindow(window->pid);
340 if(window->active) return;
343 if(!(window->data = malloc(sizeof(struct pos_size)))) return;
345 pos = (struct pos_size *) window->data;
347 GrGetWindowInfo(window->pid, &wi);
349 pos->xoff = event->x;
350 pos->yoff = event->y;
353 pos->width = wi.width;
354 pos->height = wi.height;
356 window->active = GR_TRUE;
359 void closebutton_buttondown(win *window, GR_EVENT_BUTTON *event)
361 Dprintf("closebutton_buttondown window %d\n", window->wid);
363 GrRaiseWindow(window->pid);
365 window->active = GR_TRUE;
366 closebutton_exposure(window, NULL);
370 void topbar_buttonup(win *window, GR_EVENT_BUTTON *event)
372 Dprintf("topbar_buttonup window %d\n", window->wid);
374 window->active = GR_FALSE;
377 void closebutton_buttonup(win *window, GR_EVENT_BUTTON *event)
379 win *pwin = find_window(window->pid);
380 struct clientinfo *ci = pwin->data;
382 Dprintf("closebutton_buttonup window %d\n", window->wid);
384 window->active = GR_FALSE;
385 closebutton_exposure(window, NULL);
387 GrCloseWindow(ci->cid);
390 void topbar_mousemoved(win *window, GR_EVENT_MOUSE *event)
392 struct position *pos;
393 GR_WM_PROPERTIES props;
395 Dprintf("topbar_mousemoved window %d\n", window->wid);
397 if(!window->active) return;
399 pos = (struct position *) window->data;
401 /* turn off background erase draw while moving*/
402 GrGetWMProperties(window->pid, &props);
403 props.flags = GR_WM_FLAGS_PROPS;
404 props.props |= GR_WM_PROPS_NOBACKGROUND;
405 GrSetWMProperties(window->pid, &props);
407 GrMoveWindow(window->pid, event->rootx - pos->x,
408 event->rooty - pos->y);
410 props.props &= ~GR_WM_PROPS_NOBACKGROUND;
411 GrSetWMProperties(window->pid, &props);
414 void leftbar_mousemoved(win *window, GR_EVENT_MOUSE *event)
418 struct pos_size *pos;
420 Dprintf("leftbar_mousemoved window %d\n", window->wid);
422 if(!window->active) return;
424 pos = (struct pos_size *) window->data;
426 newx = event->rootx - pos->xoff;
427 newwidth = pos->width + pos->xorig - event->rootx - pos->xoff;
429 GrMoveWindow(window->pid, newx, pos->yorig);
430 GrResizeWindow(window->pid, newwidth, pos->height);
433 void leftresize_mousemoved(win *window, GR_EVENT_MOUSE *event)
436 GR_SIZE newwidth, newheight;
437 struct pos_size *pos;
439 Dprintf("leftresize_mousemoved window %d\n", window->wid);
441 if(!window->active) return;
443 pos = (struct pos_size *) window->data;
445 newx = event->rootx - pos->xoff;
446 newheight = event->rooty - pos->yorig;
447 newwidth = pos->width + pos->xorig - event->rootx - pos->xoff;
449 GrMoveWindow(window->pid, newx, pos->yorig);
450 GrResizeWindow(window->pid, newwidth, newheight);
453 void bottombar_mousemoved(win *window, GR_EVENT_MOUSE *event)
456 struct pos_size *pos;
458 Dprintf("bottombar_mousemoved window %d\n", window->wid);
460 if(!window->active) return;
462 pos = (struct pos_size *) window->data;
464 newheight = event->rooty - pos->yorig;
466 GrResizeWindow(window->pid, pos->width, newheight);
469 void rightresize_mousemoved(win *window, GR_EVENT_MOUSE *event)
471 GR_SIZE newwidth, newheight;
472 struct pos_size *pos;
474 Dprintf("rightresize_mousemoved window %d\n", window->wid);
476 if(!window->active) return;
478 pos = (struct pos_size *) window->data;
480 newheight = event->rooty - pos->yorig;
481 newwidth = event->rootx - pos->xorig;
483 GrResizeWindow(window->pid, newwidth, newheight);
486 void rightbar_mousemoved(win *window, GR_EVENT_MOUSE *event)
489 struct pos_size *pos;
491 Dprintf("rightbar_mousemoved window %d\n", window->wid);
493 if(!window->active) return;
495 pos = (struct pos_size *) window->data;
497 newwidth = event->rootx - pos->xorig;
499 GrResizeWindow(window->pid, newwidth, pos->height);