mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Merging new panel in the trunk.
This commit is contained in:
13
ede-panel/applets/pager/Jamfile
Normal file
13
ede-panel/applets/pager/Jamfile
Normal file
@@ -0,0 +1,13 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Part of Equinox Desktop Environment (EDE).
|
||||
# Copyright (c) 2009 EDE Authors.
|
||||
#
|
||||
# This program is licensed under terms of the
|
||||
# GNU General Public License version 2 or newer.
|
||||
# See COPYING for details.
|
||||
|
||||
SubDir TOP ede-panel-new applets pager ;
|
||||
|
||||
PanelApplet pager : Pager.cpp PagerButton.cpp ;
|
||||
125
ede-panel/applets/pager/Pager.cpp
Normal file
125
ede-panel/applets/pager/Pager.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "Applet.h"
|
||||
#include "Netwm.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <FL/Fl_Group.H>
|
||||
#include <FL/Fl.H>
|
||||
#include <edelib/Debug.h>
|
||||
|
||||
#include "PagerButton.h"
|
||||
|
||||
class Pager : public Fl_Group {
|
||||
public:
|
||||
Pager();
|
||||
~Pager();
|
||||
void init_workspace_boxes(void);
|
||||
void workspace_changed(void);
|
||||
};
|
||||
|
||||
static void box_cb(Fl_Widget*, void *b) {
|
||||
PagerButton *pb = (PagerButton*)b;
|
||||
|
||||
/* because workspaces in button labels are increased */
|
||||
int s = pb->get_workspace_label() - 1;
|
||||
netwm_change_workspace(s);
|
||||
}
|
||||
|
||||
static void net_event_cb(int action, Window xid, void *data) {
|
||||
E_RETURN_IF_FAIL(data != NULL);
|
||||
|
||||
if(action == NETWM_CHANGED_CURRENT_WORKSPACE) {
|
||||
Pager *p = (Pager*)data;
|
||||
p->workspace_changed();
|
||||
}
|
||||
}
|
||||
|
||||
Pager::Pager() : Fl_Group(0, 0, 25, 25, NULL) {
|
||||
box(FL_DOWN_BOX);
|
||||
/* we will explicitly add elements */
|
||||
end();
|
||||
|
||||
init_workspace_boxes();
|
||||
netwm_callback_add(net_event_cb, this);
|
||||
}
|
||||
|
||||
Pager::~Pager() {
|
||||
netwm_callback_remove(net_event_cb);
|
||||
}
|
||||
|
||||
void Pager::init_workspace_boxes(void) {
|
||||
int X, Y, H;
|
||||
|
||||
/* prepare the sizes */
|
||||
X = x() + Fl::box_dx(box());
|
||||
Y = y() + Fl::box_dy(box());
|
||||
H = h() - Fl::box_dh(box());
|
||||
|
||||
int nworkspaces, curr_workspace;
|
||||
char **names = 0;
|
||||
char nbuf[16];
|
||||
|
||||
nworkspaces = netwm_get_workspace_count();
|
||||
curr_workspace = netwm_get_current_workspace();
|
||||
netwm_get_workspace_names(names);
|
||||
|
||||
/*
|
||||
* Resize group before childs, or they will be resized too, messing things up.
|
||||
* Here, each child is 25px wide plus 1px for delimiter between the childs .
|
||||
*/
|
||||
int gw = nworkspaces * (25 + 1);
|
||||
gw += Fl::box_dw(box());
|
||||
/* last child do not ends with 1px wide delimiter */
|
||||
gw -= 1;
|
||||
|
||||
size(gw, h());
|
||||
|
||||
for(int i = 0; i < nworkspaces; i++) {
|
||||
/* let box width be fixed */
|
||||
PagerButton *bx = new PagerButton(X, Y, 25, H);
|
||||
bx->box(FL_FLAT_BOX);
|
||||
|
||||
if(i == curr_workspace)
|
||||
bx->select_it(1);
|
||||
else
|
||||
bx->select_it(0);
|
||||
|
||||
/* workspaces are started from 0 */
|
||||
bx->set_workspace_label(i + 1);
|
||||
|
||||
if(names)
|
||||
bx->copy_tooltip(names[i]);
|
||||
|
||||
bx->callback(box_cb, bx);
|
||||
|
||||
add(bx);
|
||||
/* position for the next box */
|
||||
X = bx->x() + bx->w() + 1;
|
||||
}
|
||||
|
||||
XFreeStringList(names);
|
||||
}
|
||||
|
||||
void Pager::workspace_changed(void) {
|
||||
int c = netwm_get_current_workspace();
|
||||
PagerButton *pb;
|
||||
|
||||
E_RETURN_IF_FAIL(c < children());
|
||||
|
||||
for(int i = 0; i < children(); i++) {
|
||||
pb = (PagerButton*)child(i);
|
||||
pb->select_it(0);
|
||||
}
|
||||
|
||||
pb = (PagerButton*)child(c);
|
||||
pb->select_it(1);
|
||||
}
|
||||
|
||||
EDE_PANEL_APPLET_EXPORT (
|
||||
Pager,
|
||||
EDE_PANEL_APPLET_OPTION_ALIGN_LEFT,
|
||||
"Desktop switcher",
|
||||
"0.1",
|
||||
"empty",
|
||||
"Sanel Zukan"
|
||||
)
|
||||
40
ede-panel/applets/pager/PagerButton.cpp
Normal file
40
ede-panel/applets/pager/PagerButton.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <edelib/Debug.h>
|
||||
#include "PagerButton.h"
|
||||
|
||||
PagerButton::~PagerButton() {
|
||||
if(ttip)
|
||||
free(ttip);
|
||||
}
|
||||
|
||||
void PagerButton::set_workspace_label(int l) {
|
||||
wlabel = l;
|
||||
|
||||
char buf[16];
|
||||
snprintf(buf, sizeof(buf), "%i", l);
|
||||
copy_label(buf);
|
||||
}
|
||||
|
||||
void PagerButton::copy_tooltip(const char *t) {
|
||||
E_RETURN_IF_FAIL(t != NULL);
|
||||
|
||||
if(ttip)
|
||||
free(ttip);
|
||||
|
||||
ttip = strdup(t);
|
||||
tooltip(ttip);
|
||||
}
|
||||
|
||||
void PagerButton::select_it(int i) {
|
||||
if(i) {
|
||||
color((Fl_Color)44);
|
||||
labelcolor(FL_BLACK);
|
||||
} else {
|
||||
color((Fl_Color)33);
|
||||
labelcolor(FL_GRAY);
|
||||
}
|
||||
|
||||
redraw();
|
||||
}
|
||||
22
ede-panel/applets/pager/PagerButton.h
Normal file
22
ede-panel/applets/pager/PagerButton.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef __PAGERBUTTON_H__
|
||||
#define __PAGERBUTTON_H__
|
||||
|
||||
#include <FL/Fl_Button.H>
|
||||
|
||||
class PagerButton : public Fl_Button {
|
||||
private:
|
||||
char *ttip;
|
||||
int wlabel;
|
||||
public:
|
||||
PagerButton(int X, int Y, int W, int H, const char *l = 0) : Fl_Button(X, Y, W, H), ttip(NULL), wlabel(0)
|
||||
{ }
|
||||
~PagerButton();
|
||||
|
||||
void set_workspace_label(int l);
|
||||
int get_workspace_label(void) { return wlabel; }
|
||||
|
||||
void copy_tooltip(const char *t);
|
||||
void select_it(int i);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user