From 8089bbab4b8384c0b2c0922d3964ab163ef04e52 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 9 Sep 2014 06:01:46 +0200 Subject: broadcast switching-vt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-vt.c | 37 ++++++++++++++++++++++++++++++++----- src/mds-vt.h | 10 ++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/mds-vt.c b/src/mds-vt.c index 8784058..8b2f276 100644 --- a/src/mds-vt.c +++ b/src/mds-vt.c @@ -371,12 +371,15 @@ int master_loop(void) { if (switching_vt) { - /* FIXME */ + int leaving = switching_vt == 1; + switching_vt = 0; + r = switch_vt(leaving); } - - if (r = mds_message_read(&received, socket_fd), r == 0) - if (r = handle_message(), r == 0) - continue; + else + if (r = mds_message_read(&received, socket_fd), r == 0) + r = handle_message(); + if (r == 0) + continue; if (r == -2) { @@ -413,6 +416,30 @@ int master_loop(void) } +/** + * Perform a VT switch requested by the OS kernel + * + * @param leave_foreground Whether the display is leaving the foreground + * @return Zero on success, -1 on error + */ +int switch_vt(int leave_foreground) +{ + char buf[46 + 12 + 3 * sizeof(int)]; + + sprintf(buf, + "Command: switching-vt\n" + "Message ID: %" PRIu32 "\n" + "Status: %s\n" + "\n", + message_id, + leave_foreground ? "deactivating" : "activating"); + + message_id = message_id == UINT32_MAX ? 0 : (message_id + 1); + + return -!!full_send(buf, strlen(buf)); +} + + /** * Handle the received message * diff --git a/src/mds-vt.h b/src/mds-vt.h index 922e543..93e05de 100644 --- a/src/mds-vt.h +++ b/src/mds-vt.h @@ -25,6 +25,16 @@ #include + +/** + * Perform a VT switch requested by the OS kernel + * + * @param leave_foreground Whether the display is leaving the foreground + * @return Zero on success, -1 on error + */ +int switch_vt(int leave_foreground); + + /** * Handle the received message * -- cgit v1.2.3-70-g09d2