From bafdb44a106d685a9e55b34855be3b0ffa2e3a7b Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Wed, 18 Nov 2009 12:24:58 +0000 Subject: [PATCH] Let ede-launch use xterm if TERM was inherited from login console. Dumping usage of FL_SHOW event in ede-panel; everything is now handled in Panel::show(). Call Panel::hide() even if ede-panel was ended/killed with outside signal; with this configuration file will be stored. Remember panel position (top/bottom). --- ede-launch/ede-launch.cpp | 4 +- ede-panel/Panel.cpp | 98 +++++++++++++++++++++++++-------------- ede-panel/Panel.h | 15 ++++-- ede-panel/ede-panel.cpp | 22 ++++++++- 4 files changed, 97 insertions(+), 42 deletions(-) diff --git a/ede-launch/ede-launch.cpp b/ede-launch/ede-launch.cpp index f07bb88..5a572b3 100644 --- a/ede-launch/ede-launch.cpp +++ b/ede-launch/ede-launch.cpp @@ -272,7 +272,9 @@ static void ok_cb(Fl_Widget*, void* w) { if(in_term->value()) { char buf[128]; char* term = getenv("TERM"); - if(!term) + + /* also check if TERM get inherited from login console */ + if(!term || strcmp(term, "linux") == 0) term = "xterm"; snprintf(buf, sizeof(buf), "%s -e %s", term, cmd); diff --git a/ede-panel/Panel.cpp b/ede-panel/Panel.cpp index 593728d..05dda39 100644 --- a/ede-panel/Panel.cpp +++ b/ede-panel/Panel.cpp @@ -165,6 +165,38 @@ static void move_widget(Panel *self, Fl_Widget *o, int &sx, int &sy) { } #endif +Panel::Panel() : PanelWindow(300, 30) { + clicked = 0; + sx = sy = 0; + vpos = PANEL_POSITION_BOTTOM; + screen_x = screen_y = screen_w = screen_h = 0; + screen_h_half = 0; + can_move_widgets = false; + + box(FL_UP_BOX); + read_config(); +} + +void Panel::read_config(void) { + Resource r; + if(!r.load("ede-panel")) + return; + + int p; + if(r.get("Panel", "position", p, PANEL_POSITION_BOTTOM)) { + if((p != PANEL_POSITION_TOP) && (p != PANEL_POSITION_BOTTOM)) + p = PANEL_POSITION_BOTTOM; + } + + vpos = p; +} + +void Panel::save_config(void) { + Resource r; + r.set("Panel", "position", vpos); + r.save("ede-panel"); +} + void Panel::do_layout(void) { E_RETURN_IF_FAIL(mgr.napplets() > 0); @@ -231,7 +263,7 @@ void Panel::do_layout(void) { /* * Code for horizontal streching. * - * FIXME: This code pretty sucks and need better rewrite in future. + * FIXME: This code pretty sucks and need better rewrite in the future. * 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. */ @@ -281,30 +313,35 @@ void Panel::show(void) { if(!netwm_get_workarea(X, Y, W, H)) Fl::screen_xywh(X, Y, W, H); - resize(X, Y + H - DEFAULT_PANEL_H, W, DEFAULT_PANEL_H); - screen_x = X; screen_y = Y; screen_w = W; screen_h = H; screen_h_half = screen_h / 2; + /* set size as soon as possible, since do_layout() depends on it */ + size(W, DEFAULT_PANEL_H); + do_layout(); window_xid_create(this, netwm_make_me_dock); + + /* position it, this is done after XID was created */ + if(vpos == PANEL_POSITION_BOTTOM) { + position(screen_x, screen_h - h()); + netwm_set_window_strut(this, 0, 0, 0, h()); + } else { + /* FIXME: this does not work well with edewm (nor pekwm). kwin do it correctly. */ + position(screen_x, screen_y); + netwm_set_window_strut(this, 0, 0, h(), 0); + } +} + +void Panel::hide(void) { + save_config(); } int Panel::handle(int e) { switch(e) { - case FL_SHOW: { - int ret = PanelWindow::handle(e); - position(0, screen_h - h()); - - if(shown()) - netwm_set_window_strut(this, 0, 0, 0, h()); - - return ret; - } - case FL_PUSH: clicked = Fl::belowmouse(); @@ -319,29 +356,21 @@ int Panel::handle(int e) { return 1; case FL_DRAG: { -#if 0 - if(clicked && clicked->takesevents()) { - cursor(FL_CURSOR_MOVE); - /* moving the child */ - //move_widget(this, clicked, sx, sy); - clicked->handle(e); - } else { -#endif - cursor(FL_CURSOR_MOVE); - /* are moving the panel; only vertical moving is supported */ + /* 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) { - position(screen_x, screen_y); - netwm_set_window_strut(this, 0, 0, h(), 0); - } + /* snap it to the top or bottom, depending on pressed mouse location */ + if(Fl::event_y_root() <= screen_h_half && y() > screen_h_half) { + position(screen_x, screen_y); + netwm_set_window_strut(this, 0, 0, h(), 0); + vpos = PANEL_POSITION_TOP; + } - if(Fl::event_y_root() > screen_h_half && y() < screen_h_half) { - /* TODO: use area x and area y */ - position(screen_x, screen_h - h()); - netwm_set_window_strut(this, 0, 0, 0, h()); - } - // } + if(Fl::event_y_root() > screen_h_half && y() < screen_h_half) { + position(screen_x, screen_h - h()); + netwm_set_window_strut(this, 0, 0, 0, h()); + vpos = PANEL_POSITION_BOTTOM; + } return 1; } @@ -360,7 +389,6 @@ int Panel::handle(int e) { /* do not quit on Esc key */ if(Fl::event_key() == FL_Escape) return 1; - /* fallthrough */ } diff --git a/ede-panel/Panel.h b/ede-panel/Panel.h index b19ac22..5e69c28 100644 --- a/ede-panel/Panel.h +++ b/ede-panel/Panel.h @@ -9,24 +9,31 @@ EDELIB_NS_USING_AS(Window, PanelWindow) +enum { + PANEL_POSITION_TOP, + PANEL_POSITION_BOTTOM +}; + class Panel : public PanelWindow { private: Fl_Widget *clicked; + int vpos; int sx, sy; int screen_x, screen_y, screen_w, screen_h, screen_h_half; bool can_move_widgets; AppletManager mgr; + void read_config(void); + void save_config(void); void do_layout(void); public: - Panel() : PanelWindow(300, 30), clicked(0), sx(0), sy(0), - screen_x(0), screen_y(0), screen_w(0), screen_h(0), screen_h_half(0), can_move_widgets(false) - { box(FL_UP_BOX); } + Panel(); - int handle(int e); void show(void); + void hide(void); + int handle(int e); void load_applets(void); int panel_w(void) { return w(); } diff --git a/ede-panel/ede-panel.cpp b/ede-panel/ede-panel.cpp index c6bff01..3b8db2f 100644 --- a/ede-panel/ede-panel.cpp +++ b/ede-panel/ede-panel.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,9 +6,26 @@ #include "Panel.h" #include "AppletManager.h" +static bool running; + +static void exit_signal(int signum) { + running = false; +} + int main(int argc, char **argv) { - Panel* panel = new Panel(); + signal(SIGTERM, exit_signal); + signal(SIGKILL, exit_signal); + signal(SIGINT, exit_signal); + + Panel *panel = new Panel(); panel->load_applets(); panel->show(); - return Fl::run(); + running = true; + + while(running) + Fl::wait(); + + /* so Panel::hide() can be called */ + panel->hide(); + return 0; }