summaryrefslogtreecommitdiff
path: root/modules/input/imbroadway.c
blob: 2fb40d471ec0c69c5ced91b3a4c2855469a1f4d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * gtkimmodulebroadway
 * Copyright (C) 2013 Alexander Larsson
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * $Id:$
 */

#include "config.h"
#include <string.h>

#include <gtk/gtk.h>
#include "gtk/gtkintl.h"
#include "gtk/gtkimmodule.h"

#include "gdk/broadway/gdkbroadway.h"

#define GTK_TYPE_IM_CONTEXT_BROADWAY (gtk_im_context_broadway_get_type ())
#define GTK_IM_CONTEXT_BROADWAY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_IM_CONTEXT_BROADWAY, GtkIMContextBroadway))
#define GTK_IM_CONTEXT_BROADWAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_IM_CONTEXT_BROADWAY, GtkIMContextBroadwayClass))

typedef struct _GtkIMContextBroadway
{
  GtkIMContextSimple parent;
  GtkWidget *client_widget;
} GtkIMContextBroadway;

typedef struct _GtkIMContextBroadwayClass
{
  GtkIMContextSimpleClass parent_class;
} GtkIMContextBroadwayClass;

G_DEFINE_DYNAMIC_TYPE (GtkIMContextBroadway, gtk_im_context_broadway, GTK_TYPE_IM_CONTEXT_SIMPLE)

void
g_io_module_load (GIOModule *module)
{
  g_type_module_use (G_TYPE_MODULE (module));

  g_print ("load io module for broadway\n");
  gtk_im_context_broadway_register_type (G_TYPE_MODULE (module));

  g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME,
                                  GTK_TYPE_IM_CONTEXT_BROADWAY,
                                  "broadway",
                                  10);
}

void
g_io_module_unload (GIOModule *module)
{
}

char **
g_io_module_query (void)
{
  char *eps[] = {
    GTK_IM_MODULE_EXTENSION_POINT_NAME,
    NULL
  };

  return g_strdupv (eps);
}


static void
broadway_set_client_widget (GtkIMContext *context, GtkWidget *widget)
{
  GtkIMContextBroadway *bw = GTK_IM_CONTEXT_BROADWAY (context);

  bw->client_widget = widget;
}

static void
broadway_focus_in (GtkIMContext *context)
{
  GtkIMContextBroadway *bw = GTK_IM_CONTEXT_BROADWAY (context);
  GdkDisplay *display;

  if (bw->client_widget)
    {
      display = gtk_widget_get_display (bw->client_widget);
      gdk_broadway_display_show_keyboard (GDK_BROADWAY_DISPLAY (display));
    }
}

static void
broadway_focus_out (GtkIMContext *context)
{
  GtkIMContextBroadway *bw = GTK_IM_CONTEXT_BROADWAY (context);
  GdkDisplay *display;

  if (bw->client_widget)
    {
      display = gtk_widget_get_display (bw->client_widget);
      gdk_broadway_display_hide_keyboard (GDK_BROADWAY_DISPLAY (display));
    }
}

static void
gtk_im_context_broadway_class_init (GtkIMContextBroadwayClass *class)
{
  GtkIMContextClass *klass = GTK_IM_CONTEXT_CLASS (class);

  klass->focus_in = broadway_focus_in;
  klass->focus_out = broadway_focus_out;
  klass->set_client_widget = broadway_set_client_widget;
}

static void
gtk_im_context_broadway_class_finalize (GtkIMContextBroadwayClass *class)
{
}

static void
gtk_im_context_broadway_init (GtkIMContextBroadway *im_context)
{
}