2008-10-02 18:47:02 +00:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Tint2 : area
|
2009-01-17 14:07:56 +00:00
|
|
|
*
|
2010-11-02 11:40:50 +00:00
|
|
|
* Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution
|
2009-01-17 14:07:56 +00:00
|
|
|
*
|
2008-10-02 18:47:02 +00:00
|
|
|
* 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.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
2010-01-04 16:25:17 +00:00
|
|
|
#include <X11/extensions/Xrender.h>
|
2008-10-02 18:47:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-01-18 22:12:41 +00:00
|
|
|
#include <pango/pangocairo.h>
|
2008-10-02 18:47:02 +00:00
|
|
|
|
|
|
|
#include "area.h"
|
2009-01-18 22:12:41 +00:00
|
|
|
#include "server.h"
|
2009-02-07 23:28:13 +00:00
|
|
|
#include "panel.h"
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-12-30 16:25:19 +00:00
|
|
|
|
2010-08-08 19:23:54 +00:00
|
|
|
/************************************************************
|
2010-08-10 13:18:17 +00:00
|
|
|
* !!! This design is experimental and not yet fully implemented !!!!!!!!!!!!!
|
2010-08-08 19:23:54 +00:00
|
|
|
*
|
2010-09-16 23:24:25 +00:00
|
|
|
* DATA ORGANISATION :
|
2010-08-08 19:23:54 +00:00
|
|
|
* Areas in tint2 are similar to widgets in a GUI.
|
2010-09-16 23:24:25 +00:00
|
|
|
* All graphical objects (panel, taskbar, task, systray, clock, ...) 'inherit' an abstract class 'Area'.
|
|
|
|
* This class 'Area' manage the background, border, size, position and padding.
|
|
|
|
* Area is at the begining of each object (&object == &area).
|
2010-08-08 19:23:54 +00:00
|
|
|
*
|
2010-09-16 23:24:25 +00:00
|
|
|
* tint2 define one panel per monitor. And each panel have a tree of Area.
|
2010-08-10 13:18:17 +00:00
|
|
|
* The root of the tree is Panel.Area. And task, clock, systray, taskbar,... are nodes.
|
|
|
|
*
|
2010-09-16 23:24:25 +00:00
|
|
|
* The tree give the localisation of each object :
|
|
|
|
* - tree's root is in the background while tree's leafe are foreground objects
|
|
|
|
* - position of a node/Area depend on the layout : parent's position (posx, posy), size of previous brothers and parent's padding
|
|
|
|
* - size of a node/Area depend on the content (SIZE_BY_CONTENT objects) or on the layout (SIZE_BY_LAYOUT objects)
|
|
|
|
*
|
|
|
|
* DRAWING AND LAYERING ENGINE :
|
|
|
|
* Redrawing an object (like the clock) could come from an 'external event' (date change)
|
|
|
|
* or from a 'layering event' (position change).
|
2010-09-21 09:54:19 +00:00
|
|
|
* The following 'drawing engine' take care of :
|
|
|
|
* - posx/posy of all Area
|
|
|
|
* - 'layering event' propagation between object
|
2010-09-16 23:24:25 +00:00
|
|
|
* 1) browse tree SIZE_BY_CONTENT
|
|
|
|
* - resize SIZE_BY_CONTENT node : children are resized before parent
|
|
|
|
* - if 'size' changed then 'resize = 1' on the parent
|
|
|
|
* 2) browse tree SIZE_BY_LAYOUT and POSITION
|
|
|
|
* - resize SIZE_BY_LAYOUT node : parent is resized before children
|
|
|
|
* - calculate position (posx,posy) : parent is calculated before children
|
|
|
|
* - if 'position' changed then 'redraw = 1'
|
|
|
|
* 3) browse tree REDRAW
|
|
|
|
* - redraw needed objects : parent is drawn before children
|
|
|
|
*
|
|
|
|
* CONFIGURE PANEL'S LAYOUT :
|
2010-08-10 13:18:17 +00:00
|
|
|
* 'panel_items' parameter (in config) define the list and the order of nodes in tree's panel.
|
|
|
|
* 'panel_items = SC' define a panel with just Systray and Clock.
|
2010-09-16 23:24:25 +00:00
|
|
|
* So the tree 'Panel.Area' will have 2 childs (Systray and Clock).
|
2010-08-10 13:18:17 +00:00
|
|
|
*
|
2010-08-08 19:23:54 +00:00
|
|
|
************************************************************/
|
|
|
|
|
2010-09-21 09:54:19 +00:00
|
|
|
void init_rendering(void *obj, int pos)
|
|
|
|
{
|
|
|
|
Area *a = (Area*)obj;
|
|
|
|
|
|
|
|
// initialize fixed position/size
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l;
|
2010-09-21 09:54:19 +00:00
|
|
|
for (l = a->list; l ; l = l->next) {
|
|
|
|
Area *child = ((Area*)l->data);
|
|
|
|
if (panel_horizontal) {
|
|
|
|
child->posy = pos + a->bg->border.width + a->paddingy;
|
|
|
|
child->height = a->height - (2 * (a->bg->border.width + a->paddingy));
|
2015-01-30 09:53:16 +00:00
|
|
|
if (child->_on_change_layout)
|
|
|
|
child->_on_change_layout(child);
|
2010-09-21 09:54:19 +00:00
|
|
|
init_rendering(child, child->posy);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
child->posx = pos + a->bg->border.width + a->paddingy;
|
|
|
|
child->width = a->width - (2 * (a->bg->border.width + a->paddingy));
|
2015-01-30 09:53:16 +00:00
|
|
|
if (child->_on_change_layout)
|
|
|
|
child->_on_change_layout(child);
|
2010-09-21 09:54:19 +00:00
|
|
|
init_rendering(child, child->posx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-18 10:41:34 +00:00
|
|
|
void rendering(void *obj)
|
|
|
|
{
|
|
|
|
Panel *panel = (Panel*)obj;
|
2010-11-13 10:27:26 +00:00
|
|
|
|
2010-09-18 10:41:34 +00:00
|
|
|
size_by_content(&panel->area);
|
2015-06-11 22:52:10 +00:00
|
|
|
size_by_layout(&panel->area, 1);
|
2010-09-18 10:41:34 +00:00
|
|
|
|
|
|
|
refresh(&panel->area);
|
|
|
|
}
|
|
|
|
|
2010-08-07 12:17:56 +00:00
|
|
|
|
2010-08-08 14:06:15 +00:00
|
|
|
void size_by_content (Area *a)
|
|
|
|
{
|
2010-09-16 23:24:25 +00:00
|
|
|
// don't resize hiden objects
|
2015-06-11 22:52:10 +00:00
|
|
|
if (!a->on_screen)
|
|
|
|
return;
|
2010-08-10 13:18:17 +00:00
|
|
|
|
2010-08-08 14:06:15 +00:00
|
|
|
// children node are resized before its parent
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l;
|
2010-08-08 14:06:15 +00:00
|
|
|
for (l = a->list; l ; l = l->next)
|
|
|
|
size_by_content(l->data);
|
|
|
|
|
2010-09-16 23:24:25 +00:00
|
|
|
// calculate area's size
|
2010-09-25 21:18:47 +00:00
|
|
|
a->on_changed = 0;
|
2010-08-08 14:06:15 +00:00
|
|
|
if (a->resize && a->size_mode == SIZE_BY_CONTENT) {
|
|
|
|
a->resize = 0;
|
|
|
|
|
2010-08-08 19:23:54 +00:00
|
|
|
if (a->_resize) {
|
2010-09-16 23:24:25 +00:00
|
|
|
if (a->_resize(a)) {
|
2010-09-26 13:10:37 +00:00
|
|
|
// 'size' changed => 'resize = 1' on the parent
|
2010-09-16 23:24:25 +00:00
|
|
|
((Area*)a->parent)->resize = 1;
|
2010-09-25 21:18:47 +00:00
|
|
|
a->on_changed = 1;
|
2010-09-16 23:24:25 +00:00
|
|
|
}
|
2010-08-08 19:23:54 +00:00
|
|
|
}
|
2010-08-08 14:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-11 22:52:10 +00:00
|
|
|
void size_by_layout (Area *a, int level)
|
2010-08-08 14:06:15 +00:00
|
|
|
{
|
2010-09-16 23:24:25 +00:00
|
|
|
// don't resize hiden objects
|
2015-06-11 22:52:10 +00:00
|
|
|
if (!a->on_screen)
|
|
|
|
return;
|
2010-08-10 13:18:17 +00:00
|
|
|
|
2010-08-08 14:06:15 +00:00
|
|
|
// parent node is resized before its children
|
2010-09-16 23:24:25 +00:00
|
|
|
// calculate area's size
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l;
|
2010-08-08 14:06:15 +00:00
|
|
|
if (a->resize && a->size_mode == SIZE_BY_LAYOUT) {
|
|
|
|
a->resize = 0;
|
|
|
|
|
2010-08-08 19:23:54 +00:00
|
|
|
if (a->_resize) {
|
2010-09-26 13:10:37 +00:00
|
|
|
a->_resize(a);
|
|
|
|
// resize childs with SIZE_BY_LAYOUT
|
|
|
|
for (l = a->list; l ; l = l->next) {
|
|
|
|
Area *child = ((Area*)l->data);
|
|
|
|
if (child->size_mode == SIZE_BY_LAYOUT && child->list)
|
|
|
|
child->resize = 1;
|
2010-08-08 19:23:54 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-08 14:06:15 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 22:52:10 +00:00
|
|
|
// update position of children
|
|
|
|
if (a->list) {
|
|
|
|
if (a->alignment == ALIGN_LEFT) {
|
|
|
|
int pos = (panel_horizontal ? a->posx : a->posy) + a->bg->border.width + a->paddingxlr;
|
|
|
|
|
|
|
|
for (l = a->list; l ; l = l->next) {
|
|
|
|
Area *child = ((Area*)l->data);
|
|
|
|
if (!child->on_screen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (panel_horizontal) {
|
|
|
|
if (pos != child->posx) {
|
|
|
|
// pos changed => redraw
|
|
|
|
child->posx = pos;
|
|
|
|
child->on_changed = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pos != child->posy) {
|
|
|
|
// pos changed => redraw
|
|
|
|
child->posy = pos;
|
|
|
|
child->on_changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_by_layout(child, level+1);
|
|
|
|
|
|
|
|
pos += panel_horizontal ? child->width + a->paddingx : child->height + a->paddingx;
|
2010-09-19 10:01:06 +00:00
|
|
|
}
|
2015-06-11 22:52:10 +00:00
|
|
|
} else if (a->alignment == ALIGN_RIGHT) {
|
|
|
|
int pos = (panel_horizontal ? a->posx + a->width : a->posy + a->height) - a->bg->border.width - a->paddingxlr;
|
|
|
|
|
|
|
|
for (l = g_list_last(a->list); l ; l = l->prev) {
|
|
|
|
Area *child = ((Area*)l->data);
|
|
|
|
if (!child->on_screen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pos -= panel_horizontal ? child->width : child->height;
|
|
|
|
|
|
|
|
if (panel_horizontal) {
|
|
|
|
if (pos != child->posx) {
|
|
|
|
// pos changed => redraw
|
|
|
|
child->posx = pos;
|
|
|
|
child->on_changed = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pos != child->posy) {
|
|
|
|
// pos changed => redraw
|
|
|
|
child->posy = pos;
|
|
|
|
child->on_changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_by_layout(child, level+1);
|
|
|
|
|
|
|
|
pos -= a->paddingx;
|
|
|
|
}
|
|
|
|
} else if (a->alignment == ALIGN_CENTER) {
|
|
|
|
|
|
|
|
int children_size = 0;
|
|
|
|
|
|
|
|
for (l = a->list; l ; l = l->next) {
|
|
|
|
Area *child = ((Area*)l->data);
|
|
|
|
if (!child->on_screen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
children_size += panel_horizontal ? child->width : child->height;
|
|
|
|
children_size += (l == a->list) ? 0 : a->paddingx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pos = (panel_horizontal ? a->posx : a->posy) + a->bg->border.width + a->paddingxlr;
|
|
|
|
pos += ((panel_horizontal ? a->width : a->height) - children_size) / 2;
|
|
|
|
|
|
|
|
for (l = a->list; l ; l = l->next) {
|
|
|
|
Area *child = ((Area*)l->data);
|
|
|
|
if (!child->on_screen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (panel_horizontal) {
|
|
|
|
if (pos != child->posx) {
|
|
|
|
// pos changed => redraw
|
|
|
|
child->posx = pos;
|
|
|
|
child->on_changed = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pos != child->posy) {
|
|
|
|
// pos changed => redraw
|
|
|
|
child->posy = pos;
|
|
|
|
child->on_changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_by_layout(child, level+1);
|
|
|
|
|
|
|
|
pos += panel_horizontal ? child->width + a->paddingx : child->height + a->paddingx;
|
2010-09-19 10:01:06 +00:00
|
|
|
}
|
2010-09-18 10:41:34 +00:00
|
|
|
}
|
2015-06-11 22:52:10 +00:00
|
|
|
}
|
2010-09-26 13:10:37 +00:00
|
|
|
|
|
|
|
if (a->on_changed) {
|
|
|
|
// pos/size changed
|
|
|
|
a->redraw = 1;
|
|
|
|
if (a->_on_change_layout)
|
|
|
|
a->_on_change_layout (a);
|
2010-09-18 10:41:34 +00:00
|
|
|
}
|
2010-08-08 14:06:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-27 22:18:30 +00:00
|
|
|
|
2010-09-16 23:24:25 +00:00
|
|
|
void refresh (Area *a)
|
|
|
|
{
|
|
|
|
// don't draw and resize hide objects
|
|
|
|
if (!a->on_screen) return;
|
|
|
|
|
|
|
|
// don't draw transparent objects (without foreground and without background)
|
|
|
|
if (a->redraw) {
|
|
|
|
a->redraw = 0;
|
|
|
|
// force redraw of child
|
2015-06-11 22:52:10 +00:00
|
|
|
//GList *l;
|
2010-09-26 13:10:37 +00:00
|
|
|
//for (l = a->list ; l ; l = l->next)
|
|
|
|
//((Area*)l->data)->redraw = 1;
|
2010-09-16 23:24:25 +00:00
|
|
|
|
|
|
|
//printf("draw area posx %d, width %d\n", a->posx, a->width);
|
|
|
|
draw(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw current Area
|
|
|
|
if (a->pix == 0) printf("empty area posx %d, width %d\n", a->posx, a->width);
|
|
|
|
XCopyArea (server.dsp, a->pix, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
|
|
|
|
|
|
|
|
// and then refresh child object
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l;
|
2010-09-16 23:24:25 +00:00
|
|
|
for (l = a->list; l ; l = l->next)
|
|
|
|
refresh(l->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-26 17:07:33 +00:00
|
|
|
int resize_by_layout(void *obj, int maximum_size)
|
2010-09-21 09:54:19 +00:00
|
|
|
{
|
2010-09-22 22:01:37 +00:00
|
|
|
Area *child, *a = (Area*)obj;
|
|
|
|
int size, nb_by_content=0, nb_by_layout=0;
|
2010-09-21 09:54:19 +00:00
|
|
|
|
2010-09-22 22:01:37 +00:00
|
|
|
if (panel_horizontal) {
|
|
|
|
// detect free size for SIZE_BY_LAYOUT's Area
|
|
|
|
size = a->width - (2 * (a->paddingxlr + a->bg->border.width));
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l;
|
2010-09-22 22:01:37 +00:00
|
|
|
for (l = a->list ; l ; l = l->next) {
|
|
|
|
child = (Area*)l->data;
|
|
|
|
if (child->on_screen && child->size_mode == SIZE_BY_CONTENT) {
|
|
|
|
size -= child->width;
|
|
|
|
nb_by_content++;
|
|
|
|
}
|
|
|
|
if (child->on_screen && child->size_mode == SIZE_BY_LAYOUT)
|
|
|
|
nb_by_layout++;
|
|
|
|
}
|
2010-11-13 10:27:26 +00:00
|
|
|
//printf(" resize_by_layout Deb %d, %d\n", nb_by_content, nb_by_layout);
|
2010-09-22 22:01:37 +00:00
|
|
|
if (nb_by_content+nb_by_layout)
|
|
|
|
size -= ((nb_by_content+nb_by_layout-1) * a->paddingx);
|
|
|
|
|
2010-09-26 13:10:37 +00:00
|
|
|
int width=0, modulo=0, old_width;
|
2010-09-22 22:01:37 +00:00
|
|
|
if (nb_by_layout) {
|
|
|
|
width = size / nb_by_layout;
|
|
|
|
modulo = size % nb_by_layout;
|
2010-09-26 17:07:33 +00:00
|
|
|
if (width > maximum_size && maximum_size != 0) {
|
|
|
|
width = maximum_size;
|
|
|
|
modulo = 0;
|
|
|
|
}
|
2010-09-21 09:54:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-22 22:01:37 +00:00
|
|
|
// resize SIZE_BY_LAYOUT objects
|
|
|
|
for (l = a->list ; l ; l = l->next) {
|
|
|
|
child = (Area*)l->data;
|
|
|
|
if (child->on_screen && child->size_mode == SIZE_BY_LAYOUT) {
|
2010-09-26 13:10:37 +00:00
|
|
|
old_width = child->width;
|
2010-09-22 22:01:37 +00:00
|
|
|
child->width = width;
|
|
|
|
if (modulo) {
|
|
|
|
child->width++;
|
|
|
|
modulo--;
|
|
|
|
}
|
2010-09-26 13:10:37 +00:00
|
|
|
if (child->width != old_width)
|
|
|
|
child->on_changed = 1;
|
2010-09-21 09:54:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2010-09-22 22:01:37 +00:00
|
|
|
// detect free size for SIZE_BY_LAYOUT's Area
|
|
|
|
size = a->height - (2 * (a->paddingxlr + a->bg->border.width));
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l;
|
2010-09-22 22:01:37 +00:00
|
|
|
for (l = a->list ; l ; l = l->next) {
|
|
|
|
child = (Area*)l->data;
|
|
|
|
if (child->on_screen && child->size_mode == SIZE_BY_CONTENT) {
|
|
|
|
size -= child->height;
|
|
|
|
nb_by_content++;
|
|
|
|
}
|
|
|
|
if (child->on_screen && child->size_mode == SIZE_BY_LAYOUT)
|
|
|
|
nb_by_layout++;
|
|
|
|
}
|
|
|
|
if (nb_by_content+nb_by_layout)
|
|
|
|
size -= ((nb_by_content+nb_by_layout-1) * a->paddingx);
|
2010-09-21 09:54:19 +00:00
|
|
|
|
2015-06-11 22:52:10 +00:00
|
|
|
int height=0, modulo=0;
|
2010-09-22 22:01:37 +00:00
|
|
|
if (nb_by_layout) {
|
|
|
|
height = size / nb_by_layout;
|
|
|
|
modulo = size % nb_by_layout;
|
2010-09-26 17:07:33 +00:00
|
|
|
if (height > maximum_size && maximum_size != 0) {
|
|
|
|
height = maximum_size;
|
|
|
|
modulo = 0;
|
|
|
|
}
|
2010-09-21 09:54:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-22 22:01:37 +00:00
|
|
|
// resize SIZE_BY_LAYOUT objects
|
|
|
|
for (l = a->list ; l ; l = l->next) {
|
|
|
|
child = (Area*)l->data;
|
|
|
|
if (child->on_screen && child->size_mode == SIZE_BY_LAYOUT) {
|
2015-06-11 22:52:10 +00:00
|
|
|
int old_height = child->height;
|
2010-09-22 22:01:37 +00:00
|
|
|
child->height = height;
|
|
|
|
if (modulo) {
|
|
|
|
child->height++;
|
|
|
|
modulo--;
|
|
|
|
}
|
2010-09-26 13:10:37 +00:00
|
|
|
if (child->height != old_height)
|
|
|
|
child->on_changed = 1;
|
2010-09-21 09:54:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-05 21:01:05 +00:00
|
|
|
void set_redraw (Area *a)
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
a->redraw = 1;
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l;
|
2009-09-07 21:41:21 +00:00
|
|
|
for (l = a->list ; l ; l = l->next)
|
|
|
|
set_redraw(l->data);
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
2010-09-22 19:33:10 +00:00
|
|
|
void hide(Area *a)
|
|
|
|
{
|
|
|
|
Area *parent = (Area*)a->parent;
|
|
|
|
|
|
|
|
a->on_screen = 0;
|
|
|
|
parent->resize = 1;
|
|
|
|
if (panel_horizontal)
|
|
|
|
a->width = 0;
|
|
|
|
else
|
|
|
|
a->height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void show(Area *a)
|
|
|
|
{
|
|
|
|
Area *parent = (Area*)a->parent;
|
|
|
|
|
|
|
|
a->on_screen = 1;
|
|
|
|
parent->resize = 1;
|
|
|
|
a->resize = 1;
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2010-01-09 00:11:01 +00:00
|
|
|
void draw (Area *a)
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2010-01-09 00:11:01 +00:00
|
|
|
if (a->pix) XFreePixmap (server.dsp, a->pix);
|
|
|
|
a->pix = XCreatePixmap (server.dsp, server.root_win, a->width, a->height, server.depth);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-12-30 23:27:31 +00:00
|
|
|
// add layer of root pixmap (or clear pixmap if real_transparency==true)
|
2010-04-18 12:07:36 +00:00
|
|
|
if (server.real_transparency)
|
2010-01-09 00:11:01 +00:00
|
|
|
clear_pixmap(a->pix, 0 ,0, a->width, a->height);
|
|
|
|
XCopyArea (server.dsp, ((Panel *)a->panel)->temp_pmap, a->pix, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
cairo_surface_t *cs;
|
|
|
|
cairo_t *c;
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2010-01-09 00:11:01 +00:00
|
|
|
cs = cairo_xlib_surface_create (server.dsp, a->pix, server.visual, a->width, a->height);
|
2009-09-07 21:41:21 +00:00
|
|
|
c = cairo_create (cs);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2010-01-09 00:11:01 +00:00
|
|
|
draw_background (a, c);
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
if (a->_draw_foreground)
|
2010-01-09 00:11:01 +00:00
|
|
|
a->_draw_foreground(a, c);
|
2008-11-08 20:23:42 +00:00
|
|
|
|
2009-09-07 21:41:21 +00:00
|
|
|
cairo_destroy (c);
|
|
|
|
cairo_surface_destroy (cs);
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-09 00:11:01 +00:00
|
|
|
void draw_background (Area *a, cairo_t *c)
|
2008-10-02 18:47:02 +00:00
|
|
|
{
|
2010-01-09 00:11:01 +00:00
|
|
|
if (a->bg->back.alpha > 0.0) {
|
2009-09-07 21:41:21 +00:00
|
|
|
//printf(" draw_background (%d %d) RGBA (%lf, %lf, %lf, %lf)\n", a->posx, a->posy, pix->back.color[0], pix->back.color[1], pix->back.color[2], pix->back.alpha);
|
2010-01-09 00:11:01 +00:00
|
|
|
draw_rect(c, a->bg->border.width, a->bg->border.width, a->width-(2.0 * a->bg->border.width), a->height-(2.0*a->bg->border.width), a->bg->border.rounded - a->bg->border.width/1.571);
|
|
|
|
cairo_set_source_rgba(c, a->bg->back.color[0], a->bg->back.color[1], a->bg->back.color[2], a->bg->back.alpha);
|
2009-09-07 21:41:21 +00:00
|
|
|
cairo_fill(c);
|
|
|
|
}
|
|
|
|
|
2010-01-09 00:11:01 +00:00
|
|
|
if (a->bg->border.width > 0 && a->bg->border.alpha > 0.0) {
|
|
|
|
cairo_set_line_width (c, a->bg->border.width);
|
2009-09-07 21:41:21 +00:00
|
|
|
|
|
|
|
// draw border inside (x, y, width, height)
|
2010-01-09 00:11:01 +00:00
|
|
|
draw_rect(c, a->bg->border.width/2.0, a->bg->border.width/2.0, a->width - a->bg->border.width, a->height - a->bg->border.width, a->bg->border.rounded);
|
2009-09-07 21:41:21 +00:00
|
|
|
/*
|
|
|
|
// convert : radian = degre * M_PI/180
|
2010-08-08 14:06:15 +00:00
|
|
|
// definir le degrade dans un carre de (0,0) (100,100)
|
|
|
|
// ensuite ce degrade est extrapoler selon le ratio width/height
|
|
|
|
// dans repere (0, 0) (100, 100)
|
2009-09-07 21:41:21 +00:00
|
|
|
double X0, Y0, X1, Y1, degre;
|
|
|
|
// x = X * (a->width / 100), y = Y * (a->height / 100)
|
|
|
|
double x0, y0, x1, y1;
|
|
|
|
X0 = 0;
|
|
|
|
Y0 = 100;
|
|
|
|
X1 = 100;
|
|
|
|
Y1 = 0;
|
|
|
|
degre = 45;
|
2010-08-08 14:06:15 +00:00
|
|
|
// et ensuite faire la changement d'unite du repere
|
|
|
|
// car ce qui doit reste inchangee est les traits et pas la direction
|
2009-09-07 21:41:21 +00:00
|
|
|
|
2010-08-08 14:06:15 +00:00
|
|
|
// il faut d'abord appliquer une rotation de 90 (et -180 si l'angle est superieur a 180)
|
|
|
|
// ceci peut etre applique une fois pour toute au depart
|
|
|
|
// ensuite calculer l'angle dans le nouveau repare
|
|
|
|
// puis faire une rotation de 90
|
2009-09-07 21:41:21 +00:00
|
|
|
x0 = X0 * ((double)a->width / 100);
|
|
|
|
x1 = X1 * ((double)a->width / 100);
|
|
|
|
y0 = Y0 * ((double)a->height / 100);
|
|
|
|
y1 = Y1 * ((double)a->height / 100);
|
|
|
|
|
|
|
|
x0 = X0 * ((double)a->height / 100);
|
|
|
|
x1 = X1 * ((double)a->height / 100);
|
|
|
|
y0 = Y0 * ((double)a->width / 100);
|
|
|
|
y1 = Y1 * ((double)a->width / 100);
|
|
|
|
|
|
|
|
cairo_pattern_t *linpat;
|
|
|
|
linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
|
|
|
|
cairo_pattern_add_color_stop_rgba (linpat, 0, a->border.color[0], a->border.color[1], a->border.color[2], a->border.alpha);
|
|
|
|
cairo_pattern_add_color_stop_rgba (linpat, 1, a->border.color[0], a->border.color[1], a->border.color[2], 0);
|
|
|
|
cairo_set_source (c, linpat);
|
|
|
|
*/
|
2010-01-09 00:11:01 +00:00
|
|
|
cairo_set_source_rgba (c, a->bg->border.color[0], a->bg->border.color[1], a->bg->border.color[2], a->bg->border.alpha);
|
2009-09-07 21:41:21 +00:00
|
|
|
|
|
|
|
cairo_stroke (c);
|
|
|
|
//cairo_pattern_destroy (linpat);
|
|
|
|
}
|
2008-10-02 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void remove_area (Area *a)
|
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
Area *parent = (Area*)a->parent;
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2015-06-11 22:52:10 +00:00
|
|
|
parent->list = g_list_remove(parent->list, a);
|
2009-09-07 21:41:21 +00:00
|
|
|
set_redraw (parent);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void add_area (Area *a)
|
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
Area *parent = (Area*)a->parent;
|
2009-01-17 14:07:56 +00:00
|
|
|
|
2015-06-11 22:52:10 +00:00
|
|
|
parent->list = g_list_append(parent->list, a);
|
2009-09-07 21:41:21 +00:00
|
|
|
set_redraw (parent);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-08 20:23:42 +00:00
|
|
|
|
|
|
|
void free_area (Area *a)
|
|
|
|
{
|
2015-04-11 09:51:10 +00:00
|
|
|
if (!a)
|
|
|
|
return;
|
|
|
|
|
2015-06-11 22:52:10 +00:00
|
|
|
GList *l0;
|
2009-09-07 21:41:21 +00:00
|
|
|
for (l0 = a->list; l0 ; l0 = l0->next)
|
|
|
|
free_area (l0->data);
|
|
|
|
|
|
|
|
if (a->list) {
|
2015-06-11 22:52:10 +00:00
|
|
|
g_list_free(a->list);
|
2009-09-07 21:41:21 +00:00
|
|
|
a->list = 0;
|
2009-02-13 21:54:42 +00:00
|
|
|
}
|
2010-01-09 00:11:01 +00:00
|
|
|
if (a->pix) {
|
|
|
|
XFreePixmap (server.dsp, a->pix);
|
|
|
|
a->pix = 0;
|
2009-02-13 21:54:42 +00:00
|
|
|
}
|
2008-11-08 20:23:42 +00:00
|
|
|
}
|
|
|
|
|
2009-01-18 22:12:41 +00:00
|
|
|
|
|
|
|
void draw_rect(cairo_t *c, double x, double y, double w, double h, double r)
|
|
|
|
{
|
2009-09-07 21:41:21 +00:00
|
|
|
if (r > 0.0) {
|
|
|
|
double c1 = 0.55228475 * r;
|
|
|
|
|
|
|
|
cairo_move_to(c, x+r, y);
|
|
|
|
cairo_rel_line_to(c, w-2*r, 0);
|
|
|
|
cairo_rel_curve_to(c, c1, 0.0, r, c1, r, r);
|
|
|
|
cairo_rel_line_to(c, 0, h-2*r);
|
|
|
|
cairo_rel_curve_to(c, 0.0, c1, c1-r, r, -r, r);
|
|
|
|
cairo_rel_line_to (c, -w +2*r, 0);
|
|
|
|
cairo_rel_curve_to (c, -c1, 0, -r, -c1, -r, -r);
|
|
|
|
cairo_rel_line_to (c, 0, -h + 2 * r);
|
|
|
|
cairo_rel_curve_to (c, 0, -c1, r - c1, -r, r, -r);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cairo_rectangle(c, x, y, w, h);
|
2009-01-18 22:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-30 23:27:31 +00:00
|
|
|
void clear_pixmap(Pixmap p, int x, int y, int w, int h)
|
|
|
|
{
|
2010-01-04 16:25:17 +00:00
|
|
|
Picture pict = XRenderCreatePicture(server.dsp, p, XRenderFindVisualFormat(server.dsp, server.visual), 0, 0);
|
|
|
|
XRenderColor col = { .red=0, .green=0, .blue=0, .alpha=0 };
|
|
|
|
XRenderFillRectangle(server.dsp, PictOpSrc, pict, &col, x, y, w, h);
|
2010-01-05 11:21:18 +00:00
|
|
|
XRenderFreePicture(server.dsp, pict);
|
2009-12-30 23:27:31 +00:00
|
|
|
}
|