summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorportix <none@none>2012-03-29 15:04:21 +0200
committerportix <none@none>2012-03-29 15:04:21 +0200
commit7f34483796a200375c9b633f1f2fb7e9bdc3c11f (patch)
tree472d0943790c1699b7bdbded7bf4d59b18935c06 /src
parent560d4768ac1f22d8276f1720d9c2ae750d837c69 (diff)
downloaddwb-7f34483796a200375c9b633f1f2fb7e9bdc3c11f.zip
Save session also if commandline-argument -R is given, closing #135
Diffstat (limited to 'src')
-rw-r--r--src/application.c11
-rw-r--r--src/commands.c2
-rw-r--r--src/dwb.c8
-rw-r--r--src/session.c32
-rw-r--r--src/session.h8
5 files changed, 38 insertions, 23 deletions
diff --git a/src/application.c b/src/application.c
index 1a5c99c4..50b682b7 100644
--- a/src/application.c
+++ b/src/application.c
@@ -295,6 +295,7 @@ application_execute_args(char **argv) {
static void /* application_start(GApplication *app, char **argv) {{{*/
application_start(GApplication *app, char **argv) {
gboolean restored = false;
+ int session_flags = 0;
if (argv == NULL)
return;
gtk_init(NULL, NULL);
@@ -302,14 +303,17 @@ application_start(GApplication *app, char **argv) {
dwb_pack(GET_CHAR("widget-packing"), false);
+ if (opt_force)
+ session_flags |= SESSION_FORCE;
/* restore session */
if (! opt_override_restore) {
if (GET_BOOL("save-session") || opt_restore != NULL) {
- if (opt_restore == NULL)
- opt_restore = g_strdup("default");
- restored = session_restore(opt_restore, opt_force);
+ restored = session_restore(opt_restore, session_flags);
}
}
+ else {
+ session_restore(opt_restore, session_flags | SESSION_ONLY_MARK);
+ }
if (! restored && g_strv_length(argv) == 1 ) {
view_add(NULL, false);
dwb_open_startpage(dwb.state.fview);
@@ -324,7 +328,6 @@ application_start(GApplication *app, char **argv) {
pango_layout_get_size(layout, &w, &h);
dwb.misc.bar_height = h/PANGO_SCALE;
-
gtk_widget_set_size_request(dwb.gui.entry, -1, dwb.misc.bar_height);
g_object_unref(layout);
diff --git a/src/commands.c b/src/commands.c
index b6494701..f882f45f 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -479,7 +479,7 @@ DwbStatus
commands_save_session(KeyMap *km, Arg *arg) {
if (arg->n == NORMAL_MODE) {
dwb.state.mode = SAVE_SESSION;
- session_save(NULL, true);
+ session_save(NULL, SESSION_FORCE);
dwb_end();
return STATUS_END;
}
diff --git a/src/dwb.c b/src/dwb.c
index 91a15414..8a4b97f5 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -2069,7 +2069,7 @@ dwb_entry_activate(GdkEventKey *e) {
return true;
case DOWNLOAD_GET_PATH: download_start(NULL);
return true;
- case SAVE_SESSION: session_save(GET_TEXT(), true);
+ case SAVE_SESSION: session_save(GET_TEXT(), SESSION_FORCE);
dwb_end();
return true;
case COMPLETE_BUFFER: completion_eval_buffer_completion();
@@ -2810,7 +2810,7 @@ dwb_save_files(gboolean end_session) {
}
/* save session */
if (end_session && GET_BOOL("save-session") && dwb.state.mode != SAVE_SESSION) {
- session_save(NULL, false);
+ session_save(NULL, 0);
}
return true;
}
@@ -3044,15 +3044,15 @@ dwb_init_settings() {
s = dwb_malloc(sizeof(WebSettings));
*s = DWB_SETTINGS[j];
if ( (arg = util_char_to_arg(value, s->type)) ) {
- s->arg = s->arg_local = *arg;
+ s->arg = *arg;
}
break;
}
}
if (s == NULL) {
s = &DWB_SETTINGS[j];
- s->arg_local = s->arg;
}
+ s->arg_local = s->arg;
g_hash_table_insert(dwb.settings, key, s);
if (s->apply & SETTING_BUILTIN || s->apply & SETTING_ONINIT) {
s->func(NULL, s);
diff --git a/src/session.c b/src/session.c
index a3fc1ac3..6474c3f9 100644
--- a/src/session.c
+++ b/src/session.c
@@ -167,7 +167,7 @@ session_list() {
/* session_restore(const char *name) {{{*/
gboolean
-session_restore(char *name, gboolean force) {
+session_restore(char *name, int flags) {
gboolean is_marked = false;
char *uri = NULL;
GList *currentview = NULL, *lastview = NULL;
@@ -175,23 +175,28 @@ session_restore(char *name, gboolean force) {
int last = 1;
char *end;
int locked_state = 0;
+ if (name == NULL) {
+ _session_name = g_strdup("default");
+ }
+ else
+ _session_name = name;
- char *group = session_get_group(name, &is_marked);
- if (is_marked && !force) {
- fprintf(stderr, "Warning: Session '%s' will not be restored.\n", name);
- fprintf(stderr, "There is already a restored session open with name '%s'.\n", name);
+ char *group = session_get_group(_session_name, &is_marked);
+ if (is_marked && (flags & SESSION_FORCE) == 0) {
+ fprintf(stderr, "Warning: Session '%s' will not be restored.\n", _session_name);
+ fprintf(stderr, "There is already a restored session open with name '%s'.\n", _session_name);
fputs("To force opening a saved session use -f or --force.\n", stderr);
_has_marked = false;
- return false;
+ goto clean;
}
- _session_name = name;
if (group == NULL) {
return false;
}
char *group_begin = strchr(group, '\n');
- session_save_file(name, group_begin+1, true);
+ session_save_file(_session_name, group_begin+1, true);
+ if (flags & SESSION_ONLY_MARK)
+ goto clean;
char **lines = g_strsplit(group, "\n", -1);
- g_free(group);
int length = g_strv_length(lines) - 1;
for (int i=1; i<=length; i++) {
@@ -231,19 +236,22 @@ session_restore(char *name, gboolean force) {
}
dwb_focus(dwb.state.fview);
g_free(uri);
+
+clean:
+ g_free(group);
return true;
}/*}}}*/
/* session_save(const char *) {{{*/
gboolean
-session_save(const char *name, gboolean force) {
+session_save(const char *name, int flags) {
if (!name) {
if (_session_name)
name = _session_name;
- else if (force)
+ else if (flags & SESSION_FORCE)
name = "default";
}
- if (!_has_marked && !force)
+ if (!_has_marked && (flags & SESSION_FORCE) == 0)
return false;
GString *buffer = g_string_new(NULL);
diff --git a/src/session.h b/src/session.h
index c7871325..af940dd9 100644
--- a/src/session.h
+++ b/src/session.h
@@ -19,8 +19,12 @@
#ifndef SESSION_H
#define SESSION_H
-gboolean session_save(const char *, gboolean);
-gboolean session_restore(char *, gboolean);
+enum SessionFlags {
+ SESSION_FORCE = 1<<0,
+ SESSION_ONLY_MARK = 1<<1,
+};
+gboolean session_save(const char *, int);
+gboolean session_restore(char *, int);
void session_list(void);
#endif