Fixed #194: ede-desktop will not save icon position on Shutdown. Code cleanup.

When user hit shutdown or restart from dialog, evoke will immediately sent shutdown/restart signal, causing abnormal X termination, killing all childs. With this commit, evoke will first close all X childs, then send shutdown/restart signal.
This commit is contained in:
Sanel Zukan 2013-01-05 03:39:09 +00:00
parent c93bfdf7ee
commit 31d35e627a
2 changed files with 57 additions and 82 deletions

View File

@ -110,7 +110,7 @@ static void send_dbus_ede_quit(void) {
#define CONSOLEKIT_PATH "/org/freedesktop/ConsoleKit/Manager"
#define CONSOLEKIT_INTERFACE "org.freedesktop.ConsoleKit.Manager"
static bool do_shutdown_or_restart(bool restart) {
static bool do_shutdown_or_restart(bool restart, void (*x_shutdown_func)(void)) {
const char *action;
int r = 1;
@ -146,6 +146,9 @@ static bool do_shutdown_or_restart(bool restart) {
EdbusMessage::iterator it = ret.begin();
if(it->is_bool() && it->to_bool() == true) {
/* first close all X children */
x_shutdown_func();
/* call action */
msg.create_method_call(CONSOLEKIT_SERVICE,
CONSOLEKIT_PATH,
@ -196,12 +199,11 @@ EvokeService* EvokeService::instance(void) {
}
bool EvokeService::setup_lock(const char* name) {
if(file_test(name, FILE_TEST_IS_REGULAR))
return false;
E_RETURN_VAL_IF_FAIL(file_test(name, FILE_TEST_IS_REGULAR) == false, false);
FILE* f = fopen(name, "w");
if(!f)
return false;
E_RETURN_VAL_IF_FAIL(f != NULL, false);
fclose(f);
lock_name = strdup(name);
@ -209,8 +211,7 @@ bool EvokeService::setup_lock(const char* name) {
}
void EvokeService::remove_lock(void) {
if(!lock_name)
return;
E_RETURN_IF_FAIL(lock_name != NULL);
file_remove(lock_name);
free(lock_name);
@ -218,14 +219,13 @@ void EvokeService::remove_lock(void) {
}
void EvokeService::clear_startup_items(void) {
if(startup_items.empty())
return;
E_RETURN_IF_FAIL(startup_items.size() > 0);
StartupItemListIter it = startup_items.begin(), it_end = startup_items.end();
for(; it != it_end; ++it)
StartupItemListIter it = startup_items.begin(), ite = startup_items.end();
while(it != ite) {
delete *it;
startup_items.clear();
it = startup_items.erase(it);
}
}
void EvokeService::read_startup(void) {
@ -246,40 +246,37 @@ void EvokeService::read_startup(void) {
return;
}
char tok_buff[256], buff[256];
char tokbuf[128], buf[128];
/* if nothing found, exit */
if(!CONFIG_GET_STRVAL(c, "Startup", "start_order", tok_buff))
return;
E_RETURN_IF_FAIL(CONFIG_GET_STRVAL(c, "Startup", "start_order", tokbuf));
if(CONFIG_GET_STRVAL(c, "Startup", "splash_theme", buff))
splash_theme = buff;
if(CONFIG_GET_STRVAL(c, "Startup", "splash_theme", buf))
splash_theme = buf;
for(const char* sect = strtok(tok_buff, ","); sect; sect = strtok(NULL, ",")) {
for(const char* sect = strtok(tokbuf, ","); sect; sect = strtok(NULL, ",")) {
/* remove leading/ending spaces, if exists */
str_trim(buff);
str_trim(buf);
/* assure each startup item has 'exec' key */
if(!CONFIG_GET_STRVAL(c, sect, "exec", buff)) {
if(!CONFIG_GET_STRVAL(c, sect, "exec", buf)) {
E_WARNING(E_STRLOC ": Startup item '%s' does not have anything to execute. Skipping...\n", sect);
continue;
}
StartupItem *s = new StartupItem;
s->exec = buff;
s->exec = buf;
if(CONFIG_GET_STRVAL(c, sect, "icon", buff))
s->icon = buff;
if(CONFIG_GET_STRVAL(c, sect, "description", buff))
s->description = buff;
if(CONFIG_GET_STRVAL(c, sect, "icon", buf))
s->icon = buf;
if(CONFIG_GET_STRVAL(c, sect, "description", buf))
s->description = buf;
startup_items.push_back(s);
}
}
void EvokeService::run_startup(bool splash, bool dryrun) {
if(startup_items.empty())
return;
E_RETURN_IF_FAIL(startup_items.size() > 0);
Splash s(startup_items, splash_theme, splash, dryrun);
s.run();
@ -290,7 +287,7 @@ void EvokeService::start_xsettings_manager(void) {
xsm = new Xsm;
if(Xsm::manager_running(fl_display, fl_screen)) {
int ret = edelib::ask(_("XSETTINGS manager already running on this screen. Would you like to replace it?"));
int ret = ask(_("XSETTINGS manager already running on this screen. Would you like to replace it?"));
if(ret < 1) {
stop_xsettings_manager(false);
return;
@ -298,19 +295,16 @@ void EvokeService::start_xsettings_manager(void) {
}
if(!xsm->init(fl_display, fl_screen)) {
edelib::alert(_("Unable to load XSETTINGS manager properly :-("));
alert(_("Unable to load XSETTINGS manager properly"));
stop_xsettings_manager(false);
}
E_RETURN_IF_FAIL(xsm);
if(xsm->load_serialized())
xsm->notify();
}
void EvokeService::stop_xsettings_manager(bool serialize) {
if(!xsm)
return;
E_RETURN_IF_FAIL(xsm != NULL);
if(serialize)
xsm->save_serialized();
@ -335,10 +329,12 @@ int EvokeService::handle(const XEvent* xev) {
if(xev->xproperty.atom == XA_EDE_EVOKE_SHUTDOWN_ALL) {
int val = get_int_property_value(XA_EDE_EVOKE_SHUTDOWN_ALL);
if(val == 1) {
int dw = DisplayWidth(fl_display, fl_screen);
int dh = DisplayHeight(fl_display, fl_screen);
int dw, dh, ret;
int ret = logout_dialog_show(dw, dh, LOGOUT_OPT_SHUTDOWN | LOGOUT_OPT_RESTART);
dw = DisplayWidth(fl_display, fl_screen);
dh = DisplayHeight(fl_display, fl_screen);
ret = logout_dialog_show(dw, dh, LOGOUT_OPT_SHUTDOWN | LOGOUT_OPT_RESTART);
if(ret == LOGOUT_RET_CANCEL)
return 1;
@ -346,12 +342,10 @@ int EvokeService::handle(const XEvent* xev) {
switch(ret) {
case LOGOUT_RET_RESTART:
if(!do_shutdown_or_restart(true))
return 1;
if(!do_shutdown_or_restart(true, x_shutdown)) return 1;
break;
case LOGOUT_RET_SHUTDOWN:
if(!do_shutdown_or_restart(false))
return 1;
if(!do_shutdown_or_restart(false, x_shutdown)) return 1;
break;
case LOGOUT_RET_LOGOUT:
default:

View File

@ -10,7 +10,6 @@
* See COPYING for details.
*/
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Shared_Image.H>
#include <edelib/Debug.h>
@ -20,6 +19,7 @@
#include <edelib/FileTest.h>
#include <edelib/Resource.h>
#include <edelib/Run.h>
#include <edelib/Netwm.h>
#include "Splash.h"
@ -31,8 +31,10 @@ EDELIB_NS_USING(Resource)
EDELIB_NS_USING(build_filename)
EDELIB_NS_USING(file_test)
EDELIB_NS_USING(run_async)
EDELIB_NS_USING(netwm_window_set_type)
EDELIB_NS_USING(RES_SYS_ONLY)
EDELIB_NS_USING(FILE_TEST_IS_DIR)
EDELIB_NS_USING(NETWM_WINDOW_TYPE_SPLASH)
#ifndef EDEWM_HAVE_NET_SPLASH
static Splash* global_splash = NULL;
@ -54,17 +56,10 @@ static int splash_xmessage_handler(int e) {
}
#endif
/*
* repeatedly call runner() until all clients are
* started then hide splash window
*/
/* repeatedly call runner() until all clients are started then hide splash window */
static void runner_cb(void* s) {
Splash* sp = (Splash*)s;
if(sp->next_client())
Fl::repeat_timeout(TIMEOUT_CONTINUE, runner_cb, sp);
else
sp->hide();
sp->next_client() ? Fl::repeat_timeout(TIMEOUT_CONTINUE, runner_cb, sp) : sp->hide();
}
Splash::Splash(StartupItemList& s, String& theme, bool show_it, bool dr) : Fl_Double_Window(480, 365) {
@ -78,27 +73,21 @@ Splash::Splash(StartupItemList& s, String& theme, bool show_it, bool dr) : Fl_Do
box(FL_BORDER_BOX);
}
Splash::~Splash() {
E_DEBUG(E_STRLOC ": Cleaning splash data\n");
/* elements of icons cleans Fl_Group */
delete [] icons;
Fl::remove_timeout(runner_cb);
}
/* after edewm got _NET_WM_WINDOW_TYPE_SPLASH support */
/* for wm's with _NET_WM_WINDOW_TYPE_SPLASH support */
#if EDEWM_HAVE_NET_SPLASH
void Splash::show(void) {
if(shown())
return;
if(shown()) return;
Fl_X::make_xid(this);
Atom win_type = XInternAtom(fl_display, "_NET_WM_WINDOW_TYPE", False);
Atom win_splash = XInternAtom(fl_display, "_NET_WM_WINDOW_TYPE_SPLASH", False);
XChangeProperty(fl_display, fl_xid(this), win_type, XA_ATOM, 32, PropModeReplace,
(unsigned char*)&win_splash, sizeof(Atom));
netwm_window_set_type(fl_xid(this), NETWM_WINDOW_TYPE_SPLASH);
}
#endif
@ -112,7 +101,6 @@ void Splash::run(void) {
}
fl_register_images();
String path, splash_theme_path;
#ifdef USE_LOCAL_CONFIG
@ -124,6 +112,7 @@ void Splash::run(void) {
return;
}
#endif
splash_theme_path += E_DIR_SEPARATOR;
splash_theme_path += *splash_theme;
@ -150,10 +139,7 @@ void Splash::run(void) {
bimg->image(splash_img);
}
/*
* place message box at the bottom with
* nice offset (10 px) from window borders
*/
/* place message box at the bottom with nice offset (10 px) from window borders */
msgbox = new Fl_Box(10, h() - 25 - 10, w() - 20, 25);
/*
@ -213,13 +199,10 @@ void Splash::run(void) {
clear_border();
/*
* If set_override() is used, message boxes will be
* popped behind splash. Using it or not ???
*/
/* If set_override() is used, message boxes will be popped behind splash. Using it or not ??? */
set_override();
// make sure window is centered
/* make sure window is centered */
int sw = DisplayWidth(fl_display, fl_screen);
int sh = DisplayHeight(fl_display, fl_screen);
position(sw / 2 - w() / 2, sh / 2 - h() / 2);
@ -227,7 +210,7 @@ void Splash::run(void) {
show();
Fl::add_timeout(TIMEOUT_START, runner_cb, this);
// to keep splash at the top
/* to keep splash at the top */
#ifndef EDEWM_HAVE_NET_SPLASH
global_splash = this;
XSelectInput(fl_display, RootWindow(fl_display, fl_screen), SubstructureNotifyMask);
@ -244,8 +227,7 @@ void Splash::run(void) {
/* called when splash option is on */
bool Splash::next_client(void) {
if(slist->empty())
return false;
E_RETURN_VAL_IF_FAIL(slist->size() > 0, false);
if(counter == 0)
slist_it = slist->begin();
@ -255,11 +237,11 @@ bool Splash::next_client(void) {
return false;
}
E_ASSERT(counter < slist->size() && "Internal error; 'counter' out of bounds");
const char* msg = (*slist_it)->description.c_str();
const char* cmd = (*slist_it)->exec.c_str();
const char *msg, *cmd;
msg = (*slist_it)->description.c_str();
cmd = (*slist_it)->exec.c_str();
icons[counter]->show();
msgbox->label(msg);
@ -276,8 +258,7 @@ bool Splash::next_client(void) {
/* called when splash option is off */
bool Splash::next_client_nosplash(void) {
if(slist->empty())
return false;
E_RETURN_VAL_IF_FAIL(slist->size() > 0, false);
if(counter == 0)
slist_it = slist->begin();
@ -292,7 +273,7 @@ bool Splash::next_client_nosplash(void) {
const char* msg = (*slist_it)->description.c_str();
const char* cmd = (*slist_it)->exec.c_str();
printf("%s\n", msg);
E_DEBUG(E_STRLOC ": Starting '%s'...\n", msg);
/* run command */
if(!dryrun)