From d1a21ee2a1acb3582b25b94c73e3eb1fe2b19242 Mon Sep 17 00:00:00 2001 From: Philip Allison Date: Tue, 15 Apr 2008 21:19:52 +0100 Subject: [PATCH] Add -float and -noquit options Signed-off-by: Philip Allison --- src/cteddy.cxx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/cteddy.cxx b/src/cteddy.cxx index 0f66b00..e5d31a2 100644 --- a/src/cteddy.cxx +++ b/src/cteddy.cxx @@ -116,8 +116,6 @@ void handle_screen(GtkWidget* window, GdkScreen* old, gpointer data) // Handle key press events void handle_key_press(GtkWidget *Window, GdkEventKey *theEvent) { - /* TA: Boolean -noquit needed here. Wouldn't want to him to - * accidentally disappear. */ switch( theEvent->keyval ) { case GDK_q: @@ -136,6 +134,12 @@ void handle_key_press(GtkWidget *Window, GdkEventKey *theEvent) int main (int argc, char* argv[]) { gtk_init(&argc, &argv); + + // Whether or not the "q to quit" keybinding is disabled + bool noquit = false; + + // Whether or not to set the window's keep-on-top hint + bool ontop = false; // Mimic the image loading behaviour of xteddy, to an extent. { @@ -147,10 +151,20 @@ int main (int argc, char* argv[]) if (s != std::string::npos) image = image.substr(s + 1); - // Allow overriding with -F + // Parse options + // XXX This code is really quick and nasty for (int i = 1; i < argc; ++i) + { + // Allow image specification with -F if (strncmp(argv[i], "-F", 2) == 0) image = argv[i] + 2; + // Allow disablement of "q" keybinding + else if (strncmp(argv[i], "-noquit", 7) == 0) + noquit = true; + // Allow keep-on-top + else if (strncmp(argv[i], "-float", 6) == 0) + ontop = true; + } // If the given path contains slashes, assume it is absolute or // relative to the current working directory and use it verbatim. @@ -158,6 +172,7 @@ int main (int argc, char* argv[]) if (image.find_last_of('/') == std::string::npos) { // Append extensions one by one and search for the image + // XXX This code is really, REALLY quick and nasty char* extensions[17]; bool found = false; extensions[0] = '\0'; @@ -246,7 +261,9 @@ int main (int argc, char* argv[]) g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(window_clicked), NULL); g_signal_connect(G_OBJECT(window), "screen-changed", G_CALLBACK(handle_screen), NULL); - g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(handle_key_press), NULL); + + if (!noquit) + g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(handle_key_press), NULL); { // Grap pixmap and alpha-thresholded bitmap from original pixmap @@ -302,6 +319,9 @@ int main (int argc, char* argv[]) // Don't steal input focus when we start g_object_set(G_OBJECT(window), "focus-on-map", false, NULL); + if (ontop) + gtk_window_set_keep_above(window, true); + gtk_widget_show_all(window); gtk_main(); -- 2.11.4.GIT