Mercurial > projects > xwrited
annotate xwd-application.c @ 19:f0accfc74f7b
Port to GLib version 2.48 or later
Use GApplication instead of the custom XWritedUnique object for uniqueness.
Use GNotification from GIO instead of libnotify.
Remove help and debug options from documentation.
Replace intltool with GNU gettext (version 0.19 or later required).
author | Guido Berhoerster <guido+xwrited@berhoerster.name> |
---|---|
date | Sat, 28 Jul 2018 22:02:24 +0200 |
parents | |
children | 683ebd334b21 |
rev | line source |
---|---|
19
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
1 /* |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
2 * Copyright (C) 2018 Guido Berhoerster <guido+xwrited@berhoerster.name> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
3 * |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
10 * the following conditions: |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
11 * |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
13 * in all copies or substantial portions of the Software. |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
14 * |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
22 */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
23 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
24 #include <errno.h> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
25 #include <fcntl.h> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
26 #include <glib-unix.h> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
27 #include <glib/gi18n.h> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
28 #include <stdio.h> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
29 #include <stdlib.h> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
30 #include <string.h> |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
31 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
32 #include "xwd-application.h" |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
33 #include "xwd-utmp.h" |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
34 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
35 #define BUFFER_TIMEOUT 500 /* ms */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
36 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
37 struct _XwdApplication { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
38 GApplication parent_instance; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
39 gint masterfd; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
40 gint slavefd; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
41 GIOChannel *master_pty_chan; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
42 guint buffer_timeout_id; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
43 GString *message_buf; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
44 }; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
45 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
46 G_DEFINE_TYPE(XwdApplication, xwd_application, G_TYPE_APPLICATION) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
47 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
48 static void xwd_application_quit(GSimpleAction *, GVariant *, gpointer); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
49 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
50 static const GOptionEntry cmd_options[] = { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
51 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
52 N_("Enable debugging messages"), NULL }, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
53 { "quit", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
54 N_("Quit running instance of xwrited"), NULL }, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
55 { "version", 'V', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
56 N_("Print the version number and quit"), NULL }, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
57 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL, NULL, NULL }, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
58 { NULL } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
59 }; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
60 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
61 static const GActionEntry xwd_application_actions[] = { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
62 { "quit", xwd_application_quit } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
63 }; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
64 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
65 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
66 xwd_application_quit(GSimpleAction *simple, GVariant *parameter, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
67 gpointer user_data) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
68 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
69 XwdApplication *self = user_data; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
70 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
71 g_application_quit(G_APPLICATION(self)); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
72 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
73 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
74 static gboolean |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
75 on_signal(gpointer user_data) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
76 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
77 XwdApplication *self = user_data; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
78 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
79 g_debug("received signal, exiting"); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
80 g_action_group_activate_action(G_ACTION_GROUP(G_APPLICATION(self)), |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
81 "quit", NULL); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
82 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
83 return (TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
84 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
85 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
86 static GString * |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
87 string_copy(GString *dest, GString *src) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
88 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
89 g_string_truncate(dest, 0); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
90 g_string_append(dest, src->str); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
91 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
92 return (dest); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
93 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
94 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
95 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
96 string_to_valid_utf8(GString *string) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
97 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
98 GString *result; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
99 gchar *start = string->str; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
100 gchar *end; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
101 gsize remaining = string->len; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
102 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
103 result = g_string_sized_new(string->len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
104 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
105 while (remaining > 0) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
106 if (g_utf8_validate(start, remaining, (const gchar **)&end)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
107 /* remaining part is valid */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
108 g_string_append_len(result, start, remaining); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
109 break; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
110 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
111 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
112 /* append valid part */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
113 g_string_append_len(result, start, end - start); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
114 /* |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
115 * replace first invalid byte with Unicode "REPLACEMENT |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
116 * CHARACTER" (U+FFFD) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
117 */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
118 g_string_append(result, "\357\277\275"); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
119 remaining -= (end - start) + 1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
120 start = end + 1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
121 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
122 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
123 string_copy(string, result); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
124 g_string_free(result, TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
125 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
126 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
127 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
128 string_trim_lines(GString *string) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
129 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
130 GString *result; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
131 gchar *p = string->str; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
132 gchar *q; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
133 gsize line_len; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
134 gsize remaining = string->len; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
135 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
136 result = g_string_sized_new(string->len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
137 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
138 while (remaining > 0) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
139 q = memchr(p, '\n', remaining); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
140 if (q == NULL) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
141 g_string_append_len(result, p, remaining); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
142 break; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
143 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
144 line_len = q - p - 1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
145 /* convert \r\n to \n */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
146 if ((line_len > 0) && (p[line_len - 1] == '\r')) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
147 line_len--; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
148 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
149 /* trim spaces on the right */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
150 while ((line_len > 0) && (p[line_len - 1] == ' ')) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
151 line_len--; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
152 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
153 g_string_append_len(result, p, line_len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
154 g_string_append_c(result, '\n'); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
155 remaining -= q + 1 - p; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
156 p = q + 1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
157 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
158 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
159 string_copy(string, result); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
160 g_string_free(result, TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
161 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
162 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
163 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
164 string_filter_nonprintable(GString *string) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
165 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
166 GString *result; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
167 const gchar *p; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
168 gunichar c; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
169 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
170 result = g_string_sized_new(string->len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
171 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
172 for (p = string->str; *p != '\0'; p = g_utf8_next_char(p)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
173 c = g_utf8_get_char(p); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
174 if (g_unichar_isprint(c) || g_unichar_isspace(c)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
175 g_string_append_unichar(result, c); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
176 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
177 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
178 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
179 string_copy(string, result); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
180 g_string_free(result, TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
181 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
182 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
183 static gchar * |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
184 hexdumpa(const void *mem, gsize n) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
185 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
186 const guchar *bytes = mem; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
187 GString *string; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
188 gsize i; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
189 gsize j; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
190 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
191 string = g_string_sized_new((n / 16 + (n % 16 > 0)) * 76); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
192 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
193 for (i = 0; i < n; i += 16) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
194 g_string_append_printf(string, "%08zx ", i); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
195 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
196 for (j = 0; (i + j < n) && (j < 16); j++) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
197 g_string_append_printf(string, " %02x", bytes[i + j]); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
198 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
199 for (; j < 16; j++) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
200 g_string_append(string, " "); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
201 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
202 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
203 g_string_append(string, " "); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
204 for (j = 0; (i + j < n) && (j < 16); j++) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
205 g_string_append_printf(string, "%c", |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
206 g_ascii_isprint(bytes[i + j]) ? bytes[i + j] : '.'); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
207 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
208 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
209 g_string_append_c(string, '\n'); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
210 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
211 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
212 return (g_string_free(string, FALSE)); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
213 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
214 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
215 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
216 display_message(XwdApplication *self) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
217 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
218 gboolean enable_debug_logging; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
219 gchar *message_dump; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
220 GString *message; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
221 GIcon *icon; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
222 GNotification *notification; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
223 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
224 if (self->message_buf->len == 0) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
225 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
226 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
227 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
228 enable_debug_logging = (g_getenv("G_MESSAGES_DEBUG") != NULL); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
229 if (enable_debug_logging) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
230 message_dump = hexdumpa(self->message_buf->str, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
231 self->message_buf->len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
232 g_debug("raw message:\n%s", message_dump); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
233 g_free(message_dump); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
234 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
235 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
236 /* |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
237 * There is no reliable way to determine the character encoding of the |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
238 * received message which, depending on the locale of the sender, may |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
239 * even differ for different messages. A user could even send binary |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
240 * data. It is thus assumed that messages are in UTF-8 encoding which |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
241 * should be the most common case on modern systems. Any invalid |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
242 * sequences are replaced with the Unicode "REPLACEMENT CHARACTER" |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
243 * (U+FFFD) and non-printable characters are removed. Additionally, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
244 * padding typically added by wall(1) implementations is removed in |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
245 * order to improve readability. |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
246 */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
247 message = g_string_new_len(self->message_buf->str, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
248 self->message_buf->len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
249 string_to_valid_utf8(message); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
250 string_filter_nonprintable(message); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
251 string_trim_lines(message); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
252 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
253 if (enable_debug_logging) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
254 message_dump = hexdumpa(message->str, message->len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
255 g_debug("message:\n%s", message_dump); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
256 g_free(message_dump); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
257 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
258 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
259 icon = g_themed_icon_new("utilities-terminal"); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
260 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
261 notification = g_notification_new(_("Message received")); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
262 g_notification_set_icon(notification, icon); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
263 g_notification_set_body(notification, message->str); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
264 g_application_send_notification(G_APPLICATION(self), NULL, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
265 notification); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
266 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
267 g_object_unref(notification); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
268 g_object_unref(icon); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
269 g_string_free(message, TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
270 g_string_truncate(self->message_buf, 0); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
271 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
272 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
273 static gboolean |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
274 on_buffer_timeout(gpointer user_data) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
275 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
276 XwdApplication *self = user_data; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
277 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
278 display_message(self); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
279 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
280 self->buffer_timeout_id = 0; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
281 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
282 return (FALSE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
283 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
284 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
285 static gboolean |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
286 on_master_pty_readable(GIOChannel *source, GIOCondition cond, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
287 gpointer user_data) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
288 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
289 XwdApplication *self = user_data; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
290 GIOStatus status; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
291 gchar buf[BUFSIZ]; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
292 gsize buf_len = 0; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
293 GError *error = NULL; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
294 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
295 if (cond & G_IO_IN) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
296 /* read message data from master pty */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
297 memset(buf, 0, sizeof (buf)); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
298 while ((status = g_io_channel_read_chars(source, (gchar *)&buf, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
299 sizeof (buf), &buf_len, &error)) == G_IO_STATUS_NORMAL) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
300 if (buf_len > 0) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
301 g_debug("read %" G_GSSIZE_FORMAT " bytes from " |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
302 "master pty", buf_len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
303 g_string_append_len(self->message_buf, buf, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
304 buf_len); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
305 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
306 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
307 if (error != NULL) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
308 g_critical("failed to read from master pty: %s", |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
309 error->message); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
310 g_error_free(error); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
311 return (FALSE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
312 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
313 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
314 /* |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
315 * a message might be read in several parts and it is not |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
316 * possible to reliably detect the beginning or end of a |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
317 * message, so buffer read data until a short timeout is |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
318 * reached as this works well for a single message which should |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
319 * be the most common case |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
320 */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
321 if (self->buffer_timeout_id == 0) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
322 self->buffer_timeout_id = g_timeout_add(BUFFER_TIMEOUT, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
323 on_buffer_timeout, self); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
324 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
325 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
326 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
327 if (cond & (G_IO_HUP | G_IO_ERR)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
328 g_critical("connection to master pty broken"); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
329 return (FALSE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
330 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
331 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
332 return (TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
333 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
334 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
335 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
336 xwd_application_startup(GApplication *application) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
337 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
338 XwdApplication *self = XWD_APPLICATION(application); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
339 gchar *slave_name; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
340 GIOFlags flags; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
341 GError *error = NULL; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
342 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
343 G_APPLICATION_CLASS(xwd_application_parent_class)->startup(application); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
344 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
345 /* create actions */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
346 g_action_map_add_action_entries(G_ACTION_MAP(self), |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
347 xwd_application_actions, G_N_ELEMENTS(xwd_application_actions), |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
348 self); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
349 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
350 /* create signal watchers */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
351 g_unix_signal_add(SIGINT, on_signal, self); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
352 g_unix_signal_add(SIGTERM, on_signal, self); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
353 g_unix_signal_add(SIGHUP, on_signal, self); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
354 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
355 /* open master pty */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
356 self->masterfd = posix_openpt(O_RDWR | O_NOCTTY); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
357 if (self->masterfd == -1) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
358 g_critical("failed to open master pty: %s", g_strerror(errno)); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
359 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
360 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
361 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
362 /* create slave pty */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
363 if ((grantpt(self->masterfd) == -1) || |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
364 (unlockpt(self->masterfd) == -1)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
365 g_critical("failed to create slave pty: %s", g_strerror(errno)); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
366 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
367 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
368 slave_name = ptsname(self->masterfd); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
369 if (slave_name == NULL) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
370 g_critical("failed to obtain name of slave pty"); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
371 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
372 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
373 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
374 /* |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
375 * keep an open fd around order to prevent closing the master fd when |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
376 * receiving an EOF |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
377 */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
378 self->slavefd = open(slave_name, O_RDWR); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
379 if (self->slavefd == -1) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
380 g_critical("failed to open slave pty: %s", g_strerror(errno)); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
381 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
382 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
383 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
384 /* create a GIOChannel for monitoring the master pty for messages */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
385 self->master_pty_chan = g_io_channel_unix_new(self->masterfd); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
386 /* make it non-blocking */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
387 flags = g_io_channel_get_flags(self->master_pty_chan); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
388 if (g_io_channel_set_flags(self->master_pty_chan, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
389 flags | G_IO_FLAG_NONBLOCK, &error) != G_IO_STATUS_NORMAL) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
390 g_critical("failed set flags on the master pty channel: %s", |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
391 error->message); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
392 g_error_free(error); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
393 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
394 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
395 /* make the channel safe for encodings other than UTF-8 */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
396 if (g_io_channel_set_encoding(self->master_pty_chan, NULL, &error) != |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
397 G_IO_STATUS_NORMAL) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
398 g_critical("failed set encoding on the master pty channel: %s", |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
399 error->message); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
400 g_error_free(error); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
401 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
402 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
403 if (!g_io_add_watch(self->master_pty_chan, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
404 G_IO_IN | G_IO_HUP | G_IO_ERR, on_master_pty_readable, self)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
405 g_critical("failed to add watch on master pty channel"); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
406 return; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
407 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
408 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
409 xwd_utmp_add_entry(self->masterfd); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
410 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
411 /* keep GApplication running */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
412 g_application_hold(application); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
413 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
414 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
415 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
416 xwd_application_shutdown(GApplication *application) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
417 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
418 XwdApplication *self = XWD_APPLICATION(application); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
419 GApplicationClass *application_class = |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
420 G_APPLICATION_CLASS(xwd_application_parent_class); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
421 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
422 /* display any buffered data before exiting */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
423 display_message(self); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
424 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
425 if (self->master_pty_chan != NULL) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
426 g_io_channel_shutdown(self->master_pty_chan, FALSE, NULL); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
427 g_clear_pointer(&self->master_pty_chan, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
428 (GDestroyNotify)g_io_channel_unref); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
429 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
430 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
431 if (self->slavefd != -1) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
432 close(self->slavefd); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
433 self->slavefd = -1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
434 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
435 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
436 if (self->masterfd != -1) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
437 close(self->masterfd); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
438 self->masterfd = -1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
439 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
440 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
441 xwd_utmp_remove_entry(self->masterfd); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
442 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
443 /* remove signal watches and buffer timeout */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
444 while (g_source_remove_by_user_data(self)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
445 continue; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
446 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
447 self->buffer_timeout_id = 0; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
448 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
449 application_class->shutdown(application); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
450 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
451 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
452 static gint |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
453 xwd_application_handle_local_options(GApplication *application, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
454 GVariantDict *options) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
455 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
456 gchar **args = NULL; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
457 gchar *messages_debug; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
458 GError *error = NULL; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
459 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
460 /* filename arguments are not allowed */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
461 if (g_variant_dict_lookup(options, G_OPTION_REMAINING, "^a&ay", |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
462 &args)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
463 g_printerr("invalid argument: \"%s\"\n", args[0]); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
464 g_free(args); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
465 return (1); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
466 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
467 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
468 if (g_variant_dict_contains(options, "version")) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
469 g_print("%s %s\n", PACKAGE, VERSION); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
470 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
471 /* quit */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
472 return (0); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
473 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
474 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
475 if (g_variant_dict_contains(options, "debug")) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
476 /* enable debug logging */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
477 messages_debug = g_strjoin(":", G_LOG_DOMAIN, |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
478 g_getenv("G_MESSAGES_DEBUG"), NULL); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
479 g_setenv("G_MESSAGES_DEBUG", messages_debug, TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
480 g_free(messages_debug); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
481 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
482 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
483 /* |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
484 * register with the session bus so that it is possible to discern |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
485 * between remote and primary instance and that remote actions can be |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
486 * invoked, this causes the startup signal to be emitted which, in case |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
487 * of the primary instance, starts to instantiate the |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
488 * backend with the given values |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
489 */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
490 if (!g_application_register(application, NULL, &error)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
491 g_critical("g_application_register: %s", error->message); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
492 g_error_free(error); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
493 return (1); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
494 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
495 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
496 if (g_variant_dict_contains(options, "quit")) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
497 /* only valid if a remote instance is running */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
498 if (!g_application_get_is_remote(application)) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
499 g_printerr("%s is not running\n", g_get_prgname()); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
500 return (1); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
501 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
502 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
503 /* signal remote instance to quit */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
504 g_action_group_activate_action(G_ACTION_GROUP(application), |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
505 "quit", NULL); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
506 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
507 /* quit local instance */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
508 return (0); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
509 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
510 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
511 /* proceed with default command line processing */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
512 return (-1); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
513 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
514 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
515 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
516 xwd_application_activate(GApplication *application) { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
517 GApplicationClass *application_class = |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
518 G_APPLICATION_CLASS(xwd_application_parent_class); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
519 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
520 /* do nothing, implementation required by GApplication */ |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
521 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
522 application_class->activate(application); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
523 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
524 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
525 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
526 xwd_application_finalize(GObject *object) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
527 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
528 XwdApplication *self = XWD_APPLICATION(object); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
529 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
530 g_string_free(self->message_buf, TRUE); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
531 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
532 G_OBJECT_CLASS(xwd_application_parent_class)->finalize(object); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
533 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
534 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
535 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
536 xwd_application_class_init(XwdApplicationClass *klass) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
537 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
538 GObjectClass *object_class = G_OBJECT_CLASS(klass); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
539 GApplicationClass *application_class = G_APPLICATION_CLASS(klass); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
540 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
541 object_class->finalize = xwd_application_finalize; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
542 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
543 application_class->startup = xwd_application_startup; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
544 application_class->shutdown = xwd_application_shutdown; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
545 application_class->handle_local_options = |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
546 xwd_application_handle_local_options; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
547 application_class->activate = xwd_application_activate; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
548 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
549 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
550 static void |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
551 xwd_application_init(XwdApplication *self) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
552 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
553 g_application_add_main_option_entries(G_APPLICATION(self), |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
554 cmd_options); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
555 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
556 self->masterfd = -1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
557 self->slavefd = -1; |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
558 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
559 self->message_buf = g_string_sized_new(BUFSIZ); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
560 } |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
561 |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
562 XwdApplication * |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
563 xwd_application_new(void) |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
564 { |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
565 return (g_object_new(XWD_TYPE_APPLICATION, "application-id", |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
566 APPLICATION_ID, NULL)); |
f0accfc74f7b
Port to GLib version 2.48 or later
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
567 } |