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

View File

@ -10,7 +10,6 @@
* See COPYING for details. * See COPYING for details.
*/ */
#include <stdio.h>
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/Fl_Shared_Image.H> #include <FL/Fl_Shared_Image.H>
#include <edelib/Debug.h> #include <edelib/Debug.h>
@ -20,6 +19,7 @@
#include <edelib/FileTest.h> #include <edelib/FileTest.h>
#include <edelib/Resource.h> #include <edelib/Resource.h>
#include <edelib/Run.h> #include <edelib/Run.h>
#include <edelib/Netwm.h>
#include "Splash.h" #include "Splash.h"
@ -31,8 +31,10 @@ EDELIB_NS_USING(Resource)
EDELIB_NS_USING(build_filename) EDELIB_NS_USING(build_filename)
EDELIB_NS_USING(file_test) EDELIB_NS_USING(file_test)
EDELIB_NS_USING(run_async) EDELIB_NS_USING(run_async)
EDELIB_NS_USING(netwm_window_set_type)
EDELIB_NS_USING(RES_SYS_ONLY) EDELIB_NS_USING(RES_SYS_ONLY)
EDELIB_NS_USING(FILE_TEST_IS_DIR) EDELIB_NS_USING(FILE_TEST_IS_DIR)
EDELIB_NS_USING(NETWM_WINDOW_TYPE_SPLASH)
#ifndef EDEWM_HAVE_NET_SPLASH #ifndef EDEWM_HAVE_NET_SPLASH
static Splash* global_splash = NULL; static Splash* global_splash = NULL;
@ -54,17 +56,10 @@ static int splash_xmessage_handler(int e) {
} }
#endif #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) { static void runner_cb(void* s) {
Splash* sp = (Splash*)s; Splash* sp = (Splash*)s;
sp->next_client() ? Fl::repeat_timeout(TIMEOUT_CONTINUE, runner_cb, sp) : sp->hide();
if(sp->next_client())
Fl::repeat_timeout(TIMEOUT_CONTINUE, runner_cb, sp);
else
sp->hide();
} }
Splash::Splash(StartupItemList& s, String& theme, bool show_it, bool dr) : Fl_Double_Window(480, 365) { Splash::Splash(StartupItemList& s, String& theme, bool show_it, bool dr) : Fl_Double_Window(480, 365) {
@ -77,28 +72,22 @@ Splash::Splash(StartupItemList& s, String& theme, bool show_it, bool dr) : Fl_Do
box(FL_BORDER_BOX); box(FL_BORDER_BOX);
} }
Splash::~Splash() { Splash::~Splash() {
E_DEBUG(E_STRLOC ": Cleaning splash data\n"); E_DEBUG(E_STRLOC ": Cleaning splash data\n");
/* elements of icons cleans Fl_Group */ /* elements of icons cleans Fl_Group */
delete [] icons; delete [] icons;
Fl::remove_timeout(runner_cb); Fl::remove_timeout(runner_cb);
} }
/* for wm's with _NET_WM_WINDOW_TYPE_SPLASH support */
/* after edewm got _NET_WM_WINDOW_TYPE_SPLASH support */
#if EDEWM_HAVE_NET_SPLASH #if EDEWM_HAVE_NET_SPLASH
void Splash::show(void) { void Splash::show(void) {
if(shown()) if(shown()) return;
return;
Fl_X::make_xid(this); Fl_X::make_xid(this);
netwm_window_set_type(fl_xid(this), NETWM_WINDOW_TYPE_SPLASH);
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));
} }
#endif #endif
@ -112,7 +101,6 @@ void Splash::run(void) {
} }
fl_register_images(); fl_register_images();
String path, splash_theme_path; String path, splash_theme_path;
#ifdef USE_LOCAL_CONFIG #ifdef USE_LOCAL_CONFIG
@ -124,6 +112,7 @@ void Splash::run(void) {
return; return;
} }
#endif #endif
splash_theme_path += E_DIR_SEPARATOR; splash_theme_path += E_DIR_SEPARATOR;
splash_theme_path += *splash_theme; splash_theme_path += *splash_theme;
@ -150,10 +139,7 @@ void Splash::run(void) {
bimg->image(splash_img); 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); msgbox = new Fl_Box(10, h() - 25 - 10, w() - 20, 25);
/* /*
@ -213,21 +199,18 @@ void Splash::run(void) {
clear_border(); 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(); set_override();
// make sure window is centered /* make sure window is centered */
int sw = DisplayWidth(fl_display, fl_screen); int sw = DisplayWidth(fl_display, fl_screen);
int sh = DisplayHeight(fl_display, fl_screen); int sh = DisplayHeight(fl_display, fl_screen);
position(sw/2 - w()/2, sh/2 - h()/2); position(sw / 2 - w() / 2, sh / 2 - h() / 2);
show(); show();
Fl::add_timeout(TIMEOUT_START, runner_cb, this); 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 #ifndef EDEWM_HAVE_NET_SPLASH
global_splash = this; global_splash = this;
XSelectInput(fl_display, RootWindow(fl_display, fl_screen), SubstructureNotifyMask); XSelectInput(fl_display, RootWindow(fl_display, fl_screen), SubstructureNotifyMask);
@ -244,8 +227,7 @@ void Splash::run(void) {
/* called when splash option is on */ /* called when splash option is on */
bool Splash::next_client(void) { bool Splash::next_client(void) {
if(slist->empty()) E_RETURN_VAL_IF_FAIL(slist->size() > 0, false);
return false;
if(counter == 0) if(counter == 0)
slist_it = slist->begin(); slist_it = slist->begin();
@ -255,11 +237,11 @@ bool Splash::next_client(void) {
return false; return false;
} }
E_ASSERT(counter < slist->size() && "Internal error; 'counter' out of bounds"); E_ASSERT(counter < slist->size() && "Internal error; 'counter' out of bounds");
const char* msg = (*slist_it)->description.c_str(); const char *msg, *cmd;
const char* cmd = (*slist_it)->exec.c_str(); msg = (*slist_it)->description.c_str();
cmd = (*slist_it)->exec.c_str();
icons[counter]->show(); icons[counter]->show();
msgbox->label(msg); msgbox->label(msg);
@ -276,8 +258,7 @@ bool Splash::next_client(void) {
/* called when splash option is off */ /* called when splash option is off */
bool Splash::next_client_nosplash(void) { bool Splash::next_client_nosplash(void) {
if(slist->empty()) E_RETURN_VAL_IF_FAIL(slist->size() > 0, false);
return false;
if(counter == 0) if(counter == 0)
slist_it = slist->begin(); slist_it = slist->begin();
@ -292,7 +273,7 @@ bool Splash::next_client_nosplash(void) {
const char* msg = (*slist_it)->description.c_str(); const char* msg = (*slist_it)->description.c_str();
const char* cmd = (*slist_it)->exec.c_str(); const char* cmd = (*slist_it)->exec.c_str();
printf("%s\n", msg); E_DEBUG(E_STRLOC ": Starting '%s'...\n", msg);
/* run command */ /* run command */
if(!dryrun) if(!dryrun)