mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Implementing #213 (Make taskbar buttons stretchable).
Taskbar buttons now can be stretchable or fixed size as before. This commit also fixes a couple of drawing issues when workspace was changed.
This commit is contained in:
parent
a3f2a79d5f
commit
8bb9028df3
@ -67,8 +67,14 @@ static void net_event_cb(int action, Window xid, void *data) {
|
|||||||
tt->update_active_button();
|
tt->update_active_button();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(action == NETWM_CHANGED_CURRENT_WORKSPACE) {
|
||||||
|
Taskbar *tt = (Taskbar*)data;
|
||||||
|
tt->update_workspace_change();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(action == NETWM_CHANGED_CURRENT_WORKSPACE || action == NETWM_CHANGED_WINDOW_LIST) {
|
if(action == NETWM_CHANGED_WINDOW_LIST) {
|
||||||
Taskbar *tt = (Taskbar*)data;
|
Taskbar *tt = (Taskbar*)data;
|
||||||
tt->update_task_buttons();
|
tt->update_task_buttons();
|
||||||
return;
|
return;
|
||||||
@ -89,6 +95,10 @@ static void net_event_cb(int action, Window xid, void *data) {
|
|||||||
|
|
||||||
Taskbar::Taskbar() : Fl_Group(0, 0, 40, 25), curr_active(NULL), prev_active(NULL) {
|
Taskbar::Taskbar() : Fl_Group(0, 0, 40, 25), curr_active(NULL), prev_active(NULL) {
|
||||||
end();
|
end();
|
||||||
|
fixed_layout = false;
|
||||||
|
|
||||||
|
//box(FL_FLAT_BOX);
|
||||||
|
//color(FL_RED);
|
||||||
|
|
||||||
update_task_buttons();
|
update_task_buttons();
|
||||||
netwm_callback_add(net_event_cb, this);
|
netwm_callback_add(net_event_cb, this);
|
||||||
@ -165,7 +175,7 @@ void Taskbar::update_task_buttons(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: allow showing all windows in each workspace */
|
/* create button */
|
||||||
if(curr_workspace == netwm_window_get_workspace(wins[i])) {
|
if(curr_workspace == netwm_window_get_workspace(wins[i])) {
|
||||||
b = new TaskButton(0, 0, DEFAULT_CHILD_W, 25);
|
b = new TaskButton(0, 0, DEFAULT_CHILD_W, 25);
|
||||||
b->set_window_xid(wins[i]);
|
b->set_window_xid(wins[i]);
|
||||||
@ -186,6 +196,26 @@ void Taskbar::update_task_buttons(void) {
|
|||||||
if(need_full_redraw) panel_redraw();
|
if(need_full_redraw) panel_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Taskbar::update_workspace_change(void) {
|
||||||
|
if(children() < 1) return;
|
||||||
|
|
||||||
|
TaskButton *b;
|
||||||
|
int p, curr_workspace = netwm_workspace_get_current();
|
||||||
|
|
||||||
|
for(int i = 0; i < children(); i++) {
|
||||||
|
b = (TaskButton*)child(i);
|
||||||
|
/*
|
||||||
|
* get fresh value, as wm can change it without notification
|
||||||
|
* (e.g. pekwm window drag to different workspace)
|
||||||
|
*/
|
||||||
|
p = netwm_window_get_workspace(b->get_window_xid());
|
||||||
|
(p == curr_workspace) ? b->show() : b->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
layout_children();
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
void Taskbar::resize(int X, int Y, int W, int H) {
|
void Taskbar::resize(int X, int Y, int W, int H) {
|
||||||
Fl_Widget::resize(X, Y, W, H);
|
Fl_Widget::resize(X, Y, W, H);
|
||||||
layout_children();
|
layout_children();
|
||||||
@ -196,29 +226,45 @@ void Taskbar::layout_children(void) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Fl_Widget *o;
|
Fl_Widget *o;
|
||||||
int X = x() + Fl::box_dx(box());
|
int X, Y, W, reduce = 0, sz = 0, all_buttons_w = 0;
|
||||||
int Y = y() + Fl::box_dy(box());
|
|
||||||
int W = w() - Fl::box_dw(box());
|
|
||||||
|
|
||||||
int child_w = DEFAULT_CHILD_W;
|
X = x() + Fl::box_dx(box());
|
||||||
int sz = children();
|
Y = y() + Fl::box_dy(box());
|
||||||
int all_buttons_w = 0;
|
W = w() - Fl::box_dw(box());
|
||||||
|
|
||||||
/* figure out the bounds */
|
for(int i = 0; i < children(); i++) {
|
||||||
for(int i = 0; i < sz; i++)
|
o = child(i);
|
||||||
all_buttons_w += child(i)->w() + DEFAULT_SPACING;
|
if(!o->visible()) continue;
|
||||||
|
|
||||||
if(all_buttons_w > W) {
|
sz++;
|
||||||
int reduce = (all_buttons_w - W) / sz;
|
|
||||||
child_w -= reduce;
|
/* resize every child to default size so we can calculate total length */
|
||||||
|
o->resize(o->x(), o->y(), (fixed_layout ? DEFAULT_CHILD_W : W), o->h());
|
||||||
|
all_buttons_w += o->w();
|
||||||
|
|
||||||
|
/* do not include ending spaces */
|
||||||
|
if(i != children() - 1)
|
||||||
|
all_buttons_w += DEFAULT_SPACING;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now, position each child and resize it if needed */
|
/*
|
||||||
for(int i = 0; i < sz; i++) {
|
* find reduction size
|
||||||
o = child(i);
|
* TODO: due large number of childs, 'reduce' could be bigger than child
|
||||||
|
* width, yielding drawing issues on borders
|
||||||
|
*/
|
||||||
|
if(all_buttons_w > W)
|
||||||
|
reduce = (all_buttons_w - W) / sz;
|
||||||
|
|
||||||
o->resize(X, Y, child_w, o->h());
|
/* now, position each child and resize it if needed */
|
||||||
X += o->w() + DEFAULT_SPACING;
|
for(int i = 0; i < children(); i++) {
|
||||||
|
o = child(i);
|
||||||
|
if(!o->visible()) continue;
|
||||||
|
|
||||||
|
o->resize(X, Y, o->w() - reduce, o->h());
|
||||||
|
X += o->w();
|
||||||
|
|
||||||
|
if(i != children() - 1)
|
||||||
|
X += DEFAULT_SPACING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +280,7 @@ void Taskbar::update_active_button(bool do_redraw, int xid) {
|
|||||||
TaskButton *o;
|
TaskButton *o;
|
||||||
for(int i = 0; i < children(); i++) {
|
for(int i = 0; i < children(); i++) {
|
||||||
o = (TaskButton*)child(i);
|
o = (TaskButton*)child(i);
|
||||||
|
if(!o->visible()) continue;
|
||||||
|
|
||||||
if(o->get_window_xid() == (Window)xid)
|
if(o->get_window_xid() == (Window)xid)
|
||||||
o->box(FL_DOWN_BOX);
|
o->box(FL_DOWN_BOX);
|
||||||
@ -282,7 +329,7 @@ void Taskbar::update_child_title(Window xid) {
|
|||||||
for(int i = 0; i < children(); i++) {
|
for(int i = 0; i < children(); i++) {
|
||||||
o = (TaskButton*)child(i);
|
o = (TaskButton*)child(i);
|
||||||
|
|
||||||
if(o->get_window_xid() == xid) {
|
if(o->visible() && o->get_window_xid() == xid) {
|
||||||
o->update_title_from_xid();
|
o->update_title_from_xid();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -296,7 +343,7 @@ void Taskbar::update_child_icon(Window xid) {
|
|||||||
for(int i = 0; i < children(); i++) {
|
for(int i = 0; i < children(); i++) {
|
||||||
o = (TaskButton*)child(i);
|
o = (TaskButton*)child(i);
|
||||||
|
|
||||||
if(o->get_window_xid() == xid) {
|
if(o->visible() && o->get_window_xid() == xid) {
|
||||||
o->update_image_from_xid();
|
o->update_image_from_xid();
|
||||||
o->redraw();
|
o->redraw();
|
||||||
break;
|
break;
|
||||||
|
@ -29,11 +29,13 @@ class TaskButton;
|
|||||||
class Taskbar : public Fl_Group {
|
class Taskbar : public Fl_Group {
|
||||||
public:
|
public:
|
||||||
TaskButton *curr_active, *prev_active;
|
TaskButton *curr_active, *prev_active;
|
||||||
|
bool fixed_layout; /* fixed or streched layout of buttons */
|
||||||
public:
|
public:
|
||||||
Taskbar();
|
Taskbar();
|
||||||
~Taskbar();
|
~Taskbar();
|
||||||
|
|
||||||
void update_task_buttons(void);
|
void update_task_buttons(void);
|
||||||
|
void update_workspace_change(void);
|
||||||
|
|
||||||
void resize(int X, int Y, int W, int H);
|
void resize(int X, int Y, int W, int H);
|
||||||
void layout_children(void);
|
void layout_children(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user