erkeybd.c File Reference

#include <glib.h>
#include <gtk/gtk.h>
#include "ergtk-keyb.h"
#include "logging.h"
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <signal.h>
Include dependency graph for erkeybd.c:

Go to the source code of this file.

Data Structures

struct  _KeybUI

Typedefs

typedef struct _KeybUI KeybUI

Functions

static void on_sigterm (int signo)
static gboolean my_io_callback (GIOChannel *source, GIOCondition condition, gpointer data)
static gint realize_keyboard (KeybUI *ui)
static gint keyboard_show (KeybUI *ui)
static gint keyboard_hide (KeybUI *ui)
static gint destroy_keyboard (KeybUI *ui)
static gboolean finish_app_cb (GtkWidget *widget, gpointer data)
int main (int argc, char **argv)

Variables

static KeybUI g_keybui

Typedef Documentation

typedef struct _KeybUI KeybUI

Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 65 of file erkeybd.c.


Function Documentation

static gint destroy_keyboard ( KeybUI ui  )  [static]

Definition at line 307 of file erkeybd.c.

References DBG_ASSERT, DBG_ENTRY, DBG_EXIT, _KeybUI::is_visible, and _KeybUI::window.

Referenced by my_io_callback().

00308 {
00309     DBG_ENTRY;
00310     DBG_ASSERT( ui != NULL ) ;
00311     DBG_ASSERT(ui->window != NULL ) ;
00312     
00313     gtk_widget_hide_all(ui->window);
00314     ui->is_visible = FALSE;
00315     gtk_widget_destroy(ui->window);
00316 
00317     DBG_EXIT;
00318     return 0;
00319 }

Here is the caller graph for this function:

static gboolean finish_app_cb ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 321 of file erkeybd.c.

References _KeybUI::alignment, DBG_ASSERT, DBG_ENTRY, DBG_EXIT, _KeybUI::is_visible, _KeybUI::keyb, _KeybUI::sock_io_chan, and _KeybUI::window.

Referenced by realize_keyboard().

00322 {
00323     DBG_ENTRY;
00324     KeybUI* k = (KeybUI*) data;
00325 
00326     DBG_ASSERT( k->window     == NULL ) ;
00327     DBG_ASSERT( k->keyb       == NULL ) ;
00328     DBG_ASSERT( k->alignment  == NULL ) ;
00329     DBG_ASSERT( k->is_visible == FALSE ) ;
00330 
00331     /* remove the watch from the main event loop and close the GIOChannel */
00332     g_io_channel_shutdown(k->sock_io_chan, FALSE, NULL);
00333     g_io_channel_unref(k->sock_io_chan);
00334     k->sock_io_chan = NULL ; 
00335 
00336     gtk_main_quit();
00337     DBG_EXIT;
00338     return FALSE;
00339 }

Here is the caller graph for this function:

static gint keyboard_hide ( KeybUI ui  )  [static]

Definition at line 288 of file erkeybd.c.

References DBG, DBG_ASSERT, DBG_ENTRY, DBG_EXIT, _KeybUI::is_visible, and _KeybUI::window.

Referenced by my_io_callback().

00289 {
00290     DBG_ENTRY;
00291     DBG_ASSERT( ui != NULL ) ;
00292     DBG_ASSERT( ui->window != NULL ) ;
00293 
00294     if ( ui->is_visible == TRUE  )
00295     {
00296         gtk_widget_hide_all(ui->window);
00297         ui->is_visible = FALSE;
00298     }
00299     else {
00300         DBG("Keyboard is already hidden!\n");
00301     }
00302 
00303     DBG_EXIT;
00304     return 0;
00305 }

Here is the caller graph for this function:

static gint keyboard_show ( KeybUI ui  )  [static]

Definition at line 267 of file erkeybd.c.

References DBG, DBG_ASSERT, DBG_ENTRY, DBG_EXIT, ERGTK_KEYB, ergtk_keyb_reset_keymap(), _KeybUI::is_visible, _KeybUI::keyb, and _KeybUI::window.

Referenced by my_io_callback().

00268 {
00269     DBG_ENTRY;
00270     DBG_ASSERT( ui != NULL ) ;
00271     DBG_ASSERT( ui->window != NULL ) ;
00272 
00273     ergtk_keyb_reset_keymap(ERGTK_KEYB(ui->keyb));
00274 
00275     if ( ui->is_visible == FALSE  )
00276     {
00277         gtk_widget_show_all(ui->window);
00278         ui->is_visible = TRUE;
00279     }
00280     else {
00281         DBG("Keyboard is already visible!\n");
00282     }
00283 
00284     DBG_EXIT;
00285     return 0;
00286 }

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 150 of file erkeybd.c.

References buffer, DBG_ASSERT, DBG_ENTRY, DBG_EXIT, my_io_callback(), on_sigterm(), realize_keyboard(), and _KeybUI::sock_io_chan.

00151 {
00152     DBG_ENTRY;
00153 
00154     struct sigaction on_term;
00155     int        sockfd = -1;
00156     int        error = 0;
00157     struct     sockaddr_in server_addr;
00158 
00159     gchar      buffer[512];
00160     memset(buffer, 0x0, sizeof(buffer));
00161 
00162     memset(&on_term, 0x00, sizeof(on_term));
00163     on_term.sa_handler = on_sigterm;
00164     sigaction(SIGTERM, &on_term, NULL);
00165 #if LOGGING_ON
00166     sigaction(SIGINT,  &on_term, NULL);
00167 #endif
00168 
00169     sockfd = socket(PF_INET, SOCK_DGRAM, 0);
00170     server_addr.sin_family = AF_INET;
00171     server_addr.sin_port = htons(60666);
00172     server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
00173     memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero));
00174 
00175     error = bind(sockfd, (struct sockaddr*) &server_addr, sizeof(server_addr));
00176 
00177     if (error)
00178     {
00179         perror("Error invoking bind");
00180         return 0;
00181     }
00182 
00183     gtk_init(&argc, &argv);
00184 
00185     g_keybui.sock_io_chan = NULL ; 
00186     g_keybui.sock_io_chan = g_io_channel_unix_new(sockfd) ;
00187     DBG_ASSERT( g_keybui.sock_io_chan != NULL  ) ;
00188 
00189     realize_keyboard(&g_keybui);
00190 
00191     g_io_channel_set_encoding(g_keybui.sock_io_chan, NULL, NULL  );
00192     g_io_add_watch( g_keybui.sock_io_chan, G_IO_IN, my_io_callback, NULL );
00193 
00194     gtk_main();
00195 
00196     close(sockfd);
00197 
00198     DBG_EXIT;
00199     return 0;
00200 }

Here is the call graph for this function:

static gboolean my_io_callback ( GIOChannel *  source,
GIOCondition  condition,
gpointer  data 
) [static]

Definition at line 110 of file erkeybd.c.

References DBG, DBG_ASSERT, DBG_ENTRY, DBG_EXIT, destroy_keyboard(), keyboard_hide(), and keyboard_show().

Referenced by main().

00111 {
00112     DBG_ENTRY;
00113 
00114     char* tmp = NULL ; 
00115 
00116     GString* buf = g_string_new(NULL);
00117 
00118     g_io_channel_read_line_string( source, buf, NULL, NULL);
00119     tmp = (char*) buf->str; 
00120 
00121     DBG(" Received -- %s", tmp );
00122 
00123     if (strcasecmp(tmp, "Keyboard-Show\n") == 0)
00124     {
00125         DBG("Showing Keyboard!\n");
00126         keyboard_show(&g_keybui);
00127     }
00128     else if (strcasecmp(tmp, "Keyboard-Hide\n") == 0)
00129     {
00130         DBG("Hiding Keyboard!\n");
00131         keyboard_hide(&g_keybui);
00132     }
00133     else if (strcasecmp(tmp, "Keyboard-Destroy\n") == 0)
00134     {
00135         DBG("Destroying Keyboard!\n");
00136         destroy_keyboard(&g_keybui);
00137     }
00138 
00139 
00140     tmp = NULL ;
00141     tmp = (char*) g_string_free(buf, TRUE);
00142     DBG_ASSERT( tmp == NULL );
00143 
00144     DBG_EXIT;
00145 
00146     return TRUE;
00147 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_sigterm ( int  signo  )  [static]

Definition at line 99 of file erkeybd.c.

References DBG, DBG_ENTRY, and DBG_EXIT.

Referenced by main().

00100 {
00101     DBG_ENTRY;
00102 
00103     DBG("erkeybd: Caught SIGNAL (%d), exiting...  my pid [%d]", getpid(), signo);
00104 
00105     gtk_main_quit();
00106 
00107     DBG_EXIT;
00108 }

Here is the caller graph for this function:

static gint realize_keyboard ( KeybUI ui  )  [static]

Definition at line 203 of file erkeybd.c.

References _KeybUI::alignment, DBG_ASSERT, DBG_ENTRY, DBG_EXIT, ergtk_keyb_new(), finish_app_cb(), _KeybUI::is_visible, _KeybUI::keyb, and _KeybUI::window.

Referenced by main().

00204 {
00205     DBG_ENTRY;
00206 
00207     DBG_ASSERT( ui != NULL ) ;
00208 
00209     ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00210     
00211     gtk_signal_connect(
00212             GTK_OBJECT(ui->window),
00213             "destroy", 
00214             GTK_SIGNAL_FUNC(gtk_widget_destroyed), 
00215             (gpointer)&ui->window
00216             );
00217     
00218 
00219     ui->alignment = gtk_alignment_new(0.5, 0.0, 0.0, 0.0);
00220     gtk_signal_connect(
00221             GTK_OBJECT(ui->alignment),
00222             "destroy", 
00223             GTK_SIGNAL_FUNC(gtk_widget_destroyed), 
00224             (gpointer)&ui->alignment
00225             );
00226 
00227     // ui->vbox = gtk_vbox_new(3,FALSE);
00228     ui->keyb = ergtk_keyb_new();
00229     gtk_signal_connect(
00230             GTK_OBJECT(ui->keyb),
00231             "destroy", 
00232             GTK_SIGNAL_FUNC(gtk_widget_destroyed), 
00233             (gpointer)&ui->keyb
00234             );
00235     g_signal_connect(
00236             G_OBJECT(ui->keyb), 
00237             "destroy", 
00238             G_CALLBACK(finish_app_cb), 
00239             (gpointer) &g_keybui 
00240             );
00241 
00242     gtk_container_add(GTK_CONTAINER(ui->alignment), ui->keyb);
00243     gtk_widget_show(ui->keyb);
00244 
00245     gtk_container_add(GTK_CONTAINER(ui->window), ui->alignment);
00246     gtk_widget_show(ui->alignment);
00247 
00248     gtk_window_set_title(GTK_WINDOW(ui->window), "erkeyb");
00249     gtk_container_set_border_width(GTK_CONTAINER(ui->window), 10);
00250     gtk_window_set_resizable(GTK_WINDOW(ui->window),FALSE);
00251 
00252     // use hint DOCK so it is hidden for fullscreen windows
00253     gtk_window_set_type_hint(GTK_WINDOW(ui->window), GDK_WINDOW_TYPE_HINT_DOCK);
00254     gtk_window_set_decorated(GTK_WINDOW(ui->window), FALSE);
00255     gtk_window_set_accept_focus(GTK_WINDOW(ui->window), FALSE);
00256 
00257     // resize and move to dock at the botton of the screen
00258     gtk_window_move(GTK_WINDOW(ui->window), 0, gdk_screen_height());
00259     gtk_window_set_resizable(GTK_WINDOW(ui->window), FALSE);
00260 
00261     ui->is_visible = FALSE;
00262 
00263     DBG_EXIT;
00264     return 0;
00265 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

KeybUI g_keybui [static]

Definition at line 80 of file erkeybd.c.

Generated by  doxygen 1.6.2-20100208