2 * draw.c - draw functions
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "statusbar.h"
28 extern Client
*clients
, *sel
, *stack
; /* global client list and stack */
30 /** Check if at least a client is tagged with tag number t and is on screen
33 * \param screen screen number
34 * \return True or False
37 isoccupied(unsigned int t
, int screen
)
41 for(c
= clients
; c
; c
= c
->next
)
42 if(c
->tags
[t
] && c
->screen
== screen
)
48 drawstatusbar(Display
*disp
, int screen
, DC
*drawcontext
, awesome_config
* awesomeconf
)
51 drawcontext
->x
= drawcontext
->y
= 0;
52 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
54 drawcontext
->w
= textw(drawcontext
->font
.set
, drawcontext
->font
.xfont
, awesomeconf
->tags
[i
], drawcontext
->font
.height
);
55 if(awesomeconf
->selected_tags
[i
])
57 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->tags
[i
], drawcontext
->sel
);
58 if(isoccupied(i
, screen
))
59 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
&& sel
->tags
[i
], drawcontext
->sel
[ColFG
]);
63 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->tags
[i
], drawcontext
->norm
);
64 if(isoccupied(i
, screen
))
65 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
&& sel
->tags
[i
], drawcontext
->norm
[ColFG
]);
67 drawcontext
->x
+= drawcontext
->w
;
69 drawcontext
->w
= awesomeconf
->statusbar
.width
;
70 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->current_layout
->symbol
, drawcontext
->norm
);
71 x
= drawcontext
->x
+ drawcontext
->w
;
72 drawcontext
->w
= textw(drawcontext
->font
.set
, drawcontext
->font
.xfont
, awesomeconf
->statustext
, drawcontext
->font
.height
);
73 drawcontext
->x
= DisplayWidth(disp
, screen
) - drawcontext
->w
;
74 if(drawcontext
->x
< x
)
77 drawcontext
->w
= DisplayWidth(disp
, screen
) - x
;
79 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, awesomeconf
->statustext
, drawcontext
->norm
);
80 if((drawcontext
->w
= drawcontext
->x
- x
) > awesomeconf
->statusbar
.height
)
85 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
->name
, drawcontext
->sel
);
87 drawsquare(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, sel
->ismax
, drawcontext
->sel
[ColFG
]);
90 drawtext(disp
, *drawcontext
, awesomeconf
->statusbar
.drawable
, NULL
, drawcontext
->norm
);
92 XCopyArea(disp
, awesomeconf
->statusbar
.drawable
, awesomeconf
->statusbar
.window
, drawcontext
->gc
, 0, 0, DisplayWidth(disp
, screen
), awesomeconf
->statusbar
.height
, 0, 0);
97 initstatusbar(Display
*disp
, int screen
, DC
*drawcontext
, Statusbar
*statusbar
)
99 XSetWindowAttributes wa
;
101 statusbar
->screen
= screen
;
103 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
104 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
105 wa
.cursor
= drawcontext
->cursor
[CurNormal
];
106 wa
.override_redirect
= 1;
107 wa
.background_pixmap
= ParentRelative
;
108 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
109 statusbar
->window
= XCreateWindow(disp
, RootWindow(disp
, screen
), 0, 0, DisplayWidth(disp
, screen
),
110 statusbar
->height
, 0, DefaultDepth(disp
, screen
), CopyFromParent
,
111 DefaultVisual(disp
, screen
), CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &wa
);
112 XDefineCursor(disp
, statusbar
->window
, drawcontext
->cursor
[CurNormal
]);
113 updatebarpos(disp
, *statusbar
);
114 XMapRaised(disp
, statusbar
->window
);
115 statusbar
->drawable
= XCreatePixmap(disp
,
116 RootWindow(disp
, screen
),
117 DisplayWidth(disp
, screen
),
119 DefaultDepth(disp
, screen
));
123 updatebarpos(Display
*disp
, Statusbar statusbar
)
128 switch (statusbar
.position
)
131 XMoveWindow(disp
, statusbar
.window
, 0, 0);
134 si
= get_display_info(disp
, statusbar
.screen
, statusbar
);
135 XMoveWindow(disp
, statusbar
.window
, 0, si
->height
);
139 XMoveWindow(disp
, statusbar
.window
, 0, 0 - statusbar
.height
);
143 while(XCheckMaskEvent(disp
, EnterWindowMask
, &ev
));
147 uicb_togglebar(Display
*disp
,
149 awesome_config
*awesomeconf
,
150 const char *arg
__attribute__ ((unused
)))
152 if(awesomeconf
->statusbar
.position
== BarOff
)
153 awesomeconf
->statusbar
.position
= (awesomeconf
->statusbar
.position
== BarOff
) ? BarTop
: awesomeconf
->statusbar_default_position
;
155 awesomeconf
->statusbar
.position
= BarOff
;
156 updatebarpos(disp
, awesomeconf
->statusbar
);
157 arrange(disp
, drawcontext
, awesomeconf
);