summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/main.c b/main.c
index e548777..433d0ce 100644
--- a/main.c
+++ b/main.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <locale.h>
+#include <signal.h>
#include <glib.h>
#include <glib-object.h>
#include <X11/Xlib.h>
@@ -38,6 +39,7 @@ XIC x_ic;
char * opt_display = NULL;
gint64 opt_xephyr = 0;
+gboolean opt_verbose = FALSE;
static GMainLoop *main_loop;
static MeegoImConnector *m_connector;
@@ -49,9 +51,49 @@ static GOptionEntry entries[] =
{
{ "display", 'd', 0, G_OPTION_ARG_STRING, &opt_display, "X11 display to use", "DISPLAY" },
{ "xephyr", 'x', 0, G_OPTION_ARG_INT64, &opt_xephyr, "Xephyr mode", "XEPHYR_WINDOW_ID" },
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Verbose mode", NULL },
{ NULL }
};
+static void log_func(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
+{
+ gboolean def_log_domain = strcmp(log_domain, G_LOG_DOMAIN) == 0;
+ if (log_level & G_LOG_LEVEL_DEBUG) {
+ // A debug message
+ if (opt_verbose) {
+ if (def_log_domain) {
+ g_print("%s\n", message);
+ } else {
+ g_print("%s: %s\n", log_domain, message);
+ }
+ }
+ } else if (log_level & (G_LOG_FLAG_FATAL | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL)) {
+ if (def_log_domain) {
+ g_printerr("FATAL: %s\n", message);
+ } else {
+ g_printerr("%s FATAL: %s\n", log_domain, message);
+ }
+ abort();
+ } else if (log_level & (G_LOG_LEVEL_WARNING)) {
+ if (def_log_domain) {
+ g_printerr("WARNING: %s\n", message);
+ } else {
+ g_printerr("%s WARNING: %s\n", log_domain, message);
+ }
+ } else {
+ if (def_log_domain) {
+ g_print("%s\n", message);
+ } else {
+ g_print("%s: %s\n", log_domain, message);
+ }
+ }
+}
+
+static void signal_func(int signum)
+{
+ g_main_loop_quit(main_loop);
+}
+
static gboolean x_watch_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
XEvent e;
@@ -90,6 +132,8 @@ int main(int argc, char *argv[])
GError *error = NULL;
GOptionContext *context;
+ g_log_set_default_handler(log_func, NULL);
+
setlocale(LC_ALL, "");
g_type_init();
@@ -134,8 +178,12 @@ int main(int argc, char *argv[])
XFlush(x_dpy); // Flush X11 queue before blocking in the event loop
+ signal(SIGINT, )
+ g_debug("Server running");
+
g_main_loop_run(main_loop);
+ g_debug("Server ending");
xims_close();
g_source_remove(x_watch);