| 1 |
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ |
| 2 |
/* vim:set et sts=4: */ |
| 3 |
/* ibus - The Input Bus |
| 4 |
* Copyright (C) 2023-2024 Takao Fujiwara <[email protected]> |
| 5 |
* Copyright (C) 2023-2024 Red Hat, Inc. |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public License |
| 9 |
* as published by the Free Software Foundation; either version 2.1 of |
| 10 |
* the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 |
* 02110-1301 USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
|
| 25 |
#include <ibus.h> |
| 26 |
#include <wayland-client-core.h> |
| 27 |
#include <stdlib.h> |
| 28 |
|
| 29 |
#include "ibuswaylandim.h" |
| 30 |
|
| 31 |
extern GSource *ibus_wayland_source_new (struct wl_display *display); |
| 32 |
|
| 33 |
static void |
| 34 |
_bus_disconnected_cb (IBusBus *bus, |
| 35 |
gpointer user_data) |
| 36 |
{ |
| 37 |
g_debug ("Connection closed by ibus-daemon\n"); |
| 38 |
g_clear_object (&bus); |
| 39 |
ibus_quit (); |
| 40 |
} |
| 41 |
|
| 42 |
gint |
| 43 |
main (gint argc, |
| 44 |
gchar **argv) |
| 45 |
{ |
| 46 |
IBusBus *bus; |
| 47 |
struct wl_display *display; |
| 48 |
IBusWaylandIM *wlim; |
| 49 |
GSource *source; |
| 50 |
|
| 51 |
ibus_init (); |
| 52 |
|
| 53 |
bus = ibus_bus_new (); |
| 54 |
if (!ibus_bus_is_connected (bus)) { |
| 55 |
g_printerr ("Cannot connect to ibus-daemon\n"); |
| 56 |
return EXIT_FAILURE; |
| 57 |
} |
| 58 |
|
| 59 |
if (!(display = wl_display_connect (NULL))) { |
| 60 |
g_printerr ("Cannot open Wayland display\n"); |
| 61 |
return EXIT_FAILURE; |
| 62 |
} |
| 63 |
wlim = ibus_wayland_im_new ("wl_display", display, "bus", bus, NULL); |
| 64 |
g_return_val_if_fail (wlim, EXIT_FAILURE); |
| 65 |
|
| 66 |
source = ibus_wayland_source_new (display); |
| 67 |
g_source_set_priority (source, G_PRIORITY_DEFAULT); |
| 68 |
g_source_set_can_recurse (source, TRUE); |
| 69 |
g_source_attach (source, NULL); |
| 70 |
|
| 71 |
g_signal_connect (bus, "disconnected", |
| 72 |
G_CALLBACK (_bus_disconnected_cb), NULL); |
| 73 |
ibus_main (); |
| 74 |
|
| 75 |
return EXIT_SUCCESS; |
| 76 |
} |
| 77 |
|