2008-10-02 18:47:02 +00:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Pål Staurland (staura@gmail.com)
|
|
|
|
* Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-01-30 22:58:36 +00:00
|
|
|
#include <stdio.h>
|
2009-02-07 23:28:13 +00:00
|
|
|
#include <stdlib.h>
|
2008-10-02 18:47:02 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <cairo.h>
|
|
|
|
#include <cairo-xlib.h>
|
|
|
|
#include <pango/pangocairo.h>
|
|
|
|
|
|
|
|
#include "server.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "panel.h"
|
|
|
|
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
int signal_pending;
|
|
|
|
// --------------------------------------------------
|
|
|
|
// mouse events
|
|
|
|
int mouse_middle;
|
|
|
|
int mouse_right;
|
|
|
|
int mouse_scroll_up;
|
|
|
|
int mouse_scroll_down;
|
|
|
|
|
|
|
|
int panel_mode;
|
|
|
|
int panel_position;
|
|
|
|
int panel_refresh;
|
|
|
|
|
|
|
|
Task *task_active = 0;
|
|
|
|
Task *task_drag = 0;
|
|
|
|
|
|
|
|
Panel *panel1 = 0;
|
|
|
|
int nb_panel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void init_panel()
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2009-02-07 23:28:13 +00:00
|
|
|
int i;
|
|
|
|
Panel *p;
|
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
|
|
|
p = &panel1[i];
|
|
|
|
|
|
|
|
p->area.parent = 0;
|
|
|
|
p->area.panel = p;
|
|
|
|
p->g_taskbar.parent = p;
|
|
|
|
p->g_taskbar.panel = p;
|
|
|
|
p->g_task.area.panel = p;
|
|
|
|
|
|
|
|
if (p->pourcentx)
|
|
|
|
p->area.width = (float)server.monitor[p->monitor].width * p->initial_width / 100;
|
|
|
|
else
|
|
|
|
p->area.width = p->initial_width;
|
|
|
|
if (p->pourcenty)
|
|
|
|
p->area.height = (float)server.monitor[p->monitor].height * p->initial_height / 100;
|
|
|
|
else
|
|
|
|
p->area.height = p->initial_height;
|
|
|
|
|
|
|
|
// full width mode
|
|
|
|
if (!p->area.width)
|
|
|
|
p->area.width = server.monitor[p->monitor].width;
|
|
|
|
|
|
|
|
if (p->area.pix.border.rounded > p->area.height/2)
|
|
|
|
p->area.pix.border.rounded = p->area.height/2;
|
|
|
|
|
|
|
|
/* panel position determined here */
|
|
|
|
if (panel_position & LEFT) {
|
|
|
|
p->posx = server.monitor[p->monitor].x + p->marginx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (panel_position & RIGHT) {
|
|
|
|
p->posx = server.monitor[p->monitor].x + server.monitor[p->monitor].width - p->area.width - p->marginx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p->posx = server.monitor[p->monitor].x + ((server.monitor[p->monitor].width - p->area.width) / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (panel_position & TOP) {
|
|
|
|
p->posy = server.monitor[p->monitor].y + p->marginy;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p->posy = server.monitor[p->monitor].y + server.monitor[p->monitor].height - p->area.height - p->marginy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Catch some events
|
|
|
|
XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, ExposureMask|ButtonPressMask|ButtonReleaseMask, NoEventMask, False, 0, 0 };
|
|
|
|
|
|
|
|
// XCreateWindow(display, parent, x, y, w, h, border, depth, class, visual, mask, attrib)
|
|
|
|
// main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
|
|
|
|
if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
|
|
|
|
//win = XCreateWindow (server.dsp, server.root_win, p->posx+p->area.paddingxlr, p->posy, p->area.width-(2*p->area.paddingxlr), p->area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att);
|
|
|
|
p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att);
|
2009-01-18 22:12:41 +00:00
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
set_panel_properties(p);
|
|
|
|
set_panel_background(p);
|
|
|
|
|
|
|
|
XMapWindow (server.dsp, p->main_win);
|
|
|
|
|
|
|
|
init_clock(&p->clock, &p->area);
|
|
|
|
}
|
2009-02-10 23:16:10 +00:00
|
|
|
panel_refresh = 1;
|
2009-02-07 23:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanup_panel()
|
|
|
|
{
|
|
|
|
if (!panel1) return;
|
|
|
|
|
|
|
|
cleanup_taskbar();
|
|
|
|
|
|
|
|
int i;
|
|
|
|
Panel *p;
|
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
|
|
|
p = &panel1[i];
|
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
// no free_area(&p->area) because it's the list of visible objects
|
|
|
|
if (p->area.list) {
|
|
|
|
g_slist_free(p->area.list);
|
|
|
|
p->area.list = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
free_area(&p->g_task.area);
|
|
|
|
free_area(&p->g_taskbar);
|
|
|
|
free_area(&p->clock.area);
|
2009-02-10 23:16:10 +00:00
|
|
|
if (p->area.pix.pmap) XFreePixmap(server.dsp, p->area.pix.pmap);
|
|
|
|
if (p->area.pix_active.pmap) XFreePixmap(server.dsp, p->area.pix_active.pmap);
|
2009-02-07 23:28:13 +00:00
|
|
|
if (p->root_pmap) XFreePixmap(server.dsp, p->root_pmap);
|
|
|
|
if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
|
|
|
|
}
|
|
|
|
|
|
|
|
// font allocated once
|
|
|
|
if (panel1[0].g_task.font_desc) pango_font_description_free(panel1[0].g_task.font_desc);
|
|
|
|
|
|
|
|
if (panel1) free(panel1);
|
|
|
|
panel1 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void visual_refresh (Panel *p)
|
|
|
|
{
|
|
|
|
if (p->root_pmap) XFreePixmap(server.dsp, p->root_pmap);
|
|
|
|
p->root_pmap = XCreatePixmap(server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
|
|
|
|
|
|
|
|
XCopyArea (server.dsp, p->area.pix.pmap, p->root_pmap, server.gc, 0, 0, p->area.width, p->area.height, 0, 0);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2008-11-12 15:11:39 +00:00
|
|
|
// draw child object
|
2009-02-07 23:28:13 +00:00
|
|
|
GSList *l = p->area.list;
|
2009-02-10 23:16:10 +00:00
|
|
|
for (; l ; l = l->next) {
|
2009-01-05 21:01:05 +00:00
|
|
|
refresh (l->data);
|
2009-02-10 23:16:10 +00:00
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
XCopyArea(server.dsp, p->root_pmap, p->main_win, server.gc, 0, 0, p->area.width, p->area.height, 0, 0);
|
|
|
|
|
2008-11-12 15:11:39 +00:00
|
|
|
// main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
|
2009-02-03 20:40:46 +00:00
|
|
|
// this feature is disabled !
|
2009-02-07 23:28:13 +00:00
|
|
|
//XCopyArea (server.dsp, server.pmap, p->main_win, server.gc, p->area.paddingxlr, 0, p->area.width-(2*p->area.paddingxlr), p->area.height, 0, 0);
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
void set_panel_properties(Panel *p)
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2009-02-07 23:28:13 +00:00
|
|
|
XStoreName (server.dsp, p->main_win, "tint2");
|
2008-10-02 18:47:02 +00:00
|
|
|
|
|
|
|
// TODO: check if the name is really needed for a panel/taskbar ?
|
|
|
|
gsize len;
|
|
|
|
gchar *name = g_locale_to_utf8("tint2", -1, NULL, &len, NULL);
|
|
|
|
if (name != NULL) {
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty(server.dsp, p->main_win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 8, PropModeReplace, (unsigned char *) name, (int) len);
|
2008-10-02 18:47:02 +00:00
|
|
|
g_free(name);
|
|
|
|
}
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
// Dock
|
|
|
|
long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
|
|
|
// Reserved space
|
|
|
|
long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
2009-02-07 23:28:13 +00:00
|
|
|
if (panel_position & TOP) {
|
|
|
|
struts[2] = p->area.height + p->marginy;
|
|
|
|
struts[8] = p->posx;
|
|
|
|
// p->area.width - 1 allowed full screen on monitor 2
|
|
|
|
struts[9] = p->posx + p->area.width - 1;
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-02-07 23:28:13 +00:00
|
|
|
struts[3] = p->area.height + p->marginy;
|
|
|
|
struts[10] = p->posx;
|
|
|
|
// p->area.width - 1 allowed full screen on monitor 2
|
|
|
|
struts[11] = p->posx + p->area.width - 1;
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
2008-11-08 20:23:42 +00:00
|
|
|
// Old specification : fluxbox need _NET_WM_STRUT.
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4);
|
|
|
|
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
// Sticky and below other window
|
|
|
|
val = 0xFFFFFFFF;
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
|
2008-10-02 18:47:02 +00:00
|
|
|
Atom state[4];
|
|
|
|
state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
|
|
|
|
state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR;
|
|
|
|
state[2] = server.atom._NET_WM_STATE_STICKY;
|
|
|
|
state[3] = server.atom._NET_WM_STATE_BELOW;
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
// Fixed position
|
|
|
|
XSizeHints size_hints;
|
|
|
|
size_hints.flags = PPosition;
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty (server.dsp, p->main_win, XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32, PropModeReplace, (unsigned char *) &size_hints, sizeof (XSizeHints) / 4);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
// Unfocusable
|
|
|
|
XWMHints wmhints;
|
|
|
|
wmhints.flags = InputHint;
|
|
|
|
wmhints.input = False;
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty (server.dsp, p->main_win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace, (unsigned char *) &wmhints, sizeof (XWMHints) / 4);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2009-01-05 21:01:05 +00:00
|
|
|
// Undecorated
|
|
|
|
long prop[5] = { 2, 0, 0, 0, 0 };
|
2009-02-07 23:28:13 +00:00
|
|
|
XChangeProperty(server.dsp, p->main_win, server.atom._MOTIF_WM_HINTS, server.atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) prop, 5);
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-08 20:23:42 +00:00
|
|
|
void visible_object()
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2009-02-07 23:28:13 +00:00
|
|
|
Panel *panel;
|
2008-11-08 20:23:42 +00:00
|
|
|
int i, j;
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
|
|
|
panel = &panel1[i];
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
if (panel->area.list) {
|
|
|
|
g_slist_free(panel->area.list);
|
|
|
|
panel->area.list = 0;
|
|
|
|
}
|
2009-02-03 20:40:46 +00:00
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
// list of visible objects
|
|
|
|
// start with clock because draw(clock) can resize others object
|
|
|
|
if (time1_format)
|
|
|
|
panel->area.list = g_slist_append(panel->area.list, &panel->clock);
|
2009-02-03 20:40:46 +00:00
|
|
|
|
2009-02-10 23:16:10 +00:00
|
|
|
//panel->area.list = g_slist_append(panel->area.list, &panel->trayer);
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
Taskbar *taskbar;
|
|
|
|
for (j=0 ; j < panel->nb_desktop ; j++) {
|
|
|
|
taskbar = &panel->taskbar[j];
|
|
|
|
if (panel_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) {
|
|
|
|
// (SINGLE_DESKTOP or SINGLE_MONITOR) and not current desktop
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
panel->area.list = g_slist_append(panel->area.list, taskbar);
|
2009-02-03 20:40:46 +00:00
|
|
|
}
|
2009-02-07 23:28:13 +00:00
|
|
|
set_redraw(&panel->area);
|
2009-02-03 20:40:46 +00:00
|
|
|
}
|
2009-02-07 23:28:13 +00:00
|
|
|
panel_refresh = 1;
|
2009-01-29 22:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
void set_panel_background(Panel *p)
|
2008-11-12 15:11:39 +00:00
|
|
|
{
|
2009-02-03 20:40:46 +00:00
|
|
|
get_root_pixmap();
|
2008-11-12 15:11:39 +00:00
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
if (p->area.pix.pmap) XFreePixmap (server.dsp, p->area.pix.pmap);
|
|
|
|
p->area.pix.pmap = XCreatePixmap (server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
|
2008-11-12 15:11:39 +00:00
|
|
|
|
2009-02-03 20:40:46 +00:00
|
|
|
// copy background (server.root_pmap) in panel
|
|
|
|
Window dummy;
|
2009-02-07 23:28:13 +00:00
|
|
|
int x, y;
|
|
|
|
XTranslateCoordinates(server.dsp, p->main_win, server.root_win, 0, 0, &x, &y, &dummy);
|
2009-02-03 20:40:46 +00:00
|
|
|
XSetTSOrigin(server.dsp, server.gc, -x, -y) ;
|
2009-02-07 23:28:13 +00:00
|
|
|
XFillRectangle(server.dsp, p->area.pix.pmap, server.gc, 0, 0, p->area.width, p->area.height);
|
2008-11-12 15:11:39 +00:00
|
|
|
|
|
|
|
// draw background panel
|
|
|
|
cairo_surface_t *cs;
|
|
|
|
cairo_t *c;
|
2009-02-07 23:28:13 +00:00
|
|
|
cs = cairo_xlib_surface_create (server.dsp, p->area.pix.pmap, server.visual, p->area.width, p->area.height);
|
2008-11-12 15:11:39 +00:00
|
|
|
c = cairo_create (cs);
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
draw_background(&p->area, c, 0);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2008-11-12 15:11:39 +00:00
|
|
|
cairo_destroy (c);
|
|
|
|
cairo_surface_destroy (cs);
|
|
|
|
|
2009-02-03 20:40:46 +00:00
|
|
|
// redraw panel
|
2009-02-07 23:28:13 +00:00
|
|
|
set_redraw (&p->area);
|
2009-02-03 20:40:46 +00:00
|
|
|
|
|
|
|
// copy background panel on desktop window
|
2009-02-07 23:28:13 +00:00
|
|
|
//XCopyArea (server.dsp, p->area.pix.pmap, server.root_win, server.gc_root, 0, 0, p->area.width, p->area.height, p->posx, p->posy);
|
2008-11-12 15:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-07 23:28:13 +00:00
|
|
|
Panel *get_panel(Window win)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0 ; i < nb_panel ; i++) {
|
|
|
|
if (panel1[i].main_win == win) {
|
|
|
|
return &panel1[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-01-29 22:43:31 +00:00
|
|
|
|