2 * ion/panews/unusedwin.c
4 * Copyright (c) Tuomo Valkonen 1999-2006.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
14 #include <libtu/objp.h>
15 #include <libtu/minmax.h>
16 #include <ioncore/common.h>
17 #include <ioncore/global.h>
18 #include <ioncore/event.h>
19 #include <ioncore/gr.h>
20 #include <ioncore/regbind.h>
21 #include <ioncore/framep.h>
22 #include <ioncore/presize.h>
23 #include <ioncore/frame-pointer.h>
24 #include "unusedwin.h"
26 #include "placement.h"
33 static void unusedwin_getbrush(WUnusedWin *uwin)
35 GrBrush *brush=gr_get_brush(uwin->wwin.win,
36 region_rootwin_of((WRegion*)uwin),
37 "frame-tiled-panews-unused");
41 grbrush_release(uwin->brush);
45 grbrush_enable_transparency(brush, GR_TRANSPARENCY_YES);
50 bool unusedwin_init(WUnusedWin *uwin, WWindow *parent, const WFitParams *fp)
54 if(!window_init(&(uwin->wwin), parent, fp))
57 unusedwin_getbrush(uwin);
59 region_add_bindmap((WRegion*)uwin, mod_panews_unusedwin_bindmap);
61 window_select_input(&(uwin->wwin), IONCORE_EVENTMASK_NORMAL);
63 ((WRegion*)uwin)->flags|=REGION_PLEASE_WARP;
69 WUnusedWin *create_unusedwin(WWindow *parent, const WFitParams *fp)
71 CREATEOBJ_IMPL(WUnusedWin, unusedwin, (p, parent, fp));
75 void unusedwin_deinit(WUnusedWin *uwin)
77 if(uwin->brush!=NULL){
78 grbrush_release(uwin->brush);
82 window_deinit(&(uwin->wwin));
89 /*{{{ unusedwin_press */
92 static void unusedwin_border_inner_geom(const WUnusedWin *uwin,
99 geom->w=REGION_GEOM(uwin).w;
100 geom->h=REGION_GEOM(uwin).h;
102 if(uwin->brush!=NULL){
103 grbrush_get_border_widths(uwin->brush, &bdw);
107 geom->w-=bdw.left+bdw.right;
108 geom->h-=bdw.top+bdw.bottom;
111 geom->w=maxof(geom->w, 0);
112 geom->h=maxof(geom->h, 0);
116 static int unusedwin_press(WUnusedWin *uwin, XButtonEvent *ev,
123 window_p_resize_prepare(&uwin->wwin, ev);
127 unusedwin_border_inner_geom(uwin, &g);
129 if(rectangle_contains(&g, ev->x, ev->y))
130 return FRAME_AREA_CLIENT;
132 return FRAME_AREA_BORDER;
139 /*{{{ unusedwin_handle_drop */
142 static bool unusedwin_handle_drop(WUnusedWin *uwin, int x, int y,
145 WSplitUnused *us=OBJ_CAST(splittree_node_of((WRegion*)uwin),
147 WPaneWS *ws=REGION_MANAGER_CHK(uwin, WPaneWS);
149 if(us==NULL || ws==NULL)
152 return panews_handle_unused_drop(ws, us, dropped);
162 static void unusedwin_updategr(WUnusedWin *uwin)
164 unusedwin_getbrush(uwin);
165 region_updategr_default((WRegion*)uwin);
169 static void unusedwin_draw(WUnusedWin *uwin, bool complete)
172 const char *substyle=(REGION_IS_ACTIVE(uwin)
176 if(uwin->brush==NULL)
181 g.w=REGION_GEOM(uwin).w;
182 g.h=REGION_GEOM(uwin).h;
184 grbrush_begin(uwin->brush, &g, (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
186 grbrush_draw_border(uwin->brush, &g, substyle);
188 grbrush_end(uwin->brush);
198 static DynFunTab unusedwin_dynfuntab[]={
199 {region_updategr, unusedwin_updategr},
200 {window_draw, unusedwin_draw},
201 {(DynFun*)window_press, (DynFun*)unusedwin_press},
202 {(DynFun*)region_handle_drop, (DynFun*)unusedwin_handle_drop},
207 IMPLCLASS(WUnusedWin, WWindow, unusedwin_deinit, unusedwin_dynfuntab);