Implement and install a DesktopWidget for Keyboard

This commit is contained in:
Pierre Pronchery 2015-05-25 00:19:50 +02:00
parent 3855200b60
commit 331b65dd2a
5 changed files with 138 additions and 4 deletions

View File

@ -1,6 +1,6 @@
package=Keyboard
version=0.2.1
subdirs=data,include,po,src,tools
subdirs=data,include,po,src,src/widget,tools
config=h,sh
dist=COPYING,Makefile,config.h,config.sh

View File

@ -335,6 +335,7 @@ static void _new_mode(Keyboard * keyboard, KeyboardMode mode);
static void _new_mode_docked(Keyboard * keyboard);
static void _new_mode_embedded(Keyboard * keyboard);
static void _new_mode_popup(Keyboard * keyboard);
static void _new_mode_widget(Keyboard * keyboard);
static void _new_mode_windowed(Keyboard * keyboard);
Keyboard * keyboard_new(KeyboardPrefs * prefs)
@ -418,7 +419,8 @@ Keyboard * keyboard_new(KeyboardPrefs * prefs)
KLS_COUNT, KLS_SPECIAL)) != NULL)
gtk_box_pack_start(GTK_BOX(vbox), widget, TRUE, TRUE, 0);
gtk_widget_show(vbox);
if(prefs->mode != KEYBOARD_MODE_EMBEDDED)
if(prefs->mode != KEYBOARD_MODE_EMBEDDED
&& prefs->mode != KEYBOARD_MODE_WIDGET)
{
#if GTK_CHECK_VERSION(2, 10, 0)
/* create the systray icon */
@ -465,6 +467,9 @@ static void _new_mode(Keyboard * keyboard, KeyboardMode mode)
case KEYBOARD_MODE_POPUP:
_new_mode_popup(keyboard);
break;
case KEYBOARD_MODE_WIDGET:
_new_mode_widget(keyboard);
break;
case KEYBOARD_MODE_WINDOWED:
_new_mode_windowed(keyboard);
break;
@ -523,6 +528,20 @@ static void _new_mode_popup(Keyboard * keyboard)
on_keyboard_delete_event), keyboard);
}
static void _new_mode_widget(Keyboard * keyboard)
{
/* XXX hack */
#if GTK_CHECK_VERSION(3, 0, 0)
keyboard->window = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
#else
keyboard->window = gtk_hbox_new(FALSE, 4);
#endif
keyboard->width = 0;
keyboard->height = 0;
keyboard->x = 0;
keyboard->y = 0;
}
static void _new_mode_windowed(Keyboard * keyboard)
{
keyboard->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@ -633,7 +652,8 @@ void keyboard_show(Keyboard * keyboard, gboolean show)
keyboard->x, keyboard->y);
#endif
}
else if(keyboard->mode != KEYBOARD_MODE_EMBEDDED)
else if(keyboard->mode != KEYBOARD_MODE_EMBEDDED
&& keyboard->mode != KEYBOARD_MODE_WIDGET)
gtk_widget_hide(keyboard->window);
}

View File

@ -32,7 +32,8 @@ typedef enum _KeyboardMode
KEYBOARD_MODE_WINDOWED = 0,
KEYBOARD_MODE_DOCKED,
KEYBOARD_MODE_EMBEDDED,
KEYBOARD_MODE_POPUP
KEYBOARD_MODE_POPUP,
KEYBOARD_MODE_WIDGET
} KeyboardMode;
typedef struct _KeyboardPrefs

13
src/widget/project.conf Normal file
View File

@ -0,0 +1,13 @@
targets=keyboard
cflags_force=-W `pkg-config --cflags libDesktop x11`
cflags=-Wall -g -O2 -fPIC -pedantic
ldflags_force=`pkg-config --libs libDesktop x11` -lXtst -lintl
dist=Makefile
[keyboard]
type=plugin
sources=widget.c
install=$(LIBDIR)/Desktop/widget
[keyboard.c]
depends=../keyboard.h,../keyboard.c

100
src/widget/widget.c Normal file
View File

@ -0,0 +1,100 @@
/* $Id$ */
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Keyboard */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <gtk/gtk.h>
#include <System.h>
#include <Desktop.h>
#include "../callbacks.h"
#include "../common.h"
#include "../layout.h"
#include "../key.h"
#include "../keyboard.h"
#include "../callbacks.c"
#include "../common.c"
#include "../layout.c"
#include "../key.c"
#include "../keyboard.c"
/* KeyboardWidget */
/* private */
/* types */
typedef struct _DesktopWidgetPlugin
{
Keyboard * keyboard;
} KeyboardWidget;
/* prototypes */
static KeyboardWidget * _keyboard_init(char const * name);
static void _keyboard_destroy(KeyboardWidget * keyboard);
static GtkWidget * _keyboard_get_widget(KeyboardWidget * keyboard);
/* public */
/* variables */
DesktopWidgetDefinition widget =
{
"Keyboard",
"input-keyboard",
NULL,
_keyboard_init,
_keyboard_destroy,
_keyboard_get_widget
};
/* private */
/* functions */
/* keyboard_init */
static KeyboardWidget * _keyboard_init(char const * name)
{
KeyboardWidget * keyboard;
KeyboardPrefs prefs;
if((keyboard = object_new(sizeof(*keyboard))) == NULL)
return NULL;
prefs.monitor = -1;
prefs.font = NULL;
prefs.mode = KEYBOARD_MODE_WIDGET;
prefs.wait = 0;
if((keyboard->keyboard = keyboard_new(&prefs)) == NULL)
{
_keyboard_destroy(keyboard);
return NULL;
}
return keyboard;
}
/* keyboard_destroy */
static void _keyboard_destroy(KeyboardWidget * keyboard)
{
if(keyboard->keyboard != NULL)
keyboard_delete(keyboard->keyboard);
object_delete(keyboard);
}
/* accessors */
/* keyboard_get_widget */
static GtkWidget * _keyboard_get_widget(KeyboardWidget * keyboard)
{
return keyboard_get_widget(keyboard->keyboard);
}