X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fsession.c;h=1a81b90dbe81ad3546c79f987a379a167866db75;hb=HEAD;hp=99d66221ce4a7f3e5993642c223884716e6a4472;hpb=22a88cfe99d897dc7d3be7b53b954f6cdfa250c6;p=chaz%2Fopenbox diff --git a/openbox/session.c b/openbox/session.c index 99d66221..1a81b90d 100644 --- a/openbox/session.c +++ b/openbox/session.c @@ -33,6 +33,8 @@ GSList *session_desktop_names = NULL; void session_startup(gint argc, gchar **argv) {} void session_shutdown(gboolean permanent) {} GList* session_state_find(struct _ObClient *c) { return NULL; } +void session_request_logout(gboolean silent) {} +gboolean session_connected(void) { return FALSE; } #else #include "debug.h" @@ -40,7 +42,7 @@ GList* session_state_find(struct _ObClient *c) { return NULL; } #include "client.h" #include "focus.h" #include "gettext.h" -#include "obt/parse.h" +#include "obt/xml.h" #include "obt/paths.h" #include @@ -158,6 +160,11 @@ void session_shutdown(gboolean permanent) } } +gboolean session_connected(void) +{ + return !!sm_conn; +} + /*! Connect to the session manager and set up our callback functions */ static gboolean session_connect(void) { @@ -369,7 +376,7 @@ static void session_setup_restart_command(void) static ObSMSaveData *sm_save_get_data(void) { - ObSMSaveData *savedata = g_new0(ObSMSaveData, 1); + ObSMSaveData *savedata = g_slice_new0(ObSMSaveData); /* save the active desktop and client. we don't bother to preemptively save the other desktop state like number and names of desktops, cuz those shouldn't be changing during @@ -391,7 +398,7 @@ static void sm_save_yourself_2(SmcConn conn, SmPointer data) if (savedata == NULL) savedata = sm_save_get_data(); success = session_save_to_file(savedata); - g_free(savedata); + g_slice_free(ObSMSaveData, savedata); /* tell the session manager how to restore this state */ if (success) session_setup_restart_command(); @@ -400,14 +407,28 @@ static void sm_save_yourself_2(SmcConn conn, SmPointer data) SmcSaveYourselfDone(conn, success); } - static void sm_save_yourself(SmcConn conn, SmPointer data, gint save_type, Bool shutdown, gint interact_style, Bool fast) { ObSMSaveData *savedata = NULL; gchar *vendor; - ob_debug_type(OB_DEBUG_SM, "Session save requested"); +#ifdef DEBUG + { + const gchar *sname = + (save_type == SmSaveLocal ? "SmSaveLocal" : + (save_type == SmSaveGlobal ? "SmSaveGlobal" : + (save_type == SmSaveBoth ? "SmSaveBoth" : "INVALID!!"))); + ob_debug_type(OB_DEBUG_SM, "Session save requested, type %s", sname); + } +#endif + + if (save_type == SmSaveGlobal) { + /* we have no data to save. we only store state to get back to where + we were, we don't keep open writable files or anything */ + SmcSaveYourselfDone(conn, TRUE); + return; + } vendor = SmcVendor(sm_conn); ob_debug_type(OB_DEBUG_SM, "Session manager's vendor: %s", vendor); @@ -422,7 +443,7 @@ static void sm_save_yourself(SmcConn conn, SmPointer data, gint save_type, if (!SmcRequestSaveYourselfPhase2(conn, sm_save_yourself_2, savedata)) { ob_debug_type(OB_DEBUG_SM, "Requst for phase 2 failed"); - g_free(savedata); + g_slice_free(ObSMSaveData, savedata); SmcSaveYourselfDone(conn, FALSE); } } @@ -475,10 +496,14 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata) if (screen_desktop_names) { gint i; + gchar *t; fprintf(f, "\n"); - for (i = 0; screen_desktop_names[i]; ++i) - fprintf(f, " %s\n", screen_desktop_names[i]); + for (i = 0; screen_desktop_names[i]; ++i){ + t = g_markup_escape_text(screen_desktop_names[i], -1); + fprintf(f, " %s\n", t); + g_free(t); + } fprintf(f, "\n"); } @@ -533,8 +558,11 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata) if (c->sm_client_id) fprintf(f, "\n", c->sm_client_id); - else - fprintf(f, "\n", c->wm_command); + else { + t = g_markup_escape_text(c->wm_command, -1); + fprintf(f, "\n", t); + g_free(t); + } t = g_markup_escape_text(c->name, -1); fprintf(f, "\t%s\n", t); @@ -555,6 +583,7 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata) fprintf(f, "\t%d\n", prey); fprintf(f, "\t%d\n", prew); fprintf(f, "\t%d\n", preh); + fprintf(f, "\t%d\n", c->opacity); if (c->shaded) fprintf(f, "\t\n"); if (c->iconic) @@ -602,7 +631,7 @@ static void session_state_free(ObSessionState *state) g_free(state->class); g_free(state->role); - g_free(state); + g_slice_free(ObSessionState, state); } } @@ -656,113 +685,120 @@ GList* session_state_find(ObClient *c) static void session_load_file(const gchar *path) { - ObtParseInst *i; + ObtXmlInst *i; xmlNodePtr node, n, m; GList *it, *inext; - i = obt_parse_instance_new(); + i = obt_xml_instance_new(); - if (!obt_parse_load_file(i, path, "openbox_session")) { - obt_parse_instance_unref(i); + if (!obt_xml_load_file(i, path, "openbox_session")) { + ob_debug_type(OB_DEBUG_SM, "ERROR: session file is missing root node"); + obt_xml_instance_unref(i); return; } - node = obt_parse_root(i); + node = obt_xml_root(i); - if ((n = obt_parse_find_node(node->children, "desktop"))) - session_desktop = obt_parse_node_int(n); + if ((n = obt_xml_find_node(node->children, "desktop"))) + session_desktop = obt_xml_node_int(n); - if ((n = obt_parse_find_node(node->children, "numdesktops"))) - session_num_desktops = obt_parse_node_int(n); + if ((n = obt_xml_find_node(node->children, "numdesktops"))) + session_num_desktops = obt_xml_node_int(n); - if ((n = obt_parse_find_node(node->children, "desktoplayout"))) { + if ((n = obt_xml_find_node(node->children, "desktoplayout"))) { /* make sure they are all there for it to be valid */ - if ((m = obt_parse_find_node(n->children, "orientation"))) - session_desktop_layout.orientation = obt_parse_node_int(m); - if (m && (m = obt_parse_find_node(n->children, "startcorner"))) - session_desktop_layout.start_corner = obt_parse_node_int(m); - if (m && (m = obt_parse_find_node(n->children, "columns"))) - session_desktop_layout.columns = obt_parse_node_int(m); - if (m && (m = obt_parse_find_node(n->children, "rows"))) - session_desktop_layout.rows = obt_parse_node_int(m); + if ((m = obt_xml_find_node(n->children, "orientation"))) + session_desktop_layout.orientation = obt_xml_node_int(m); + if (m && (m = obt_xml_find_node(n->children, "startcorner"))) + session_desktop_layout.start_corner = obt_xml_node_int(m); + if (m && (m = obt_xml_find_node(n->children, "columns"))) + session_desktop_layout.columns = obt_xml_node_int(m); + if (m && (m = obt_xml_find_node(n->children, "rows"))) + session_desktop_layout.rows = obt_xml_node_int(m); session_desktop_layout_present = m != NULL; } - if ((n = obt_parse_find_node(node->children, "desktopnames"))) { - for (m = obt_parse_find_node(n->children, "name"); m; - m = obt_parse_find_node(m->next, "name")) + if ((n = obt_xml_find_node(node->children, "desktopnames"))) { + for (m = obt_xml_find_node(n->children, "name"); m; + m = obt_xml_find_node(m->next, "name")) { session_desktop_names = g_slist_append(session_desktop_names, - obt_parse_node_string(m)); + obt_xml_node_string(m)); } } - for (node = obt_parse_find_node(node->children, "window"); node != NULL; - node = obt_parse_find_node(node->next, "window")) + ob_debug_type(OB_DEBUG_SM, "loading windows"); + for (node = obt_xml_find_node(node->children, "window"); node != NULL; + node = obt_xml_find_node(node->next, "window")) { ObSessionState *state; - state = g_new0(ObSessionState, 1); + state = g_slice_new0(ObSessionState); - if (!obt_parse_attr_string(node, "id", &state->id)) - if (!obt_parse_attr_string(node, "command", &state->command)) + if (!obt_xml_attr_string(node, "id", &state->id)) + if (!obt_xml_attr_string(node, "command", &state->command)) + goto session_load_bail; + if (!(n = obt_xml_find_node(node->children, "name"))) goto session_load_bail; - if (!(n = obt_parse_find_node(node->children, "name"))) + state->name = obt_xml_node_string(n); + if (!(n = obt_xml_find_node(node->children, "class"))) goto session_load_bail; - state->name = obt_parse_node_string(n); - if (!(n = obt_parse_find_node(node->children, "class"))) + state->class = obt_xml_node_string(n); + if (!(n = obt_xml_find_node(node->children, "role"))) goto session_load_bail; - state->class = obt_parse_node_string(n); - if (!(n = obt_parse_find_node(node->children, "role"))) + state->role = obt_xml_node_string(n); + if (!(n = obt_xml_find_node(node->children, "windowtype"))) goto session_load_bail; - state->role = obt_parse_node_string(n); - if (!(n = obt_parse_find_node(node->children, "windowtype"))) + state->type = obt_xml_node_int(n); + if (!(n = obt_xml_find_node(node->children, "desktop"))) goto session_load_bail; - state->type = obt_parse_node_int(n); - if (!(n = obt_parse_find_node(node->children, "desktop"))) + state->desktop = obt_xml_node_int(n); + if (!(n = obt_xml_find_node(node->children, "x"))) goto session_load_bail; - state->desktop = obt_parse_node_int(n); - if (!(n = obt_parse_find_node(node->children, "x"))) + state->x = obt_xml_node_int(n); + if (!(n = obt_xml_find_node(node->children, "y"))) goto session_load_bail; - state->x = obt_parse_node_int(n); - if (!(n = obt_parse_find_node(node->children, "y"))) + state->y = obt_xml_node_int(n); + if (!(n = obt_xml_find_node(node->children, "width"))) goto session_load_bail; - state->y = obt_parse_node_int(n); - if (!(n = obt_parse_find_node(node->children, "width"))) + state->w = obt_xml_node_int(n); + if (!(n = obt_xml_find_node(node->children, "height"))) goto session_load_bail; - state->w = obt_parse_node_int(n); - if (!(n = obt_parse_find_node(node->children, "height"))) + state->h = obt_xml_node_int(n); + if (!(n = obt_xml_find_node(node->children, "opacity"))) goto session_load_bail; - state->h = obt_parse_node_int(n); + state->opacity = obt_xml_node_int(n); state->shaded = - obt_parse_find_node(node->children, "shaded") != NULL; + obt_xml_find_node(node->children, "shaded") != NULL; state->iconic = - obt_parse_find_node(node->children, "iconic") != NULL; + obt_xml_find_node(node->children, "iconic") != NULL; state->skip_pager = - obt_parse_find_node(node->children, "skip_pager") != NULL; + obt_xml_find_node(node->children, "skip_pager") != NULL; state->skip_taskbar = - obt_parse_find_node(node->children, "skip_taskbar") != NULL; + obt_xml_find_node(node->children, "skip_taskbar") != NULL; state->fullscreen = - obt_parse_find_node(node->children, "fullscreen") != NULL; + obt_xml_find_node(node->children, "fullscreen") != NULL; state->above = - obt_parse_find_node(node->children, "above") != NULL; + obt_xml_find_node(node->children, "above") != NULL; state->below = - obt_parse_find_node(node->children, "below") != NULL; + obt_xml_find_node(node->children, "below") != NULL; state->max_horz = - obt_parse_find_node(node->children, "max_horz") != NULL; + obt_xml_find_node(node->children, "max_horz") != NULL; state->max_vert = - obt_parse_find_node(node->children, "max_vert") != NULL; + obt_xml_find_node(node->children, "max_vert") != NULL; state->undecorated = - obt_parse_find_node(node->children, "undecorated") != NULL; + obt_xml_find_node(node->children, "undecorated") != NULL; state->focused = - obt_parse_find_node(node->children, "focused") != NULL; + obt_xml_find_node(node->children, "focused") != NULL; /* save this. they are in the file in stacking order, so preserve that order here */ session_saved_state = g_list_append(session_saved_state, state); + ob_debug_type(OB_DEBUG_SM, "loaded %s", state->name); continue; session_load_bail: + ob_debug_type(OB_DEBUG_SM, "loading FAILED"); session_state_free(state); } @@ -797,6 +833,7 @@ static void session_load_file(const gchar *path) !strcmp(s1->class, s2->class) && !strcmp(s1->role, s2->role)) { + ob_debug_type(OB_DEBUG_SM, "removing duplicate %s", s2->name); session_state_free(s2); session_saved_state = g_list_delete_link(session_saved_state, jt); @@ -805,12 +842,29 @@ static void session_load_file(const gchar *path) } if (founddup) { + ob_debug_type(OB_DEBUG_SM, "removing duplicate %s", s1->name); session_state_free(s1); session_saved_state = g_list_delete_link(session_saved_state, it); } } - obt_parse_instance_unref(i); + obt_xml_instance_unref(i); +} + +void session_request_logout(gboolean silent) +{ + if (sm_conn) { + SmcRequestSaveYourself(sm_conn, + SmSaveGlobal, + TRUE, /* logout */ + (silent ? + SmInteractStyleNone : SmInteractStyleAny), + TRUE, /* if false, with GSM, it shows the old + logout prompt */ + TRUE); /* global */ + } + else + g_message(_("Not connected to a session manager")); } #endif