TaskApplet::TaskApplet(AppletInfo* info, QWidget* parent): Applet(info, parent), layout_(new QBoxLayout(QBoxLayout::LeftToRight)), buttonGroup_(new QButtonGroup()), widget_(new QWidget(parent)) { layout_->setContentsMargins(0, 0, 0, 0); layout_->setMargin(0); layout_->setSpacing(1); layout_->addStretch(1); widget_->setLayout(layout_); Window active = xfitMan().getActiveWindow(); QList<TaskInfo*> tasks = taskManager_.tasks(); Q_FOREACH(TaskInfo* task, tasks) { if(task->showInTaskbar()) { TaskButton* button = addButton(task); if(task->window() == active) button->setChecked(true); } } connect(&taskManager_, SIGNAL(taskAdded(TaskInfo*)), SLOT(onTaskAdded(TaskInfo*))); connect(&taskManager_, SIGNAL(taskRemoved(TaskInfo*)), SLOT(onTaskRemoved(TaskInfo*))); connect(&taskManager_, SIGNAL(taskChanged(TaskInfo*,TaskInfo::ChangeType)), SLOT(onTaskChanged(TaskInfo*,TaskInfo::ChangeType))); connect(&taskManager_, SIGNAL(activeChanged(TaskInfo*)), SLOT(onActiveChanged(TaskInfo*))); connect(buttonGroup_, SIGNAL(buttonClicked(QAbstractButton*)), SLOT(onButtonClicked(QAbstractButton*))); }
static void maximize_cb(Fl_Widget*, void *b) { TaskButton *bb = (TaskButton*)b; netwm_window_set_active(bb->get_window_xid(), 1); netwm_window_set_state(bb->get_window_xid(), NETWM_STATE_MAXIMIZED, NETWM_STATE_ACTION_TOGGLE); redraw_whole_panel(bb); }
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); if(o->get_window_xid() == xid) { o->update_title_from_xid(); break; } } }
void Taskbar::create_task_buttons(void) { /* erase all current elements */ if(children()) clear(); /* also current/prev storage */ curr_active = prev_active = NULL; /* redraw it, in case no windows exists in this workspace */ panel_redraw(); Window *wins; int nwins = netwm_get_mapped_windows(&wins); if(nwins > 0) { TaskButton *b; int curr_workspace = netwm_get_current_workspace(); char *title; for(int i = 0; i < nwins; i++) { if(!netwm_manageable_window(wins[i])) continue; /* * show window per workspace * TODO: allow showing all windows in each workspace */ if(curr_workspace == netwm_get_window_workspace(wins[i])) { b = new TaskButton(0, 0, DEFAULT_CHILD_W, 25); b->set_window_xid(wins[i]); b->update_title_from_xid(); /* * catch the name changes * TODO: put this in Netwm.{h,cpp} */ XSelectInput(fl_display, wins[i], PropertyChangeMask | StructureNotifyMask); b->callback((Fl_Callback*)button_cb, this); add(b); } } XFree(wins); } layout_children(); update_active_button(); }
void Taskbar::update_active_button(int xid) { if(!children()) return; if(xid == -1) { xid = netwm_get_active_window(); /* 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); if(o->get_window_xid() == xid) o->box(FL_DOWN_BOX); else o->box(FL_UP_BOX); } redraw(); }
static void minimize_cb(Fl_Widget*, void *b) { TaskButton *bb = (TaskButton*)b; /* WM_WINDOW_STATE_ICONIC is safer on other window managers than NETWM_STATE_HIDDEN */ wm_window_set_state(bb->get_window_xid(), WM_WINDOW_STATE_ICONIC); }
static void restore_cb(Fl_Widget*, void *b) { TaskButton *bb = (TaskButton*)b; netwm_window_set_active(bb->get_window_xid(), 1); redraw_whole_panel(bb); }
static void close_cb(Fl_Widget*, void *b) { TaskButton *bb = (TaskButton*)b; netwm_window_close(bb->get_window_xid()); /* no need to redraw whole panel since taskbar elements are recreated again */ }
void TaskBar::add_new_task(Window w) { // Add to Fl_WM module handled windows. Fl_WM::handle_window(w); TaskButton *b; char *name = 0; Fl_Image *icon = 0; if (!w) return; begin(); b = new TaskButton(w); bool ret = Fl_WM::get_window_icontitle(w, name); if(!ret || !name) ret = Fl_WM::get_window_title(w, name); if(ret && name) { b->label(name); b->tooltip(name); free(name); } else { b->label("..."); b->tooltip("..."); } if(Fl_WM::get_window_icon(w, icon, 16, 16)) { b->image(icon); } else { b->image(default_icon); } b->accept_focus(false); b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); if(Fl_WM::get_active_window()==w) { b->value(1); active = w; } if(GetState(w) == IconicState) b->label_color(fl_inactive(FL_BLACK)); end(); }