X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Ftint2;a=blobdiff_plain;f=src%2Ffreespace%2Ffreespace.c;fp=src%2Ffreespace%2Ffreespace.c;h=6ff96157fc576c7d4d0ed50f585013f211f7eda6;hp=0000000000000000000000000000000000000000;hb=aafb2db7a1f2b69f4f33b4c041e4c1452947daa5;hpb=9f7b8f30f440c4ba7d9894458fa92dfa4344db03 diff --git a/src/freespace/freespace.c b/src/freespace/freespace.c new file mode 100644 index 0000000..6ff9615 --- /dev/null +++ b/src/freespace/freespace.c @@ -0,0 +1,100 @@ +/************************************************************************** +* +* Tint2 : freespace +* +* Copyright (C) 2011 Mishael A Sibiryakov (death@junki.org) +* +* 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 +#include +#include +#include +#include +#include + +#include "window.h" +#include "server.h" +#include "panel.h" +#include "freespace.h" +#include "common.h" + +typedef enum { + COUNT_WIDTH, + COUNT_HEIGHT +} SpaceType ; + +void init_freespace_panel(void *p) +{ + Panel *panel =(Panel*)p; + FreeSpace *fsp= &panel->freespace; + + if (fsp->area.bg == 0) + fsp->area.bg = &g_array_index(backgrounds, Background, 0); + fsp->area.parent = p; + fsp->area.panel = p; + fsp->area.size_mode = SIZE_BY_CONTENT; + fsp->area.resize = 1; + fsp->area.on_screen = 1; + fsp->area._resize = resize_freespace; +} + +int freespace_get_max_size(Panel *p, SpaceType t) { + + GSList *walk; + Area *a; + int sz = 0; + + // Get space used by every element except the freespace + for (walk = p->area.list; walk; walk = g_slist_next(walk)) { + a = (Area *)walk->data; + + // Skip self + if (a->_resize == resize_freespace) + continue; + + if (t == COUNT_WIDTH) + sz += a->width + (a->bg->border.width * 2) + p->area.paddingx; + + if (t == COUNT_HEIGHT) + sz += a->height + (a->bg->border.width * 2) + p->area.paddingy; + } + + if (t == COUNT_WIDTH) + sz = p->area.width - sz - (p->area.bg->border.width * 2) - p->area.paddingxlr; + + if (t == COUNT_HEIGHT) + sz = p->area.height - sz - (p->area.bg->border.width * 2) - p->area.paddingxlr; // Not sure about paddingxlr + + return sz; +} + +int resize_freespace(void *obj) { + + FreeSpace *fsp= (FreeSpace *)obj; + Panel *panel = (Panel *)fsp->area.panel; + + fsp->area.redraw = 1; + + if (panel_horizontal) + fsp->area.width = freespace_get_max_size(panel, COUNT_WIDTH); + else + fsp->area.height= freespace_get_max_size(panel, COUNT_HEIGHT); + + // Always resize + fsp->area.resize = 1; + + return 1; +}