[PATCH 3/5] [terminal] keep track of initial vt and allow to restore it
Scott James Remnant
scott at ubuntu.com
Thu Mar 18 14:34:29 PDT 2010
When the terminal is first created, we already look up the current
VT to see whether the terminal is the active VT. Save this VT
and add a function to allow us to restore to this VT later if we
choose.
---
src/libply-splash-core/ply-terminal.c | 27 +++++++++++++++++++++++++++
src/libply-splash-core/ply-terminal.h | 1 +
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/libply-splash-core/ply-terminal.c b/src/libply-splash-core/ply-terminal.c
index 3487387..564a6bc 100644
--- a/src/libply-splash-core/ply-terminal.c
+++ b/src/libply-splash-core/ply-terminal.c
@@ -65,6 +65,7 @@ struct _ply_terminal
char *name;
int fd;
int vt_number;
+ int initial_vt;
ply_list_t *vt_change_closures;
ply_fd_watch_t *fd_watch;
@@ -107,6 +108,7 @@ ply_terminal_new (const char *device_name)
terminal->fd = -1;
terminal->vt_number = -1;
+ terminal->initial_vt = -1;
return terminal;
}
@@ -318,6 +320,9 @@ get_active_vt (ply_terminal_t *terminal)
if (ioctl (terminal->fd, VT_GETSTATE, &vt_state) < 0)
return -1;
+ if (terminal->initial_vt < 0)
+ terminal->initial_vt = vt_state.v_active;
+
return vt_state.v_active;
}
@@ -719,6 +724,28 @@ ply_terminal_activate_vt (ply_terminal_t *terminal)
return true;
}
+bool
+ply_terminal_restore_vt (ply_terminal_t *terminal)
+{
+ assert (terminal != NULL);
+
+ if (!ply_terminal_is_vt (terminal))
+ return false;
+
+ if (terminal->initial_vt < 0)
+ return false;
+
+ /* Otherwise we'd close and free the terminal before handling the
+ * "leaving the VT" signal.
+ */
+ ply_terminal_stop_watching_for_vt_changes (terminal);
+
+ if (!set_active_vt (terminal, terminal->initial_vt))
+ return false;
+
+ return true;
+}
+
void
ply_terminal_watch_for_active_vt_change (ply_terminal_t *terminal,
ply_terminal_active_vt_changed_handler_t active_vt_changed_handler,
diff --git a/src/libply-splash-core/ply-terminal.h b/src/libply-splash-core/ply-terminal.h
index 5e4f1fc..b22fe9b 100644
--- a/src/libply-splash-core/ply-terminal.h
+++ b/src/libply-splash-core/ply-terminal.h
@@ -92,6 +92,7 @@ void ply_terminal_ignore_mode_changes (ply_terminal_t *terminal,
int ply_terminal_get_vt_number (ply_terminal_t *terminal);
bool ply_terminal_activate_vt (ply_terminal_t *terminal);
+bool ply_terminal_restore_vt (ply_terminal_t *terminal);
void ply_terminal_watch_for_vt_changes (ply_terminal_t *terminal);
void ply_terminal_stop_watching_for_vt_changes (ply_terminal_t *terminal);
--
1.7.0
More information about the plymouth
mailing list