2012-05-30 14:23:27 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Sanel Zukan
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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-10-06 15:20:19 +04:00
|
|
|
#include <stdio.h>
|
2009-10-03 11:33:08 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/x.H>
|
2009-10-06 15:20:19 +04:00
|
|
|
#include <X11/Xproto.h>
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
#include <edelib/Debug.h>
|
|
|
|
#include <edelib/List.h>
|
|
|
|
#include <edelib/WindowXid.h>
|
|
|
|
#include <edelib/Resource.h>
|
|
|
|
#include <edelib/Util.h>
|
2009-12-17 18:16:35 +03:00
|
|
|
#include <edelib/Netwm.h>
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
#include "Panel.h"
|
|
|
|
|
|
|
|
/* empty space from left and right panel border */
|
|
|
|
#define INITIAL_SPACING 5
|
|
|
|
|
|
|
|
/* space between each applet */
|
|
|
|
#define DEFAULT_SPACING 5
|
|
|
|
|
|
|
|
/* default panel height */
|
|
|
|
#define DEFAULT_PANEL_H 35
|
|
|
|
|
|
|
|
#undef MIN
|
|
|
|
#undef MAX
|
2012-05-28 14:57:50 +04:00
|
|
|
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
2009-10-03 11:33:08 +04:00
|
|
|
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
|
|
|
|
2012-04-11 20:15:01 +04:00
|
|
|
EDELIB_NS_USING_LIST(10, (list,
|
|
|
|
Resource,
|
|
|
|
String,
|
|
|
|
window_xid_create,
|
|
|
|
build_filename,
|
|
|
|
netwm_window_set_strut,
|
|
|
|
netwm_window_remove_strut,
|
|
|
|
netwm_window_set_type,
|
|
|
|
netwm_workarea_get_size,
|
|
|
|
NETWM_WINDOW_TYPE_DOCK))
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
typedef list<Fl_Widget*> WidgetList;
|
|
|
|
typedef list<Fl_Widget*>::iterator WidgetListIt;
|
|
|
|
|
2012-06-07 13:32:27 +04:00
|
|
|
/* used only insid x_events */
|
|
|
|
static Panel *gpanel;
|
|
|
|
|
2009-12-17 18:16:35 +03:00
|
|
|
inline bool intersects(Fl_Widget *o1, Fl_Widget *o2) {
|
|
|
|
return (MAX(o1->x(), o2->x()) <= MIN(o1->x() + o1->w(), o2->x() + o2->w()) &&
|
|
|
|
MAX(o1->y(), o2->y()) <= MIN(o1->y() + o1->h(), o2->y() + o2->h()));
|
|
|
|
}
|
|
|
|
|
2009-10-06 15:20:19 +04:00
|
|
|
static int xerror_handler(Display *d, XErrorEvent *e) {
|
|
|
|
if(e->request_code == X_GetImage)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* construct the similar message format like X11 is using by default, but again, little
|
|
|
|
* bit different so we knows it comes from here
|
|
|
|
*/
|
|
|
|
|
|
|
|
sprintf(buf, "%d", e->request_code);
|
|
|
|
|
|
|
|
XGetErrorDatabaseText(d, "XRequest", buf, "%d", buf, sizeof(buf));
|
|
|
|
fprintf(stderr, "%s: ", buf);
|
|
|
|
|
|
|
|
XGetErrorText(d, e->error_code, buf, sizeof(buf));
|
|
|
|
fprintf(stderr, "%s\n", buf);
|
|
|
|
|
|
|
|
XGetErrorDatabaseText(d, "XlibMessage", "ResourceID", "%d", buf, sizeof(buf));
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
fprintf(stderr, buf, e->resourceid);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-17 18:16:35 +03:00
|
|
|
static void make_me_dock(Fl_Window *win) {
|
|
|
|
netwm_window_set_type(fl_xid(win), NETWM_WINDOW_TYPE_DOCK);
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
2012-06-07 13:32:27 +04:00
|
|
|
static int x_events(int ev) {
|
|
|
|
/*
|
|
|
|
* This is quite stupid to do, but hopefully very reliable. When screen is resized
|
|
|
|
* root window was resized too and using those sizes, panel is placed. Tracking workarea changes
|
|
|
|
* isn't much of use, as setting struts dimensions will affect workarea dimension too.
|
|
|
|
*/
|
|
|
|
if(fl_xevent->type == ConfigureNotify &&
|
|
|
|
(fl_xevent->xconfigure.window == RootWindow(fl_display, fl_screen))) {
|
|
|
|
gpanel->update_size_and_pos(false, false,
|
|
|
|
fl_xevent->xconfigure.x,
|
|
|
|
fl_xevent->xconfigure.y,
|
|
|
|
fl_xevent->xconfigure.width,
|
|
|
|
fl_xevent->xconfigure.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let others receive the same event */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
/* horizontaly centers widget in the panel */
|
|
|
|
static void center_widget_h(Fl_Widget *o, Panel *self) {
|
|
|
|
int ph, wy;
|
|
|
|
|
|
|
|
ph = self->panel_h() / 2;
|
|
|
|
wy = ph - (o->h() / 2);
|
|
|
|
o->position(o->x(), wy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_from_list(WidgetList &lst, Panel *self, int &X, bool inc) {
|
|
|
|
WidgetListIt it = lst.begin(), it_end = lst.end();
|
|
|
|
Fl_Widget *o;
|
|
|
|
|
|
|
|
while(it != it_end) {
|
|
|
|
o = *it;
|
|
|
|
|
|
|
|
/* 'inc == false' means we are going from right to left */
|
|
|
|
if(!inc)
|
|
|
|
X -= o->w();
|
|
|
|
|
|
|
|
/* place it correctly */
|
|
|
|
o->position(X, o->y());
|
|
|
|
|
|
|
|
self->add(o);
|
|
|
|
|
|
|
|
if(inc) {
|
|
|
|
X += DEFAULT_SPACING;
|
|
|
|
X += o->w();
|
|
|
|
} else {
|
|
|
|
X -= DEFAULT_SPACING;
|
|
|
|
}
|
|
|
|
|
|
|
|
it = lst.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:26:58 +04:00
|
|
|
#if 0
|
2009-10-03 11:33:08 +04:00
|
|
|
static void move_widget(Panel *self, Fl_Widget *o, int &sx, int &sy) {
|
|
|
|
int tx, ty, px, py;
|
|
|
|
Fl_Widget *const *a;
|
|
|
|
|
|
|
|
tx = Fl::event_x() - sx;
|
|
|
|
ty = Fl::event_y() - sy;
|
|
|
|
|
|
|
|
px = o->x() + tx;
|
|
|
|
py = o->y() + ty;
|
|
|
|
|
|
|
|
/* check the bounds */
|
|
|
|
if(px < 0)
|
|
|
|
px = 0;
|
|
|
|
if(px + o->w() > self->panel_w())
|
|
|
|
px = self->panel_w() - o->w();
|
|
|
|
if(py < 0)
|
|
|
|
py = 0;
|
|
|
|
if(py + o->h() > self->y() + self->panel_h())
|
|
|
|
py = self->y() + self->panel_h() - o->h();
|
|
|
|
if(py + o->h() > self->panel_h())
|
|
|
|
py = self->panel_h() - o->h();
|
|
|
|
|
|
|
|
/* o->position(px, py); */
|
|
|
|
o->position(px, o->y());
|
|
|
|
|
|
|
|
/* find possible collision and move others */
|
|
|
|
a = self->array();
|
|
|
|
for(int i = self->children(); i--; ) {
|
|
|
|
if(o == a[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(intersects(a[i], o)) {
|
|
|
|
px = a[i]->x() + tx;
|
|
|
|
py = a[i]->y() + ty;
|
|
|
|
|
|
|
|
/* check the bounds */
|
|
|
|
if(px < 0)
|
|
|
|
px = 0;
|
|
|
|
if(px + o->w() > self->panel_w())
|
|
|
|
px = self->panel_w() - o->w();
|
|
|
|
if(py < 0)
|
|
|
|
py = 0;
|
|
|
|
if(py + o->h() > self->y() + self->panel_h())
|
|
|
|
py = self->y() + self->panel_h() - o->h();
|
|
|
|
if(py + o->h() > self->panel_h())
|
|
|
|
py = self->panel_h() - o->h();
|
|
|
|
|
|
|
|
/* a[i]->position(px, py); */
|
|
|
|
a[i]->position(px, a[i]->y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update current position */
|
|
|
|
sx = Fl::event_x();
|
|
|
|
sy = Fl::event_y();
|
|
|
|
|
|
|
|
o->parent()->redraw();
|
|
|
|
}
|
2009-10-07 13:26:58 +04:00
|
|
|
#endif
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2009-11-18 15:24:58 +03:00
|
|
|
Panel::Panel() : PanelWindow(300, 30) {
|
2012-06-07 13:32:27 +04:00
|
|
|
gpanel = this;
|
|
|
|
|
2009-11-18 15:24:58 +03:00
|
|
|
clicked = 0;
|
|
|
|
sx = sy = 0;
|
|
|
|
vpos = PANEL_POSITION_BOTTOM;
|
2012-04-04 13:58:23 +04:00
|
|
|
screen_x = screen_y = screen_w = screen_h = screen_h_half = 0;
|
|
|
|
width_perc = 100;
|
2009-11-18 15:24:58 +03:00
|
|
|
can_move_widgets = false;
|
2012-04-11 20:15:01 +04:00
|
|
|
can_drag = true;
|
2009-11-18 15:24:58 +03:00
|
|
|
|
|
|
|
box(FL_UP_BOX);
|
|
|
|
read_config();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::read_config(void) {
|
|
|
|
Resource r;
|
|
|
|
if(!r.load("ede-panel"))
|
|
|
|
return;
|
|
|
|
|
2012-04-04 13:58:23 +04:00
|
|
|
int tmp;
|
|
|
|
if(r.get("Panel", "position", tmp, PANEL_POSITION_BOTTOM)) {
|
|
|
|
if((tmp != PANEL_POSITION_TOP) && (tmp != PANEL_POSITION_BOTTOM))
|
|
|
|
tmp = PANEL_POSITION_BOTTOM;
|
|
|
|
vpos = tmp;
|
2009-11-18 15:24:58 +03:00
|
|
|
}
|
|
|
|
|
2012-04-04 13:58:23 +04:00
|
|
|
if(r.get("Panel", "width", tmp, 100)) {
|
|
|
|
if(tmp > 100) tmp = 100;
|
|
|
|
else if(tmp < 10) tmp = 10;
|
|
|
|
|
|
|
|
width_perc = tmp;
|
|
|
|
}
|
2009-11-18 15:24:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::save_config(void) {
|
|
|
|
Resource r;
|
2012-04-04 13:58:23 +04:00
|
|
|
/* use whatever was explicitly stored in configuration */
|
|
|
|
r.load("ede-panel");
|
|
|
|
|
2009-11-18 15:24:58 +03:00
|
|
|
r.set("Panel", "position", vpos);
|
|
|
|
r.save("ede-panel");
|
|
|
|
}
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
void Panel::do_layout(void) {
|
|
|
|
E_RETURN_IF_FAIL(mgr.napplets() > 0);
|
|
|
|
|
|
|
|
Fl_Widget *o;
|
|
|
|
unsigned long opts;
|
|
|
|
unsigned int lsz;
|
|
|
|
int X, W, free_w;
|
|
|
|
|
|
|
|
WidgetList left, right, center, unmanaged, resizable_h;
|
|
|
|
|
|
|
|
for(int i = 0; i < children(); i++) {
|
|
|
|
o = child(i);
|
|
|
|
|
|
|
|
/* first center it vertically */
|
|
|
|
center_widget_h(o, this);
|
|
|
|
|
|
|
|
/* could be slow, but I'm relaying how number of loaded applets will not be that large */
|
|
|
|
if(!mgr.get_applet_options(o, opts)) {
|
|
|
|
/* here are put widgets not loaded as applets */
|
|
|
|
unmanaged.push_back(o);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opts & EDE_PANEL_APPLET_OPTION_RESIZABLE_H)
|
|
|
|
resizable_h.push_back(o);
|
|
|
|
|
|
|
|
if(opts & EDE_PANEL_APPLET_OPTION_ALIGN_LEFT) {
|
|
|
|
/* first item will be most leftest */
|
|
|
|
left.push_back(o);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opts & EDE_PANEL_APPLET_OPTION_ALIGN_RIGHT) {
|
|
|
|
/* first item will be most rightest */
|
|
|
|
right.push_back(o);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rest of them */
|
|
|
|
center.push_back(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure we at the end have all widgets, so we can overwrite group array */
|
|
|
|
lsz = left.size() + center.size() + right.size() + unmanaged.size();
|
|
|
|
E_ASSERT(lsz == (unsigned int)children() && "Size of layout lists size not equal to group size");
|
|
|
|
|
|
|
|
X = INITIAL_SPACING;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call add() on each element, processing lists in order. add() will remove element
|
|
|
|
* in group array and put it at the end of array. At the end, we should have array ordered by
|
|
|
|
* layout flags.
|
|
|
|
*/
|
|
|
|
add_from_list(left, this, X, true);
|
|
|
|
add_from_list(center, this, X, true);
|
|
|
|
add_from_list(unmanaged, this, X, true);
|
|
|
|
|
|
|
|
free_w = X;
|
|
|
|
|
|
|
|
/* elements right will be put from starting from the right panel border */
|
|
|
|
X = w() - INITIAL_SPACING;
|
|
|
|
add_from_list(right, this, X, false);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code for horizontal streching.
|
|
|
|
*
|
2009-11-18 15:24:58 +03:00
|
|
|
* FIXME: This code pretty sucks and need better rewrite in the future.
|
2009-10-03 11:33:08 +04:00
|
|
|
* To work properly, applets that will be streched must be successive or everything will be
|
|
|
|
* messed up. Also, applets that are placed right2left does not work with it; they will be resized to right.
|
|
|
|
*/
|
|
|
|
if(resizable_h.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* calculate free space for horizontal alignement, per item in resizable_h list */
|
|
|
|
free_w = (X - free_w) / resizable_h.size();
|
|
|
|
if(!free_w) free_w = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* since add_from_list() will already reserve some space by current child width and default spacing,
|
|
|
|
* those values will be used again or holes will be made
|
|
|
|
*/
|
|
|
|
WidgetListIt it = resizable_h.begin(), it_end = resizable_h.end();
|
|
|
|
o = resizable_h.front();
|
|
|
|
X = o->x();
|
|
|
|
|
|
|
|
while(it != it_end) {
|
|
|
|
o = *it;
|
|
|
|
|
|
|
|
W = o->w() + free_w;
|
|
|
|
o->resize(X, o->y(), W, o->h());
|
|
|
|
X += W + DEFAULT_SPACING;
|
|
|
|
|
|
|
|
it = resizable_h.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::show(void) {
|
|
|
|
if(shown()) {
|
|
|
|
Fl_Window::show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-06 15:20:19 +04:00
|
|
|
/*
|
|
|
|
* hush known FLTK bug with XGetImage; a lot of errors will be print when menu icons goes
|
|
|
|
* outside screen; this also make ede-panel, at some point, unresponsible
|
|
|
|
*/
|
|
|
|
XSetErrorHandler((XErrorHandler) xerror_handler);
|
2012-06-07 13:32:27 +04:00
|
|
|
update_size_and_pos(true, true);
|
|
|
|
|
|
|
|
/* collect messages */
|
|
|
|
Fl::add_handler(x_events);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::hide(void) {
|
|
|
|
Fl::remove_handler(x_events);
|
2012-08-06 18:52:09 +04:00
|
|
|
|
|
|
|
/* strange; this is not called when panel goes out :S */
|
|
|
|
mgr.clear();
|
2012-06-07 13:32:27 +04:00
|
|
|
save_config();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::update_size_and_pos(bool create_xid, bool update_strut) {
|
|
|
|
int X, Y, W, H;
|
2009-10-06 15:20:19 +04:00
|
|
|
|
2012-06-07 13:32:27 +04:00
|
|
|
/* figure out screen dimensions */
|
2009-12-17 18:16:35 +03:00
|
|
|
if(!netwm_workarea_get_size(X, Y, W, H))
|
2009-10-03 11:33:08 +04:00
|
|
|
Fl::screen_xywh(X, Y, W, H);
|
|
|
|
|
2012-06-07 13:32:27 +04:00
|
|
|
update_size_and_pos(create_xid, update_strut, X, Y, W, H);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::update_size_and_pos(bool create_xid, bool update_strut, int X, int Y, int W, int H) {
|
|
|
|
/* do not update ourself if we screen sizes are the same */
|
|
|
|
if(screen_x == X && screen_y == Y && screen_w == W && screen_h == H)
|
|
|
|
return;
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
screen_x = X;
|
|
|
|
screen_y = Y;
|
|
|
|
screen_w = W;
|
|
|
|
screen_h = H;
|
|
|
|
screen_h_half = screen_h / 2;
|
|
|
|
|
2012-04-04 13:58:23 +04:00
|
|
|
/* calculate panel percentage width if given */
|
|
|
|
if(width_perc < 100) {
|
|
|
|
W = (width_perc * screen_w) / 100;
|
2012-04-11 20:15:01 +04:00
|
|
|
X = (screen_w / 2) - (W / 2);
|
2012-04-04 13:58:23 +04:00
|
|
|
}
|
|
|
|
|
2009-11-18 15:24:58 +03:00
|
|
|
/* set size as soon as possible, since do_layout() depends on it */
|
|
|
|
size(W, DEFAULT_PANEL_H);
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
do_layout();
|
2012-06-07 13:32:27 +04:00
|
|
|
|
|
|
|
if(create_xid) window_xid_create(this, make_me_dock);
|
2009-11-18 15:24:58 +03:00
|
|
|
|
|
|
|
/* position it, this is done after XID was created */
|
|
|
|
if(vpos == PANEL_POSITION_BOTTOM) {
|
2012-04-11 20:15:01 +04:00
|
|
|
position(X, screen_h - h());
|
2012-06-07 13:32:27 +04:00
|
|
|
if(width_perc >= 100 && update_strut) {
|
|
|
|
netwm_window_remove_strut(fl_xid(this));
|
2012-04-04 13:58:23 +04:00
|
|
|
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
|
2012-06-07 13:32:27 +04:00
|
|
|
}
|
2009-11-18 15:24:58 +03:00
|
|
|
} else {
|
|
|
|
/* FIXME: this does not work well with edewm (nor pekwm). kwin do it correctly. */
|
2012-04-11 20:15:01 +04:00
|
|
|
position(X, Y);
|
2012-06-07 13:32:27 +04:00
|
|
|
if(width_perc >= 100 && update_strut) {
|
|
|
|
netwm_window_remove_strut(fl_xid(this));
|
2012-04-04 13:58:23 +04:00
|
|
|
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
|
2012-06-07 13:32:27 +04:00
|
|
|
}
|
2009-11-18 15:24:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
int Panel::handle(int e) {
|
|
|
|
switch(e) {
|
|
|
|
case FL_PUSH:
|
|
|
|
clicked = Fl::belowmouse();
|
|
|
|
|
|
|
|
if(clicked == this)
|
|
|
|
clicked = 0;
|
|
|
|
else if(clicked && clicked->takesevents())
|
|
|
|
clicked->handle(e);
|
|
|
|
|
|
|
|
/* record push position for possible child drag */
|
|
|
|
sx = Fl::event_x();
|
|
|
|
sy = Fl::event_y();
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case FL_DRAG: {
|
2012-04-11 20:15:01 +04:00
|
|
|
if(!can_drag) return 1;
|
|
|
|
|
2009-11-18 15:24:58 +03:00
|
|
|
/* are moving the panel; only vertical moving is supported */
|
|
|
|
cursor(FL_CURSOR_MOVE);
|
|
|
|
|
|
|
|
/* snap it to the top or bottom, depending on pressed mouse location */
|
|
|
|
if(Fl::event_y_root() <= screen_h_half && y() > screen_h_half) {
|
2012-04-11 20:15:01 +04:00
|
|
|
position(x(), screen_y);
|
2012-04-04 13:58:23 +04:00
|
|
|
if(width_perc >= 100)
|
|
|
|
netwm_window_set_strut(fl_xid(this), 0, 0, h(), 0);
|
2009-11-18 15:24:58 +03:00
|
|
|
vpos = PANEL_POSITION_TOP;
|
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2009-11-18 15:24:58 +03:00
|
|
|
if(Fl::event_y_root() > screen_h_half && y() < screen_h_half) {
|
2012-04-11 20:15:01 +04:00
|
|
|
position(x(), screen_h - h());
|
2012-04-04 13:58:23 +04:00
|
|
|
if(width_perc >= 100)
|
|
|
|
netwm_window_set_strut(fl_xid(this), 0, 0, 0, h());
|
2009-11-18 15:24:58 +03:00
|
|
|
vpos = PANEL_POSITION_BOTTOM;
|
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case FL_RELEASE:
|
|
|
|
cursor(FL_CURSOR_DEFAULT);
|
|
|
|
|
|
|
|
if(clicked && clicked->takesevents()) {
|
|
|
|
clicked->handle(e);
|
|
|
|
clicked = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2009-10-05 15:50:28 +04:00
|
|
|
|
|
|
|
case FL_KEYBOARD:
|
|
|
|
/* do not quit on Esc key */
|
|
|
|
if(Fl::event_key() == FL_Escape)
|
|
|
|
return 1;
|
|
|
|
/* fallthrough */
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return Fl_Window::handle(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::load_applets(void) {
|
2011-10-27 19:11:11 +04:00
|
|
|
#ifndef EDE_PANEL_LOCAL_APPLETS
|
2009-10-03 11:33:08 +04:00
|
|
|
/* FIXME: hardcoded order */
|
|
|
|
static const char *applets[] = {
|
|
|
|
"start_menu.so",
|
|
|
|
"quick_launch.so",
|
|
|
|
"pager.so",
|
2012-04-11 20:15:01 +04:00
|
|
|
"hider.so",
|
2009-10-03 11:33:08 +04:00
|
|
|
"clock.so",
|
|
|
|
"taskbar.so",
|
2009-10-12 15:25:57 +04:00
|
|
|
"keyboard_layout.so",
|
2009-11-05 18:18:51 +03:00
|
|
|
"cpu_monitor.so",
|
2011-11-10 18:20:58 +04:00
|
|
|
#ifdef __linux__
|
2011-09-30 15:43:05 +04:00
|
|
|
"mem_monitor.so",
|
2011-11-10 18:20:58 +04:00
|
|
|
#endif
|
2011-10-26 20:04:37 +04:00
|
|
|
"system_tray.so",
|
2009-10-03 11:33:08 +04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
String dir = Resource::find_data("panel-applets");
|
|
|
|
if(dir.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
String tmp;
|
|
|
|
for(int i = 0; applets[i]; i++) {
|
|
|
|
tmp = build_filename(dir.c_str(), applets[i]);
|
|
|
|
mgr.load(tmp.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
mgr.fill_group(this);
|
2011-10-27 19:11:11 +04:00
|
|
|
#else
|
2009-10-03 11:33:08 +04:00
|
|
|
mgr.load("./applets/start-menu/start_menu.so");
|
|
|
|
mgr.load("./applets/quick-launch/quick_launch.so");
|
|
|
|
mgr.load("./applets/pager/pager.so");
|
2012-04-11 20:15:01 +04:00
|
|
|
mgr.load("./applets/hider/hider.so");
|
2009-10-03 11:33:08 +04:00
|
|
|
mgr.load("./applets/clock/clock.so");
|
|
|
|
mgr.load("./applets/taskbar/taskbar.so");
|
2009-10-12 15:25:57 +04:00
|
|
|
mgr.load("./applets/keyboard-layout/keyboard_layout.so");
|
2009-11-05 18:18:51 +03:00
|
|
|
mgr.load("./applets/cpu-monitor/cpu_monitor.so");
|
2011-09-30 13:47:20 +04:00
|
|
|
mgr.load("./applets/mem-monitor/mem_monitor.so");
|
2011-10-26 20:04:37 +04:00
|
|
|
mgr.load("./applets/system-tray/system_tray.so");
|
2009-10-03 11:33:08 +04:00
|
|
|
mgr.fill_group(this);
|
2011-10-26 20:19:21 +04:00
|
|
|
#endif
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
2012-04-11 20:15:01 +04:00
|
|
|
|
|
|
|
/* TODO: can be better */
|
|
|
|
void Panel::apply_struts(bool apply) {
|
|
|
|
if(!(width_perc >= 100)) return;
|
|
|
|
|
|
|
|
int bottom = 0, top = 0;
|
|
|
|
|
|
|
|
if(vpos == PANEL_POSITION_TOP)
|
|
|
|
top = !apply ? 1 : h();
|
|
|
|
else
|
|
|
|
bottom = !apply ? 1 : h();
|
|
|
|
|
|
|
|
netwm_window_set_strut(fl_xid(this), 0, 0, top, bottom);
|
|
|
|
}
|