3 * Copyright (C) 2003 Tom Payne
4 * Copyright (C) 2003 Per Olofsson
5 * Copyright (C) 2004-2007 Tuomo Valkonen
7 * by Tom Payne <ion@tompayne.org>
8 * based on code by Per Olofsson <pelle@dsv.su.se>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * $Header: /home/twp/cvsroot/twp/ion/ion-devel-dock/dock.c,v 1.17 2003/12/21 11:59:48 twp Exp $
34 #include <X11/Xatom.h>
35 #include <X11/Xutil.h>
36 #include <X11/extensions/shape.h>
37 #include <X11/extensions/Xext.h>
39 #include <libtu/objp.h>
40 #include <libtu/map.h>
41 #include <libtu/minmax.h>
42 #include <libextl/extl.h>
43 #include <libextl/readconfig.h>
44 #include <libmainloop/defer.h>
46 #include <ioncore/common.h>
47 #include <ioncore/clientwin.h>
48 #include <ioncore/eventh.h>
49 #include <ioncore/global.h>
50 #include <ioncore/manage.h>
51 #include <ioncore/names.h>
52 #include <ioncore/property.h>
53 #include <ioncore/resize.h>
54 #include <ioncore/window.h>
55 #include <ioncore/mplex.h>
56 #include <ioncore/saveload.h>
57 #include <ioncore/bindmaps.h>
58 #include <ioncore/regbind.h>
59 #include <ioncore/extlconv.h>
60 #include <ioncore/event.h>
61 #include <ioncore/resize.h>
62 #include <ioncore/sizehint.h>
63 #include <ioncore/basicpholder.h>
73 #define UNUSED __attribute__ ((unused))
83 #include "../version.h"
85 static const char *modname="dock";
86 const char mod_dock_ion_api_version[]=ION_API_VERSION;
88 static bool shape_extension=FALSE;
89 static int shape_event_basep=0;
90 static int shape_error_basep=0;
92 static WBindmap *dock_bindmap=NULL;
99 INTRSTRUCT(WDockParam);
100 INTRSTRUCT(WDockApp);
103 DECLSTRUCT(WDockParam){
106 const StringIntMap *map;
110 DECLSTRUCT(WDockApp){
111 WDockApp *next, *prev;
117 WRectangle tile_geom;
118 WRectangle border_geom;
123 WDock *dock_next, *dock_prev;
136 static WDock *docks=NULL;
141 /*{{{ Parameter conversion */
143 static void dock_param_extl_table_get(const WDockParam *param,
144 ExtlTab conftab, int value)
148 s=stringintmap_key(param->map, value, NULL);
150 extl_table_sets_s(conftab, param->key, s);
156 static bool dock_param_do_set(const WDockParam *param, char *s,
160 int i=stringintmap_value(param->map, s, -1);
162 warn_obj(modname, "Invalid %s \"%s\"", param->desc, s);
176 static bool dock_param_extl_table_set(const WDockParam *param, ExtlTab conftab,
181 if(extl_table_gets_s(conftab, param->key, &s))
182 return dock_param_do_set(param, s, ret);
189 static bool dock_param_brush_set(const WDockParam *param, GrBrush *brush,
194 if(grbrush_get_extra(brush, param->key, 's', &s))
195 return dock_param_do_set(param, s, ret);
204 /*{{{ Parameter descriptions */
206 static const WDockParam dock_param_name={
214 #define DOCK_HPOS_MASK 0x000f
215 #define DOCK_HPOS_LEFT 0x0000
216 #define DOCK_HPOS_CENTER 0x0001
217 #define DOCK_HPOS_RIGHT 0x0002
218 #define DOCK_VPOS_MASK 0x00f0
219 #define DOCK_VPOS_TOP 0x0000
220 #define DOCK_VPOS_MIDDLE 0x0010
221 #define DOCK_VPOS_BOTTOM 0x0020
224 static StringIntMap dock_pos_map[]={
225 {"tl", DOCK_VPOS_TOP|DOCK_HPOS_LEFT},
226 {"tc", DOCK_VPOS_TOP|DOCK_HPOS_CENTER},
227 {"tr", DOCK_VPOS_TOP|DOCK_HPOS_RIGHT},
228 {"ml", DOCK_VPOS_MIDDLE|DOCK_HPOS_LEFT},
229 {"mc", DOCK_VPOS_MIDDLE|DOCK_HPOS_CENTER},
230 {"mr", DOCK_VPOS_MIDDLE|DOCK_HPOS_RIGHT},
231 {"bl", DOCK_VPOS_BOTTOM|DOCK_HPOS_LEFT},
232 {"bc", DOCK_VPOS_BOTTOM|DOCK_HPOS_CENTER},
233 {"br", DOCK_VPOS_BOTTOM|DOCK_HPOS_RIGHT},
237 static WDockParam dock_param_pos={
241 DOCK_HPOS_LEFT|DOCK_VPOS_BOTTOM
252 static StringIntMap dock_grow_map[]={
253 {"up", DOCK_GROW_UP},
254 {"down", DOCK_GROW_DOWN},
255 {"left", DOCK_GROW_LEFT},
256 {"right", DOCK_GROW_RIGHT},
260 WDockParam dock_param_grow={
268 static const WDockParam dock_param_is_auto={
276 enum WDockOutlineStyle{
277 DOCK_OUTLINE_STYLE_NONE,
278 DOCK_OUTLINE_STYLE_ALL,
279 DOCK_OUTLINE_STYLE_EACH
282 static StringIntMap dock_outline_style_map[]={
283 {"none", DOCK_OUTLINE_STYLE_NONE},
284 {"all", DOCK_OUTLINE_STYLE_ALL},
285 {"each", DOCK_OUTLINE_STYLE_EACH},
289 WDockParam dock_param_outline_style={
292 dock_outline_style_map,
293 DOCK_OUTLINE_STYLE_ALL
297 static const WDockParam dock_param_tile_width={
304 static const WDockParam dock_param_tile_height={
317 #define CLIENTWIN_WINPROP_POSITION "dockposition"
318 #define CLIENTWIN_WINPROP_BORDER "dockborder"
320 static WDockApp *dock_find_dockapp(WDock *dock, WRegion *reg)
324 for(dockapp=dock->dockapps; dockapp!=NULL; dockapp=dockapp->next){
325 if(dockapp->reg==reg){
335 static void dock_get_outline_style(WDock *dock, int *ret)
338 *ret=dock_param_outline_style.dflt;
339 if(dock->brush!=NULL)
340 dock_param_brush_set(&dock_param_outline_style, dock->brush, ret);
347 /*{{{ Size calculation */
350 static void dock_get_tile_size(WDock *dock, WRectangle *ret)
352 ExtlTab tile_size_table;
356 ret->w=dock_param_tile_width.dflt;
357 ret->h=dock_param_tile_height.dflt;
358 if(dock->brush==NULL)
360 if(grbrush_get_extra(dock->brush, "tile_size", 't', &tile_size_table)){
361 extl_table_gets_i(tile_size_table, dock_param_tile_width.key, &ret->w);
362 extl_table_gets_i(tile_size_table, dock_param_tile_height.key, &ret->h);
363 extl_unref_table(tile_size_table);
369 static void dock_get_pos_grow(WDock *dock, int *pos, int *grow)
371 WMPlex *mplex=OBJ_CAST(REGION_PARENT(dock), WMPlex);
372 WRegion *mplex_stdisp;
373 WMPlexSTDispInfo din;
376 mplex_get_stdisp(mplex, &mplex_stdisp, &din);
377 if(mplex_stdisp==(WRegion*)dock){
378 /* Ok, we're assigned as a status display for mplex, so
379 * get parameters from there.
381 *pos=((din.pos==MPLEX_STDISP_TL || din.pos==MPLEX_STDISP_BL)
384 | ((din.pos==MPLEX_STDISP_TL || din.pos==MPLEX_STDISP_TR)
398 static void dock_reshape(WDock *dock)
402 if(!shape_extension){
406 dock_get_outline_style(dock, &outline_style);
408 switch(outline_style){
409 case DOCK_OUTLINE_STYLE_NONE:
410 case DOCK_OUTLINE_STYLE_EACH:
414 /* Start with an empty set */
415 XShapeCombineRectangles(ioncore_g.dpy, ((WWindow*)dock)->win,
416 ShapeBounding, 0, 0, NULL, 0, ShapeSet, 0);
418 /* Union with dockapp shapes */
419 for(dockapp=dock->dockapps; dockapp!=NULL; dockapp=dockapp->next){
420 WClientWin *cwin=OBJ_CAST(dockapp->reg, WClientWin);
421 if(outline_style==DOCK_OUTLINE_STYLE_EACH
422 && dockapp->draw_border){
423 /* Union with border shape */
424 XRectangle tile_rect;
426 tile_rect.x=dockapp->border_geom.x;
427 tile_rect.y=dockapp->border_geom.y;
428 tile_rect.width=dockapp->border_geom.w;
429 tile_rect.height=dockapp->border_geom.h;
430 XShapeCombineRectangles(ioncore_g.dpy, ((WWindow*)dock)->win,
431 ShapeBounding, 0, 0, &tile_rect, 1,
433 }else if(cwin!=NULL){
434 /* Union with dockapp shape */
438 XRectangle *rects=XShapeGetRectangles(ioncore_g.dpy, cwin->win,
439 ShapeBounding, &count,
442 WRectangle dockapp_geom=REGION_GEOM(cwin);
443 XShapeCombineRectangles(ioncore_g.dpy, ((WWindow*)dock)->win,
445 dockapp_geom.x, dockapp_geom.y,
446 rects, count, ShapeUnion, ordering);
454 case DOCK_OUTLINE_STYLE_ALL:
459 geom=REGION_GEOM(dock);
464 XShapeCombineRectangles(ioncore_g.dpy, ((WWindow*)dock)->win,
465 ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
473 static void dock_arrange_dockapps(WDock *dock, const WRectangle *bd_dockg,
474 const WDockApp *replace_this,
477 GrBorderWidths dock_bdw, dockapp_bdw;
478 WDockApp dummy_copy, *dockapp;
479 int pos, grow, cur_coord=0;
480 WRectangle dock_geom;
482 dock->arrange_called=TRUE;
484 dock_get_pos_grow(dock, &pos, &grow);
486 /* Determine dock and dockapp border widths */
487 memset(&dock_bdw, 0, sizeof(GrBorderWidths));
488 memset(&dockapp_bdw, 0, sizeof(GrBorderWidths));
493 dock_get_outline_style(dock, &outline_style);
494 switch(outline_style){
495 case DOCK_OUTLINE_STYLE_NONE:
497 case DOCK_OUTLINE_STYLE_ALL:
498 grbrush_get_border_widths(dock->brush, &dock_bdw);
499 dockapp_bdw.spacing=dock_bdw.spacing;
501 case DOCK_OUTLINE_STYLE_EACH:
502 grbrush_get_border_widths(dock->brush, &dockapp_bdw);
507 dock_geom.w=bd_dockg->w-dock_bdw.left-dock_bdw.right;
508 dock_geom.h=bd_dockg->h-dock_bdw.top-dock_bdw.bottom;
510 /* Calculate initial co-ordinate for layout algorithm */
513 cur_coord=dock_bdw.top+dock_geom.h;
516 cur_coord=dock_bdw.top;
519 cur_coord=dock_bdw.left+dock_geom.w;
521 case DOCK_GROW_RIGHT:
522 cur_coord=dock_bdw.left;
526 /* Arrange dockapps */
527 for(dockapp=dock->dockapps; dockapp!=NULL; dockapp=dockapp->next){
528 WDockApp *da=dockapp;
530 if(replace_this!=NULL){
531 if(replace_this==dockapp){
539 /* Calculate first co-ordinate */
543 switch(pos&DOCK_HPOS_MASK){
547 case DOCK_HPOS_CENTER:
548 da->border_geom.x=(dock_geom.w-da->border_geom.w)/2;
550 case DOCK_HPOS_RIGHT:
551 da->border_geom.x=dock_geom.w-da->border_geom.w;
554 da->border_geom.x+=dock_bdw.left;
557 case DOCK_GROW_RIGHT:
558 switch(pos&DOCK_VPOS_MASK){
562 case DOCK_VPOS_MIDDLE:
563 da->border_geom.y=(dock_geom.h-da->border_geom.h)/2;
565 case DOCK_VPOS_BOTTOM:
566 da->border_geom.y=dock_geom.h-da->border_geom.h;
569 da->border_geom.y+=dock_bdw.top;
573 /* Calculate second co-ordinate */
576 cur_coord-=da->border_geom.h;
577 da->border_geom.y=cur_coord;
578 cur_coord-=dockapp_bdw.spacing;
581 da->border_geom.y=cur_coord;
582 cur_coord+=da->border_geom.h+dockapp_bdw.spacing;
585 cur_coord-=da->border_geom.w;
586 da->border_geom.x=cur_coord;
587 cur_coord-=dockapp_bdw.spacing;
589 case DOCK_GROW_RIGHT:
590 da->border_geom.x=cur_coord;
591 cur_coord+=da->border_geom.w+dockapp_bdw.spacing;
595 /* Calculate tile geom */
596 da->tile_geom.x=da->border_geom.x+dockapp_bdw.left;
597 da->tile_geom.y=da->border_geom.y+dockapp_bdw.top;
599 /* Calculate dockapp geom */
601 da->geom.x=da->tile_geom.x+(da->tile_geom.w-da->geom.w)/2;
602 da->geom.y=da->tile_geom.y+(da->tile_geom.h-da->geom.h)/2;
604 da->geom.x=da->tile_geom.x;
605 da->geom.y=da->tile_geom.y;
608 if(replace_this==NULL)
609 region_fit(da->reg, &(da->geom), REGION_FIT_BOUNDS);
614 static void dock_set_minmax(WDock *dock, int grow, const WRectangle *g)
618 if(grow==DOCK_GROW_UP || grow==DOCK_GROW_DOWN){
628 static void dockapp_calc_preferred_size(WDock *dock, int grow,
629 const WRectangle *tile_size,
632 int w=da->geom.w, h=da->geom.h;
634 if(grow==DOCK_GROW_UP || grow==DOCK_GROW_DOWN){
635 da->geom.w=minof(w, tile_size->w);
639 da->geom.h=minof(h, tile_size->h);
642 region_size_hints_correct(da->reg, &(da->geom.w), &(da->geom.h), TRUE);
647 static void dock_managed_rqgeom_(WDock *dock, WRegion *reg, int flags,
648 const WRectangle *geom, WRectangle *geomret,
649 bool just_update_minmax)
651 WDockApp *dockapp=NULL, *thisdockapp=NULL, thisdockapp_copy;
652 WRectangle parent_geom, dock_geom, border_dock_geom;
653 GrBorderWidths dock_bdw, dockapp_bdw;
654 int n_dockapps=0, max_w=1, max_h=1, total_w=0, total_h=0;
656 WRectangle tile_size;
657 WWindow *par=REGION_PARENT(dock);
659 /* dock_resize calls with NULL parameters. */
660 assert(reg!=NULL || (geomret==NULL && !(flags®ION_RQGEOM_TRYONLY)));
662 dock_get_pos_grow(dock, &pos, &grow);
664 /* Determine parent and tile geoms */
668 parent_geom.w=REGION_GEOM(par).w;
669 parent_geom.h=REGION_GEOM(par).h;
671 /* Should not happen in normal operation. */
676 dock_get_tile_size(dock, &tile_size);
678 /* Determine dock and dockapp border widths */
679 memset(&dock_bdw, 0, sizeof(GrBorderWidths));
680 memset(&dockapp_bdw, 0, sizeof(GrBorderWidths));
685 dock_get_outline_style(dock, &outline_style);
686 switch(outline_style){
687 case DOCK_OUTLINE_STYLE_NONE:
689 case DOCK_OUTLINE_STYLE_ALL:
690 grbrush_get_border_widths(dock->brush, &dock_bdw);
691 dockapp_bdw.spacing=dock_bdw.spacing;
693 case DOCK_OUTLINE_STYLE_EACH:
694 grbrush_get_border_widths(dock->brush, &dockapp_bdw);
699 /* Calculate widths and heights */
700 for(dockapp=dock->dockapps; dockapp!=NULL; dockapp=dockapp->next){
701 WDockApp *da=dockapp;
702 bool update=!(flags®ION_RQGEOM_TRYONLY);
703 if(dockapp->reg==reg){
705 if(flags®ION_RQGEOM_TRYONLY){
706 thisdockapp_copy=*dockapp;
707 thisdockapp_copy.geom=*geom;
708 da=&thisdockapp_copy;
715 /* Calculcate preferred size */
716 dockapp_calc_preferred_size(dock, grow, &tile_size, da);
718 /* Determine whether dockapp should be placed on a tile */
719 da->tile=da->geom.w<=tile_size.w && da->geom.h<=tile_size.h;
721 /* Calculate width and height */
723 da->tile_geom.w=tile_size.w;
724 da->tile_geom.h=tile_size.h;
726 da->tile_geom.w=da->geom.w;
727 da->tile_geom.h=da->geom.h;
730 /* Calculate border width and height */
731 da->border_geom.w=dockapp_bdw.left+da->tile_geom.w+dockapp_bdw.right;
732 da->border_geom.h=dockapp_bdw.top+da->tile_geom.h+dockapp_bdw.right;
735 /* Calculate maximum and accumulated widths and heights */
736 if(da->border_geom.w>max_w)
737 max_w=da->border_geom.w;
738 total_w+=da->border_geom.w+(n_dockapps ? dockapp_bdw.spacing : 0);
740 if(da->border_geom.h>max_h)
741 max_h=da->border_geom.h;
742 total_h+=da->border_geom.h+(n_dockapps ? dockapp_bdw.spacing : 0);
748 if(thisdockapp==NULL && reg!=NULL){
749 warn("Requesting dockapp not found.");
751 *geomret=REGION_GEOM(reg);
755 /* Calculate width and height of dock */
759 case DOCK_GROW_RIGHT:
771 dock_geom.w=tile_size.w;
772 dock_geom.h=tile_size.h;
775 border_dock_geom.x=REGION_GEOM(dock).x;
776 border_dock_geom.y=REGION_GEOM(dock).y;
777 border_dock_geom.w=dock_bdw.left+dock_geom.w+dock_bdw.right;
778 border_dock_geom.h=dock_bdw.top+dock_geom.h+dock_bdw.bottom;
780 /* Fit dock to new geom if required */
781 if(!(flags®ION_RQGEOM_TRYONLY)){
782 WRQGeomParams rq=RQGEOMPARAMS_INIT;
784 dock_set_minmax(dock, grow, &border_dock_geom);
786 if(just_update_minmax)
789 rq.flags=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
790 rq.geom=border_dock_geom;
792 dock->arrange_called=FALSE;
794 region_rqgeom((WRegion*)dock, &rq, NULL);
796 if(!dock->arrange_called)
797 dock_arrange_dockapps(dock, ®ION_GEOM(dock), NULL, NULL);
799 if(thisdockapp!=NULL && geomret!=NULL)
800 *geomret=thisdockapp->geom;
802 if(thisdockapp!=NULL && geomret!=NULL){
803 dock_arrange_dockapps(dock, ®ION_GEOM(dock),
804 thisdockapp, &thisdockapp_copy);
805 *geomret=thisdockapp_copy.geom;
810 static void dock_managed_rqgeom(WDock *dock, WRegion *reg,
811 const WRQGeomParams *rq,
814 dock_managed_rqgeom_(dock, reg, rq->flags, &rq->geom, geomret, FALSE);
818 void dock_size_hints(WDock *dock, WSizeHints *hints)
821 hints->min_width=dock->min_w;
822 hints->min_height=dock->min_h;
825 hints->max_width=dock->max_w;
826 hints->max_height=dock->max_h;
830 static bool dock_fitrep(WDock *dock, WWindow *parent, const WFitParams *fp)
832 if(!window_fitrep(&(dock->win), parent, fp))
835 dock_arrange_dockapps(dock, &(fp->g), NULL, NULL);
844 static int dock_orientation(WDock *dock)
846 return ((dock->grow==DOCK_GROW_LEFT || dock->grow==DOCK_GROW_RIGHT)
847 ? REGION_ORIENTATION_HORIZONTAL
848 : REGION_ORIENTATION_VERTICAL);
858 static void dock_draw(WDock *dock, bool complete)
863 if(dock->brush==NULL)
868 g.w=REGION_GEOM(dock).w;
869 g.h=REGION_GEOM(dock).h;
871 grbrush_begin(dock->brush, &g, (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
873 dock_get_outline_style(dock, &outline_style);
874 switch(outline_style){
875 case DOCK_OUTLINE_STYLE_NONE:
877 case DOCK_OUTLINE_STYLE_ALL:
879 WRectangle geom=REGION_GEOM(dock);
881 grbrush_draw_border(dock->brush, &geom);
884 case DOCK_OUTLINE_STYLE_EACH:
887 for(dockapp=dock->dockapps; dockapp!=NULL;
888 dockapp=dockapp->next){
889 grbrush_draw_border(dock->brush, &dockapp->tile_geom);
895 grbrush_end(dock->brush);
900 * Resizes and refreshes \var{dock}.
903 void dock_resize(WDock *dock)
905 dock_managed_rqgeom_(dock, NULL, 0, NULL, NULL, FALSE);
906 dock_draw(dock, TRUE);
910 static void dock_brush_release(WDock *dock)
914 grbrush_release(dock->brush);
921 static void dock_brush_get(WDock *dock)
924 dock_brush_release(dock);
925 dock->brush=gr_get_brush(((WWindow*)dock)->win,
926 region_rootwin_of((WRegion*)dock),
931 static void dock_updategr(WDock *dock)
933 dock_brush_get(dock);
943 static void mplexpos(int pos, int *mpos)
945 int hp=pos&DOCK_HPOS_MASK, vp=pos&DOCK_VPOS_MASK;
948 p=(vp!=DOCK_VPOS_MIDDLE
950 ? (hp!=DOCK_HPOS_CENTER
951 ? (hp==DOCK_HPOS_RIGHT
955 : (hp!=DOCK_HPOS_CENTER
956 ? (hp==DOCK_HPOS_RIGHT
963 warn("Invalid dock position while as stdisp.");
969 static void mplexszplcy(int pos, WSizePolicy *szplcy)
971 int hp=pos&DOCK_HPOS_MASK, vp=pos&DOCK_VPOS_MASK;
974 p=(vp!=DOCK_VPOS_MIDDLE
976 ? (hp!=DOCK_HPOS_CENTER
977 ? (hp==DOCK_HPOS_RIGHT
978 ? SIZEPOLICY_GRAVITY_NORTHEAST
979 : SIZEPOLICY_GRAVITY_NORTHWEST)
980 : SIZEPOLICY_GRAVITY_NORTH)
981 : (hp!=DOCK_HPOS_CENTER
982 ? (hp==DOCK_HPOS_RIGHT
983 ? SIZEPOLICY_GRAVITY_SOUTHEAST
984 : SIZEPOLICY_GRAVITY_SOUTHWEST)
985 : SIZEPOLICY_GRAVITY_SOUTH))
986 : SIZEPOLICY_GRAVITY_CENTER);
992 static void dock_do_set(WDock *dock, ExtlTab conftab, bool resize)
1000 if(extl_table_gets_s(conftab, dock_param_name.key, &s)){
1001 if(!region_set_name((WRegion*)dock, s)){
1002 warn_obj(modname, "Can't set name to \"%s\"", s);
1007 if(extl_table_gets_b(conftab, "save", &save))
1010 if(dock_param_extl_table_set(&dock_param_pos, conftab, &dock->pos))
1013 if(dock_param_extl_table_set(&dock_param_grow, conftab, &dock->grow))
1016 if(extl_table_gets_b(conftab, dock_param_is_auto.key, &b))
1019 if(resize && (growset || posset)){
1020 WMPlex *par=OBJ_CAST(REGION_PARENT(dock), WMPlex);
1021 WRegion *stdisp=NULL;
1022 WMPlexSTDispInfo din;
1025 mplex_get_stdisp(par, &stdisp, &din);
1026 din.fullsize=FALSE; /* not supported. */
1027 if(stdisp==(WRegion*)dock){
1029 mplexpos(dock->pos, &din.pos);
1031 /* Update min/max first */
1032 dock_managed_rqgeom_(dock, NULL, 0, NULL, NULL, TRUE);
1034 mplex_set_stdisp(par, (WRegion*)dock, &din);
1035 }else if((WRegion*)par==REGION_MANAGER(dock)){
1037 mplexszplcy(dock->pos, &szplcy);
1038 mplex_set_szplcy(par, (WRegion*)dock, szplcy);
1048 * Configure \var{dock}. \var{conftab} is a table of key/value pairs:
1050 * \begin{tabularx}{\linewidth}{llX}
1051 * \tabhead{Key & Values & Description}
1052 * \var{name} & string & Name of dock \\
1053 * \var{pos} & string in $\{t,m,b\}\times\{t,c,b\}$ & Dock position.
1054 * Can only be used in floating mode. \\
1055 * \var{grow} & up/down/left/right &
1056 * Growth direction where new dockapps are added. Also
1057 * sets orientation for dock when working as WMPlex status
1058 * display (see \fnref{WMPlex.set_stdisp}). \\
1059 * \var{is_auto} & bool &
1060 * Should \var{dock} automatically manage new dockapps? \\
1063 * Any parameters not explicitly set in \var{conftab} will be left unchanged.
1066 void dock_set(WDock *dock, ExtlTab conftab)
1068 dock_do_set(dock, conftab, TRUE);
1072 static void dock_do_get(WDock *dock, ExtlTab conftab)
1074 extl_table_sets_s(conftab, dock_param_name.key,
1075 region_name((WRegion*)dock));
1076 dock_param_extl_table_get(&dock_param_pos, conftab, dock->pos);
1077 dock_param_extl_table_get(&dock_param_grow, conftab, dock->grow);
1078 extl_table_sets_b(conftab, dock_param_is_auto.key, dock->is_auto);
1079 extl_table_sets_b(conftab, "save", dock->save);
1084 * Get \var{dock}'s configuration table. See \fnref{WDock.set} for a
1085 * description of the table.
1089 ExtlTab dock_get(WDock *dock)
1093 conftab=extl_create_table();
1094 dock_do_get(dock, conftab);
1102 /*{{{ Init/deinit */
1105 static bool dock_init(WDock *dock, WWindow *parent, const WFitParams *fp)
1109 dock->pos=dock_param_pos.dflt;
1110 dock->grow=dock_param_grow.dflt;
1111 dock->is_auto=dock_param_is_auto.dflt;
1113 dock->dockapps=NULL;
1118 dock->arrange_called=FALSE;
1122 if(!window_init((WWindow*)dock, parent, &fp2))
1125 region_add_bindmap((WRegion*)dock, dock_bindmap);
1127 window_select_input(&(dock->win), IONCORE_EVENTMASK_CWINMGR);
1129 dock_brush_get(dock);
1131 LINK_ITEM(docks, dock, dock_next, dock_prev);
1137 static WDock *create_dock(WWindow *parent, const WFitParams *fp)
1139 CREATEOBJ_IMPL(WDock, dock, (p, parent, fp));
1143 static void dock_deinit(WDock *dock)
1145 while(dock->dockapps!=NULL)
1146 destroy_obj((Obj*)dock->dockapps->reg);
1148 UNLINK_ITEM(docks, dock, dock_next, dock_prev);
1150 dock_brush_release(dock);
1152 window_deinit((WWindow*) dock);
1157 WDock *mod_dock_create(ExtlTab tab)
1160 bool floating=FALSE;
1162 WScreen *screen=NULL;
1164 WRegion *stdisp=NULL;
1165 WMPlexSTDispInfo din;
1168 if(extl_table_gets_s(tab, "mode", &mode)){
1169 if(strcmp(mode, "floating")==0){
1171 }else if(strcmp(mode, "embedded")!=0){
1172 warn("Invalid dock mode.");
1179 extl_table_gets_i(tab, "screen", &screenid);
1180 screen=ioncore_find_screen_id(screenid);
1182 warn("Screen %d does not exist.", screenid);
1186 for(dock=docks; dock; dock=dock->dock_next){
1187 if(region_screen_of((WRegion*)dock)==screen){
1188 warn("Screen %d already has a dock. Refusing to create another.",
1195 mplex_get_stdisp((WMPlex*)screen, &stdisp, &din);
1196 if(stdisp!=NULL && !extl_table_is_bool_set(tab, "force")){
1197 warn("Screen %d already has an stdisp. Refusing to add embedded "
1203 /* Create the dock */
1204 fp.mode=REGION_FIT_BOUNDS|REGION_FIT_WHATEVER;
1210 dock=create_dock((WWindow*)screen, &fp);
1213 warn("Failed to create dock.");
1218 /* Get parameters */
1220 dock_do_set(dock, tab, FALSE);
1222 /* Calculate min/max size */
1223 dock_managed_rqgeom_(dock, NULL, 0, NULL, NULL, TRUE);
1227 const WRectangle *pg=®ION_GEOM(screen);
1228 WMPlexAttachParams par=MPLEXATTACHPARAMS_INIT;
1229 WRegionAttachData data;
1231 par.flags=(MPLEX_ATTACH_UNNUMBERED
1232 |MPLEX_ATTACH_SIZEPOLICY
1234 |MPLEX_ATTACH_PASSIVE);
1236 par.geom.w=dock->min_w;
1237 par.geom.h=dock->min_h;
1241 mplexszplcy(dock->pos, &par.szplcy);
1243 if(extl_table_is_bool_set(tab, "floating_hidden"))
1244 par.flags|=MPLEX_ATTACH_HIDDEN;
1246 data.type=REGION_ATTACH_REPARENT;
1247 data.u.reg=(WRegion*)dock;
1249 if(mplex_do_attach((WMPlex*)screen, &par, &data))
1252 mplexpos(dock->pos, &din.pos);
1253 din.fullsize=FALSE; /* not supported */
1254 if(mplex_set_stdisp((WMPlex*)screen, (WRegion*)dock, &din))
1258 /* Failed to attach. */
1259 warn("Failed to attach dock to screen.");
1260 destroy_obj((Obj*)dock);
1272 * Toggle floating docks on \var{mplex}.
1275 void mod_dock_set_floating_shown_on(WMPlex *mplex, const char *how)
1277 int setpar=libtu_setparam_invert(libtu_string_to_setparam(how));
1280 for(dock=docks; dock; dock=dock->dock_next){
1281 if(REGION_MANAGER(dock)==(WRegion*)mplex)
1282 mplex_set_hidden(mplex, (WRegion*)dock, setpar);
1293 ExtlTab dock_get_configuration(WDock *dock)
1297 if(dock->save==FALSE)
1298 return extl_table_none();
1300 tab=region_get_base_configuration((WRegion*)dock);
1301 dock_do_get(dock, tab);
1307 WRegion *dock_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
1309 WDock *dock=create_dock(par, fp);
1311 dock_set(dock, tab);
1312 dock_fitrep(dock, NULL, fp);
1315 return (WRegion*)dock;
1322 /*{{{ Client window management setup */
1325 static bool dock_do_attach_final(WDock *dock, WRegion *reg, void *unused)
1327 WDockApp *dockapp, *before_dockapp;
1330 bool draw_border=TRUE;
1333 /* Create and initialise a new WDockApp struct */
1334 dockapp=ALLOC(WDockApp);
1339 if(OBJ_IS(reg, WClientWin)){
1340 ExtlTab proptab=((WClientWin*)reg)->proptab;
1341 extl_table_gets_b(proptab, CLIENTWIN_WINPROP_BORDER, &draw_border);
1342 extl_table_gets_i(proptab, CLIENTWIN_WINPROP_POSITION, &pos);
1346 dockapp->draw_border=draw_border;
1348 dockapp->tile=FALSE;
1350 /* Insert the dockapp at the correct relative position */
1351 before_dockapp=dock->dockapps;
1352 for(before_dockapp=dock->dockapps;
1353 before_dockapp!=NULL && dockapp->pos>=before_dockapp->pos;
1354 before_dockapp=before_dockapp->next){
1357 if(before_dockapp!=NULL){
1358 LINK_ITEM_BEFORE(dock->dockapps, before_dockapp, dockapp, next, prev);
1360 LINK_ITEM(dock->dockapps, dockapp, next, prev);
1363 region_set_manager(reg, (WRegion*)dock);
1365 geom=REGION_GEOM(reg);
1366 dock_managed_rqgeom_(dock, reg,
1367 REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y,
1368 &geom, NULL, FALSE);
1377 static WRegion *dock_do_attach(WDock *dock, WRegionAttachData *data)
1380 dock_get_tile_size(dock, &(fp.g));
1383 fp.mode=REGION_FIT_WHATEVER|REGION_FIT_BOUNDS;
1385 return region_attach_helper((WRegion*)dock, (WWindow*)dock, &fp,
1386 (WRegionDoAttachFn*)dock_do_attach_final,
1392 * Attach \var{reg} to \var{dock}.
1395 bool dock_attach(WDock *dock, WRegion *reg)
1397 WRegionAttachData data;
1400 data.type=REGION_ATTACH_REPARENT;
1403 return (dock_do_attach(dock, &data)!=NULL);
1407 static bool dock_handle_drop(WDock *dock, int x, int y,
1410 return dock_attach(dock, dropped);
1414 static WRegion *dock_ph_handler(WDock *dock, int flags, WRegionAttachData *data)
1416 return dock_do_attach(dock, data);
1420 static WPHolder *dock_managed_get_pholder(WDock *dock, WRegion *mgd)
1422 return (WPHolder*)create_basicpholder((WRegion*)dock,
1423 ((WBasicPHolderHandler*)
1428 static WPHolder *dock_prepare_manage(WDock *dock, const WClientWin *cwin,
1429 const WManageParams *param UNUSED,
1432 if(!MANAGE_PRIORITY_OK(priority, MANAGE_PRIORITY_LOW))
1435 return (WPHolder*)create_basicpholder((WRegion*)dock,
1436 ((WBasicPHolderHandler*)
1441 static void dock_managed_remove(WDock *dock, WRegion *reg)
1444 WDockApp *dockapp=dock_find_dockapp(dock, reg);
1449 UNLINK_ITEM(dock->dockapps, dockapp, next, prev);
1452 region_unset_manager(reg, (WRegion*)dock);
1458 static bool dock_clientwin_is_dockapp(WClientWin *cwin,
1459 const WManageParams *param)
1461 bool is_dockapp=FALSE;
1463 /* First, inspect the WManageParams.dockapp parameter */
1468 /* Second, inspect the _NET_WM_WINDOW_TYPE property */
1470 static Atom atom__net_wm_window_type=None;
1471 static Atom atom__net_wm_window_type_dock=None;
1472 Atom actual_type=None;
1474 unsigned long nitems;
1475 unsigned long bytes_after;
1476 unsigned char *prop;
1478 if(atom__net_wm_window_type==None){
1479 atom__net_wm_window_type=XInternAtom(ioncore_g.dpy,
1480 "_NET_WM_WINDOW_TYPE",
1483 if(atom__net_wm_window_type_dock==None){
1484 atom__net_wm_window_type_dock=XInternAtom(ioncore_g.dpy,
1485 "_NET_WM_WINDOW_TYPE_DOCK",
1488 if(XGetWindowProperty(ioncore_g.dpy, cwin->win, atom__net_wm_window_type,
1489 0, sizeof(Atom), False, XA_ATOM, &actual_type,
1490 &actual_format, &nitems, &bytes_after, &prop)
1492 if(actual_type==XA_ATOM && nitems>=1
1493 && *(Atom*)prop==atom__net_wm_window_type_dock){
1500 /* Third, inspect the WM_CLASS property */
1505 p=xwindow_get_text_property(cwin->win, XA_WM_CLASS, &n);
1507 if(n>=2 && strcmp(p[1], "DockApp")==0){
1514 /* Fourth, inspect the _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR property */
1516 static Atom atom__kde_net_wm_system_tray_window_for=None;
1517 Atom actual_type=None;
1519 unsigned long nitems;
1520 unsigned long bytes_after;
1521 unsigned char *prop;
1523 if(atom__kde_net_wm_system_tray_window_for==None){
1524 atom__kde_net_wm_system_tray_window_for=XInternAtom(ioncore_g.dpy,
1525 "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR",
1528 if(XGetWindowProperty(ioncore_g.dpy, cwin->win,
1529 atom__kde_net_wm_system_tray_window_for, 0,
1530 sizeof(Atom), False, AnyPropertyType,
1531 &actual_type, &actual_format, &nitems,
1532 &bytes_after, &prop)==Success){
1533 if(actual_type!=None){
1545 static WDock *dock_find_suitable_dock(WClientWin *cwin,
1546 const WManageParams *param)
1550 for(dock=docks; dock; dock=dock->dock_next){
1553 if(!region_same_rootwin((WRegion*)dock, (WRegion*)cwin))
1562 static bool clientwin_do_manage_hook(WClientWin *cwin, const WManageParams *param)
1566 if(!dock_clientwin_is_dockapp(cwin, param)){
1570 dock=dock_find_suitable_dock(cwin, param);
1575 return region_manage_clientwin((WRegion*)dock, cwin, param,
1576 MANAGE_PRIORITY_NONE);
1583 /*{{{ Module init/deinit */
1586 bool mod_dock_init()
1589 if(XShapeQueryExtension(ioncore_g.dpy, &shape_event_basep,
1590 &shape_error_basep)){
1591 shape_extension=TRUE;
1593 XMissingExtension(ioncore_g.dpy, "SHAPE");
1596 if(!ioncore_register_regclass(&CLASSDESCR(WDock),
1597 (WRegionLoadCreateFn*)dock_load)){
1601 if(!mod_dock_register_exports()){
1602 ioncore_unregister_regclass(&CLASSDESCR(WDock));
1606 dock_bindmap=ioncore_alloc_bindmap("WDock", NULL);
1607 if(dock_bindmap==NULL){
1608 warn("Unable to allocate dock bindmap.");
1609 mod_dock_unregister_exports();
1610 ioncore_unregister_regclass(&CLASSDESCR(WDock));
1613 extl_read_config("cfg_dock", NULL, TRUE);
1615 hook_add(clientwin_do_manage_alt,
1616 (WHookDummy*)clientwin_do_manage_hook);
1623 void mod_dock_deinit()
1627 ioncore_unregister_regclass(&CLASSDESCR(WDock));
1629 hook_remove(clientwin_do_manage_alt,
1630 (WHookDummy*)clientwin_do_manage_hook);
1634 WDock *next=dock->dock_next;
1635 destroy_obj((Obj*)dock);
1639 mod_dock_unregister_exports();
1641 if(dock_bindmap!=NULL){
1642 ioncore_free_bindmap("WDock", dock_bindmap);
1651 /*{{{ WDock class description and dynfun list */
1654 static DynFunTab dock_dynfuntab[]={
1655 {window_draw, dock_draw},
1656 {region_updategr, dock_updategr},
1657 {region_managed_rqgeom, dock_managed_rqgeom},
1658 {(DynFun*)region_prepare_manage, (DynFun*)dock_prepare_manage},
1659 {region_managed_remove, dock_managed_remove},
1660 {(DynFun*)region_get_configuration, (DynFun*)dock_get_configuration},
1661 {region_size_hints, dock_size_hints},
1662 {(DynFun*)region_fitrep, (DynFun*)dock_fitrep},
1663 {(DynFun*)region_orientation, (DynFun*)dock_orientation},
1664 {(DynFun*)region_handle_drop, (DynFun*)dock_handle_drop},
1666 {(DynFun*)region_managed_get_pholder,
1667 (DynFun*)dock_managed_get_pholder},
1673 IMPLCLASS(WDock, WWindow, dock_deinit, dock_dynfuntab);