2012-08-06 16:00:25 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2013-01-18 02:49:49 +04:00
|
|
|
* Copyright (C) 2012-2013 Sanel Zukan
|
2012-08-06 16:00:25 +04:00
|
|
|
*
|
|
|
|
* 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-03 11:33:08 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <edelib/Debug.h>
|
2009-12-17 18:16:35 +03:00
|
|
|
#include <edelib/Netwm.h>
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
#include "TaskButton.h"
|
|
|
|
#include "Taskbar.h"
|
|
|
|
|
|
|
|
#define DEFAULT_CHILD_W 175
|
|
|
|
#define DEFAULT_SPACING 5
|
|
|
|
|
2009-12-17 18:16:35 +03:00
|
|
|
EDELIB_NS_USING(netwm_callback_add)
|
|
|
|
EDELIB_NS_USING(netwm_callback_remove)
|
|
|
|
EDELIB_NS_USING(netwm_window_get_all_mapped)
|
|
|
|
EDELIB_NS_USING(netwm_window_is_manageable)
|
|
|
|
EDELIB_NS_USING(netwm_window_get_workspace)
|
|
|
|
EDELIB_NS_USING(netwm_window_get_active)
|
|
|
|
EDELIB_NS_USING(netwm_window_set_active)
|
2012-12-17 19:49:33 +04:00
|
|
|
EDELIB_NS_USING(netwm_window_set_state)
|
2009-12-17 18:16:35 +03:00
|
|
|
EDELIB_NS_USING(netwm_workspace_get_current)
|
|
|
|
EDELIB_NS_USING(wm_window_set_state)
|
|
|
|
EDELIB_NS_USING(wm_window_get_state)
|
|
|
|
EDELIB_NS_USING(NETWM_CHANGED_ACTIVE_WINDOW)
|
|
|
|
EDELIB_NS_USING(NETWM_CHANGED_CURRENT_WORKSPACE)
|
|
|
|
EDELIB_NS_USING(NETWM_CHANGED_WINDOW_LIST)
|
|
|
|
EDELIB_NS_USING(NETWM_CHANGED_WINDOW_NAME)
|
2010-03-10 02:38:57 +03:00
|
|
|
EDELIB_NS_USING(NETWM_CHANGED_WINDOW_ICON)
|
2013-01-04 17:05:42 +04:00
|
|
|
EDELIB_NS_USING(NETWM_CHANGED_WINDOW_DESKTOP)
|
2009-12-17 18:16:35 +03:00
|
|
|
EDELIB_NS_USING(WM_WINDOW_STATE_ICONIC)
|
2012-12-17 19:49:33 +04:00
|
|
|
EDELIB_NS_USING(NETWM_STATE_ACTION_TOGGLE)
|
|
|
|
EDELIB_NS_USING(NETWM_STATE_HIDDEN)
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
static void button_cb(TaskButton *b, void *t) {
|
|
|
|
Taskbar *tt = (Taskbar*)t;
|
|
|
|
|
|
|
|
if(Fl::event_button() == FL_RIGHT_MOUSE)
|
|
|
|
b->display_menu();
|
|
|
|
else
|
|
|
|
tt->activate_window(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void net_event_cb(int action, Window xid, void *data) {
|
|
|
|
E_RETURN_IF_FAIL(data != NULL);
|
2013-01-04 17:05:42 +04:00
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
/* this is a message, so property is not changed and netwm_window_get_active() must be called */
|
|
|
|
if(action == NETWM_CHANGED_ACTIVE_WINDOW) {
|
2009-10-03 11:33:08 +04:00
|
|
|
Taskbar *tt = (Taskbar*)data;
|
2012-12-17 19:49:33 +04:00
|
|
|
tt->update_active_button();
|
2009-10-03 11:33:08 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-12-20 04:58:30 +04:00
|
|
|
|
|
|
|
if(action == NETWM_CHANGED_CURRENT_WORKSPACE) {
|
|
|
|
Taskbar *tt = (Taskbar*)data;
|
|
|
|
tt->update_workspace_change();
|
|
|
|
return;
|
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
if(action == NETWM_CHANGED_WINDOW_LIST) {
|
2009-10-03 11:33:08 +04:00
|
|
|
Taskbar *tt = (Taskbar*)data;
|
2012-12-17 19:49:33 +04:00
|
|
|
tt->update_task_buttons();
|
2009-10-03 11:33:08 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
if(action == NETWM_CHANGED_WINDOW_NAME) {
|
2009-10-03 11:33:08 +04:00
|
|
|
Taskbar *tt = (Taskbar*)data;
|
2012-12-17 19:49:33 +04:00
|
|
|
tt->update_child_title(xid);
|
2009-10-03 11:33:08 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-03-10 02:38:57 +03:00
|
|
|
|
|
|
|
if(action == NETWM_CHANGED_WINDOW_ICON) {
|
|
|
|
Taskbar *tt = (Taskbar*)data;
|
|
|
|
tt->update_child_icon(xid);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-04 17:05:42 +04:00
|
|
|
|
|
|
|
if(action == NETWM_CHANGED_WINDOW_DESKTOP) {
|
|
|
|
Taskbar *tt = (Taskbar*)data;
|
|
|
|
tt->update_child_workspace(xid);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
Taskbar::Taskbar() : Fl_Group(0, 0, 40, 25), curr_active(NULL), prev_active(NULL) {
|
2009-10-03 11:33:08 +04:00
|
|
|
end();
|
2013-01-04 17:05:42 +04:00
|
|
|
|
2013-01-04 18:36:40 +04:00
|
|
|
//box(FL_FLAT_BOX);
|
|
|
|
//color(FL_RED);
|
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
fixed_layout = false;
|
2013-01-04 17:05:42 +04:00
|
|
|
ignore_workspace_value = false;
|
|
|
|
|
|
|
|
current_workspace = netwm_workspace_get_current();
|
2012-12-20 04:58:30 +04:00
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
update_task_buttons();
|
2009-10-03 11:33:08 +04:00
|
|
|
netwm_callback_add(net_event_cb, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Taskbar::~Taskbar() {
|
|
|
|
netwm_callback_remove(net_event_cb);
|
|
|
|
}
|
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
void Taskbar::update_task_buttons(void) {
|
|
|
|
Window *wins;
|
2013-01-04 17:05:42 +04:00
|
|
|
int ws, nwins = netwm_window_get_all_mapped(&wins);
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
if(nwins < 1) {
|
|
|
|
if(children() > 0) clear();
|
|
|
|
return;
|
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
TaskButton *b;
|
|
|
|
bool need_full_redraw = false;
|
|
|
|
|
|
|
|
for(int i = 0, found; i < children(); i++) {
|
|
|
|
found = 0;
|
|
|
|
b = (TaskButton*)child(i);
|
|
|
|
|
|
|
|
for(int j = 0; j < nwins; j++) {
|
|
|
|
if(b->get_window_xid() == wins[j]) {
|
2013-01-04 14:33:53 +04:00
|
|
|
/* assure this window is on current workspace */
|
2012-12-17 19:49:33 +04:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
if(!found) {
|
2013-01-04 14:33:53 +04:00
|
|
|
/* FLTK since 1.3 optimized Fl_Group::remove() */
|
|
|
|
#if (FL_MAJOR_VERSION >= 1) && (FL_MINOR_VERSION >= 3)
|
|
|
|
remove(i);
|
|
|
|
#else
|
2012-12-17 19:49:33 +04:00
|
|
|
remove(b);
|
2013-01-04 14:33:53 +04:00
|
|
|
#endif
|
2012-12-17 19:49:33 +04:00
|
|
|
/* Fl_Group does not call delete on remove() */
|
|
|
|
delete b;
|
|
|
|
need_full_redraw = true;
|
|
|
|
}
|
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2013-01-04 14:33:53 +04:00
|
|
|
/* now see which one needs to be created */
|
2012-12-17 19:49:33 +04:00
|
|
|
for(int i = 0, found; i < nwins; i++) {
|
|
|
|
found = 0;
|
2010-01-06 17:45:56 +03:00
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
for(int j = 0; j < children(); j++) {
|
|
|
|
b = (TaskButton*)child(j);
|
2010-01-06 17:45:56 +03:00
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
if(b->get_window_xid() == wins[i]) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
if(found || !netwm_window_is_manageable(wins[i]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Window transient_prop_win = None;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if it has WM_TRANSIENT_FOR hint set; transient_prop_win would point to parent window, but
|
|
|
|
* parent should not be root window for this screen
|
|
|
|
*/
|
|
|
|
if(XGetTransientForHint(fl_display, wins[i], &transient_prop_win)
|
|
|
|
&& (transient_prop_win != None)
|
|
|
|
&& (transient_prop_win != RootWindow(fl_display, fl_screen)))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
/* create button */
|
2013-01-04 17:05:42 +04:00
|
|
|
ws = netwm_window_get_workspace(wins[i]);
|
|
|
|
if(visible_on_current_workspace(ws)) {
|
2012-12-17 19:49:33 +04:00
|
|
|
b = new TaskButton(0, 0, DEFAULT_CHILD_W, 25);
|
|
|
|
b->set_window_xid(wins[i]);
|
|
|
|
b->update_title_from_xid();
|
|
|
|
b->update_image_from_xid();
|
2013-01-04 17:05:42 +04:00
|
|
|
b->set_workspace(ws);
|
2012-12-17 19:49:33 +04:00
|
|
|
|
|
|
|
/* catch the name changes */
|
|
|
|
XSelectInput(fl_display, wins[i], PropertyChangeMask | StructureNotifyMask);
|
|
|
|
b->callback((Fl_Callback*)button_cb, this);
|
|
|
|
add(b);
|
2012-12-20 05:50:00 +04:00
|
|
|
|
|
|
|
need_full_redraw = true;
|
2012-12-17 19:49:33 +04:00
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
XFree(wins);
|
2009-10-03 11:33:08 +04:00
|
|
|
layout_children();
|
2012-12-17 19:49:33 +04:00
|
|
|
update_active_button(!need_full_redraw);
|
|
|
|
|
|
|
|
if(need_full_redraw) panel_redraw();
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
void Taskbar::update_workspace_change(void) {
|
|
|
|
if(children() < 1) return;
|
2013-01-04 17:05:42 +04:00
|
|
|
current_workspace = netwm_workspace_get_current();
|
2012-12-20 04:58:30 +04:00
|
|
|
|
|
|
|
TaskButton *b;
|
|
|
|
for(int i = 0; i < children(); i++) {
|
|
|
|
b = (TaskButton*)child(i);
|
2013-01-04 17:05:42 +04:00
|
|
|
visible_on_current_workspace(b->get_workspace()) ? b->show() : b->hide();
|
2012-12-20 04:58:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
layout_children();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
void Taskbar::resize(int X, int Y, int W, int H) {
|
|
|
|
Fl_Widget::resize(X, Y, W, H);
|
|
|
|
layout_children();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Taskbar::layout_children(void) {
|
2013-01-04 18:36:40 +04:00
|
|
|
if(!children()) return;
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
Fl_Widget *o;
|
2013-01-18 03:53:11 +04:00
|
|
|
int X, Y, W, child_h, reduce = 0, sz = 0, all_buttons_w = 0;
|
2012-12-20 04:58:30 +04:00
|
|
|
|
|
|
|
X = x() + Fl::box_dx(box());
|
|
|
|
Y = y() + Fl::box_dy(box());
|
|
|
|
W = w() - Fl::box_dw(box());
|
2013-01-18 03:53:11 +04:00
|
|
|
child_h = parent()->h() - 10; /* same sizes as in panel */
|
2012-12-20 04:58:30 +04:00
|
|
|
|
|
|
|
for(int i = 0; i < children(); i++) {
|
|
|
|
o = child(i);
|
|
|
|
if(!o->visible()) continue;
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
sz++;
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
/* resize every child to default size so we can calculate total length */
|
2013-01-18 03:53:11 +04:00
|
|
|
o->resize(o->x(), o->y(), (fixed_layout ? DEFAULT_CHILD_W : W), child_h);
|
2012-12-20 04:58:30 +04:00
|
|
|
all_buttons_w += o->w();
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
/* do not include ending spaces */
|
|
|
|
if(i != children() - 1)
|
|
|
|
all_buttons_w += DEFAULT_SPACING;
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
2013-01-04 18:36:40 +04:00
|
|
|
/* find reduction size */
|
2012-12-20 04:58:30 +04:00
|
|
|
if(all_buttons_w > W)
|
|
|
|
reduce = (all_buttons_w - W) / sz;
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
/* now, position each child and resize it if needed */
|
2012-12-20 04:58:30 +04:00
|
|
|
for(int i = 0; i < children(); i++) {
|
2009-10-03 11:33:08 +04:00
|
|
|
o = child(i);
|
2012-12-20 04:58:30 +04:00
|
|
|
if(!o->visible()) continue;
|
|
|
|
|
2013-01-04 18:36:40 +04:00
|
|
|
/*
|
|
|
|
* I'm putting -1 here to leave a small space at the end of group; this will also
|
|
|
|
* make children adaptive to not overflow group in case too many of them was created
|
|
|
|
*/
|
2013-01-18 03:53:11 +04:00
|
|
|
o->resize(X, Y, o->w() - reduce - 1, child_h);
|
2013-01-04 18:36:40 +04:00
|
|
|
X += o->w() + DEFAULT_SPACING;
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
void Taskbar::update_active_button(bool do_redraw, int xid) {
|
2009-10-03 11:33:08 +04:00
|
|
|
if(!children())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(xid == -1) {
|
2009-12-17 18:16:35 +03:00
|
|
|
xid = netwm_window_get_active();
|
2009-10-03 11:33:08 +04:00
|
|
|
/* TODO: make sure panel does not get 'active', or all buttons will be FL_UP_BOX */
|
|
|
|
}
|
|
|
|
|
|
|
|
TaskButton *o;
|
|
|
|
for(int i = 0; i < children(); i++) {
|
|
|
|
o = (TaskButton*)child(i);
|
2012-12-20 04:58:30 +04:00
|
|
|
if(!o->visible()) continue;
|
2009-10-03 11:33:08 +04:00
|
|
|
|
2013-01-04 14:33:53 +04:00
|
|
|
if(o->get_window_xid() == (Window)xid) {
|
2009-10-03 11:33:08 +04:00
|
|
|
o->box(FL_DOWN_BOX);
|
2013-01-04 14:33:53 +04:00
|
|
|
curr_active = o;
|
|
|
|
} else {
|
2009-10-03 11:33:08 +04:00
|
|
|
o->box(FL_UP_BOX);
|
2013-01-04 14:33:53 +04:00
|
|
|
}
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
2012-12-17 19:49:33 +04:00
|
|
|
if(do_redraw) redraw();
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Taskbar::activate_window(TaskButton *b) {
|
|
|
|
E_RETURN_IF_FAIL(b != NULL);
|
|
|
|
|
|
|
|
Window xid = b->get_window_xid();
|
|
|
|
|
|
|
|
/* if clicked on activated button, it will be minimized, then next one will be activated */
|
|
|
|
if(b == curr_active) {
|
2009-12-17 18:16:35 +03:00
|
|
|
if(wm_window_get_state(xid) != WM_WINDOW_STATE_ICONIC) {
|
2009-10-03 11:33:08 +04:00
|
|
|
/* minimize if not so */
|
2009-12-17 18:16:35 +03:00
|
|
|
wm_window_set_state(xid, WM_WINDOW_STATE_ICONIC);
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
if(prev_active &&
|
|
|
|
prev_active != b &&
|
2013-01-18 02:49:49 +04:00
|
|
|
prev_active->get_workspace() == b->get_workspace() &&
|
2009-12-17 18:16:35 +03:00
|
|
|
wm_window_get_state(prev_active->get_window_xid()) != WM_WINDOW_STATE_ICONIC)
|
2009-10-03 11:33:08 +04:00
|
|
|
{
|
|
|
|
xid = prev_active->get_window_xid();
|
|
|
|
b = prev_active;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* active or restore minimized */
|
2012-12-17 19:49:33 +04:00
|
|
|
netwm_window_set_active(xid, 1);
|
2012-12-18 02:26:55 +04:00
|
|
|
update_active_button(false, xid);
|
2009-10-03 11:33:08 +04:00
|
|
|
|
|
|
|
prev_active = curr_active;
|
|
|
|
curr_active = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Taskbar::update_child_title(Window xid) {
|
|
|
|
E_RETURN_IF_FAIL(xid >= 0);
|
|
|
|
|
|
|
|
TaskButton *o;
|
|
|
|
for(int i = 0; i < children(); i++) {
|
|
|
|
o = (TaskButton*)child(i);
|
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
if(o->visible() && o->get_window_xid() == xid) {
|
2009-10-03 11:33:08 +04:00
|
|
|
o->update_title_from_xid();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-10 02:38:57 +03:00
|
|
|
void Taskbar::update_child_icon(Window xid) {
|
|
|
|
E_RETURN_IF_FAIL(xid >= 0);
|
|
|
|
|
|
|
|
TaskButton *o;
|
|
|
|
for(int i = 0; i < children(); i++) {
|
|
|
|
o = (TaskButton*)child(i);
|
|
|
|
|
2012-12-20 04:58:30 +04:00
|
|
|
if(o->visible() && o->get_window_xid() == xid) {
|
2010-03-10 02:38:57 +03:00
|
|
|
o->update_image_from_xid();
|
|
|
|
o->redraw();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 17:05:42 +04:00
|
|
|
void Taskbar::update_child_workspace(Window xid) {
|
|
|
|
if(children() < 0) return;
|
|
|
|
|
|
|
|
TaskButton *o;
|
|
|
|
for(int i = 0; i < children(); i++) {
|
|
|
|
o = (TaskButton*)child(i);
|
|
|
|
|
|
|
|
if(o->get_window_xid() == xid) {
|
|
|
|
int ws = netwm_window_get_workspace(xid);
|
|
|
|
o->set_workspace(ws);
|
|
|
|
visible_on_current_workspace(ws) ? o->show() : o->hide();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layout_children();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2009-10-03 11:33:08 +04:00
|
|
|
void Taskbar::panel_redraw(void) {
|
2012-12-17 19:49:33 +04:00
|
|
|
parent()->redraw();
|
2009-10-03 11:33:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
EDE_PANEL_APPLET_EXPORT (
|
|
|
|
Taskbar,
|
|
|
|
EDE_PANEL_APPLET_OPTION_ALIGN_LEFT | EDE_PANEL_APPLET_OPTION_RESIZABLE_H,
|
|
|
|
"Taskbar",
|
|
|
|
"0.1",
|
|
|
|
"empty",
|
|
|
|
"Sanel Zukan"
|
|
|
|
)
|