Skip to content

Commit 71c6bfb

Browse files
committed
refactor(linux): Reformat file
1 parent 38b8cf7 commit 71c6bfb

File tree

1 file changed

+72
-80
lines changed

1 file changed

+72
-80
lines changed

linux/ibus-keyman/src/main.c

Lines changed: 72 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -23,125 +23,117 @@
2323

2424
#include <ibus.h>
2525
#include <locale.h>
26-
#include <stdlib.h>
2726
#include <stdio.h>
28-
#include "keymanutil.h"
27+
#include <stdlib.h>
2928
#include "engine.h"
3029
#include "keyman-service.h"
30+
#include "keymanutil.h"
3131

32-
static IBusBus *bus = NULL;
32+
static IBusBus *bus = NULL;
3333
static IBusFactory *factory = NULL;
3434

3535
/* options */
36-
static gboolean xml = FALSE;
36+
static gboolean xml = FALSE;
3737
static gboolean ibus = FALSE;
38-
gboolean testing = FALSE;
39-
40-
static const GOptionEntry entries[] =
41-
{
42-
{ "xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL },
43-
{ "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
44-
{ "testing", 0, 0, G_OPTION_ARG_NONE, &testing, "component is executed by integration testing", NULL},
45-
{ NULL },
38+
gboolean testing = FALSE;
39+
40+
static const GOptionEntry entries[] = {
41+
{"xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL},
42+
{"ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL},
43+
{"testing", 0, 0, G_OPTION_ARG_NONE, &testing, "component is executed by integration testing", NULL},
44+
{NULL},
4645
};
4746

4847
// Add an environment variable to see debug messages: export G_MESSAGES_DEBUG=all
4948

5049
static void
51-
ibus_disconnected_cb (IBusBus *unused_bus,
52-
gpointer unused_data)
53-
{
54-
g_debug ("bus disconnected");
55-
KeymanService *service = km_service_get_default(NULL);
56-
g_clear_object(&service);
50+
ibus_disconnected_cb(IBusBus *unused_bus, gpointer unused_data) {
51+
g_debug("bus disconnected");
52+
KeymanService *service = km_service_get_default(NULL);
53+
g_clear_object(&service);
5754

58-
g_object_unref(factory);
59-
g_object_unref(bus);
55+
g_object_unref(factory);
56+
g_object_unref(bus);
6057

61-
ibus_quit ();
58+
ibus_quit();
6259
}
6360

64-
6561
static void
66-
start_component (void)
67-
{
68-
GList *engines, *p;
69-
IBusComponent *component;
62+
start_component(void) {
63+
GList *engines, *p;
64+
IBusComponent *component;
7065

71-
ibus_init ();
66+
ibus_init();
7267

73-
bus = ibus_bus_new ();
74-
g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
68+
bus = ibus_bus_new();
69+
g_signal_connect(bus, "disconnected", G_CALLBACK(ibus_disconnected_cb), NULL);
7570

76-
component = ibus_keyman_get_component ();
71+
component = ibus_keyman_get_component();
7772

78-
factory = ibus_factory_new (ibus_bus_get_connection (bus));
73+
factory = ibus_factory_new(ibus_bus_get_connection(bus));
7974

80-
engines = ibus_component_get_engines (component);
81-
for (p = engines; p != NULL; p = p->next) {
82-
IBusEngineDesc *engine = (IBusEngineDesc *)p->data;
83-
#if IBUS_CHECK_VERSION(1,3,99)
84-
const gchar *engine_name = ibus_engine_desc_get_name (engine);
75+
engines = ibus_component_get_engines(component);
76+
for (p = engines; p != NULL; p = p->next) {
77+
IBusEngineDesc *engine = (IBusEngineDesc *)p->data;
78+
#if IBUS_CHECK_VERSION(1, 3, 99)
79+
const gchar *engine_name = ibus_engine_desc_get_name(engine);
8580
#else
86-
const gchar *engine_name = engine->name;
87-
#endif /* !IBUS_CHECK_VERSION(1,3,99) */
88-
ibus_factory_add_engine (factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE);
89-
}
90-
91-
if (ibus) {
92-
ibus_bus_request_name (bus, "org.freedesktop.IBus.Keyman", 0);
93-
}
94-
else {
95-
ibus_bus_register_component (bus, component);
96-
}
97-
98-
g_object_unref (component);
99-
km_service_get_default(NULL); // initialise dbus service
100-
101-
ibus_main ();
81+
const gchar *engine_name = engine->name;
82+
#endif /* !IBUS_CHECK_VERSION(1,3,99) */
83+
ibus_factory_add_engine(factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE);
84+
}
85+
86+
if (ibus) {
87+
ibus_bus_request_name(bus, "org.freedesktop.IBus.Keyman", 0);
88+
} else {
89+
ibus_bus_register_component(bus, component);
90+
}
91+
92+
g_object_unref(component);
93+
km_service_get_default(NULL); // initialise dbus service
94+
95+
ibus_main();
10296
}
10397

10498
static void
105-
print_engines_xml (void)
106-
{
107-
IBusComponent *component;
108-
GString *output;
99+
print_engines_xml(void) {
100+
IBusComponent *component;
101+
GString *output;
109102

110-
ibus_init ();
103+
ibus_init();
111104

112-
component = ibus_keyman_get_component ();
113-
output = g_string_new ("");
105+
component = ibus_keyman_get_component();
106+
output = g_string_new("");
114107

115-
ibus_component_output_engines (component, output, 0);
108+
ibus_component_output_engines(component, output, 0);
116109

117-
fprintf (stdout, "%s", output->str);
110+
fprintf(stdout, "%s", output->str);
118111

119-
g_string_free (output, TRUE);
120-
g_object_unref(component);
112+
g_string_free(output, TRUE);
113+
g_object_unref(component);
121114
}
122115

123116
int
124-
main (gint argc, gchar **argv)
125-
{
126-
GError *error = NULL;
127-
GOptionContext *context;
117+
main(gint argc, gchar **argv) {
118+
GError *error = NULL;
119+
GOptionContext *context;
128120

129-
setlocale (LC_ALL, "");
121+
setlocale(LC_ALL, "");
130122

131-
context = g_option_context_new ("- ibus Keyman engine component");
123+
context = g_option_context_new("- ibus Keyman engine component");
132124

133-
g_option_context_add_main_entries (context, entries, "ibus-keyman");
125+
g_option_context_add_main_entries(context, entries, "ibus-keyman");
134126

135-
if (!g_option_context_parse (context, &argc, &argv, &error)) {
136-
g_print ("Option parsing failed: %s\n", error->message);
137-
exit (-1);
138-
}
127+
if (!g_option_context_parse(context, &argc, &argv, &error)) {
128+
g_print("Option parsing failed: %s\n", error->message);
129+
exit(-1);
130+
}
139131

140-
if (xml) {
141-
print_engines_xml ();
142-
exit (0);
143-
}
132+
if (xml) {
133+
print_engines_xml();
134+
exit(0);
135+
}
144136

145-
start_component ();
146-
return 0;
137+
start_component();
138+
return 0;
147139
}

0 commit comments

Comments
 (0)