Skip to content

Commit

Permalink
Version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEN committed Dec 15, 2015
1 parent 0d8a1aa commit 50edee1
Show file tree
Hide file tree
Showing 46 changed files with 156 additions and 148 deletions.
9 changes: 6 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
## This Makefile.am is free software; the Free Software Foundation
## gives unlimited permission to copy, distribute and modify it.

SUBDIRS = images
EXTRA_DIST = COPYING CREDITS INSTALL NEWS

bin_PROGRAMS = gxkb
gxkb_SOURCES = gxkb.c xkb-callbacks.c xkb-config.c xkb-util.c
gxkb_CFLAGS = @GTK_CFLAGS@ @GLIB_CFLAGS@ @LIBXKLAVIER_CFLAGS@ @LIBWNCK_CFLAGS@
gxkb_LDFLAGS = @GTK_LIBS@ @GLIB_LIBS@ @LIBXKLAVIER_LIBS@ @LIBWNCK_LIBS@
gxkb_SOURCES = gxkb.c xkb-callbacks.c xkb-config.c xkb-util.c common.h xkb-callbacks.h xkb-config.h xkb-util.h
gxkb_CFLAGS = @GTK_CFLAGS@ @GLIB_CFLAGS@ @LIBXKLAVIER_CFLAGS@ @LIBWNCK_CFLAGS@ -DFLAGSDIR=\"$(datadir)/gxkb/flags\"
gxkb_LDADD = @GTK_LIBS@ @GLIB_LIBS@ @LIBXKLAVIER_LIBS@ @LIBWNCK_LIBS@
11 changes: 10 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
March 19 2013:
Version gxkb 0.3 released.
* add left-click menu with keyboard layout options
* add right-click menu with 'exit' and 'about' options
* add icons

March 18 2013:
Version gxkb 2.0 released.
Version gxkb 0.2 released.

March 11 2013:
Initial code base.
Empty file removed README
Empty file.
Empty file removed TODO
Empty file.
3 changes: 2 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ typedef struct
t_xkb_settings *settings; /* per-app setting and default group */

/* widgets */
GtkWidget *popup;
GtkWidget *lb_mouse_popup;
GtkWidget *rb_mouse_popup;
/* */
} t_xkb;

Expand Down
18 changes: 6 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
AC_INIT([gxkb], [2.0], [zen@root.ua])
AC_INIT([gxkb], [0.3], [zen@root.ua])
AM_INIT_AUTOMAKE([-Wall -Werror foreign ])
AC_CONFIG_SRCDIR([gxkb.c])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
AC_HEADER_STDC
PKG_PROG_PKG_CONFIG([0.20])
PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.24.10])
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.32.4])
PKG_CHECK_MODULES(LIBXKLAVIER, [libxklavier >= 5.2.1])
PKG_CHECK_MODULES(LIBWNCK, [libwnck-1.0 >= 2.30.7])
PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.20.0])
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.24.0])
PKG_CHECK_MODULES(LIBXKLAVIER, [libxklavier >= 5.0])
PKG_CHECK_MODULES(LIBWNCK, [libwnck-1.0 >= 2.30.0])
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
AC_SUBST(GLIB_CFLAGS)
Expand All @@ -19,13 +19,7 @@ AC_SUBST(LIBWNCK_CFLAGS)
AC_SUBST(LIBWNCK_LIBS)
AC_DEFINE(WNCK_I_KNOW_THIS_IS_UNSTABLE, 1, [libwnck is happy with this])
AC_DEFINE(HAVE_CONFIG_H,1,[Include config.h])
if test "x$prefix" = "xNONE" ; then
prefix="/usr/local"
fi
if test "x$exec_prefix" = "xNONE" ; then
exec_prefix=$prefix
fi
#AC_CONFIG_FILES([
#Makefile
#])
AC_OUTPUT([Makefile])
AC_OUTPUT([Makefile images/Makefile])
152 changes: 70 additions & 82 deletions gxkb.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ void xkb_initialize_menu (t_xkb *xkb);

void xkb_refresh (t_xkb *xkb);

GdkPixbuf * text_to_gtk_pixbuf (t_xkb *xkb, gchar *text);

void xkb_about (t_xkb *xkb);
/* ================================================================== *
* Implementation *
* ================================================================== */
Expand Down Expand Up @@ -80,11 +79,11 @@ xkb_new (GtkStatusIcon *tray)
xkb->settings = g_new0 (t_xkb_settings, 1);
xkb->tray = tray;

g_signal_connect (G_OBJECT(xkb->tray), "activate", G_CALLBACK (xkb_tray_icon_clicked), xkb);
g_signal_connect (G_OBJECT(xkb->tray), "scroll-event", G_CALLBACK (xkb_tray_icon_scrolled), xkb);
g_signal_connect(G_OBJECT(xkb->tray), "activate", G_CALLBACK (xkb_tray_icon_clicked), xkb);
g_signal_connect(G_OBJECT(xkb->tray), "scroll-event", G_CALLBACK (xkb_tray_icon_scrolled), xkb);
g_signal_connect(G_OBJECT(xkb->tray), "popup-menu", G_CALLBACK(xkb_tray_icon_popup_menu), xkb);

wnck_screen = wnck_screen_get_default ();
wnck_screen = wnck_screen_get_default();
g_signal_connect (G_OBJECT (wnck_screen), "active-window-changed",
G_CALLBACK (xkb_active_window_changed), xkb);
g_signal_connect (G_OBJECT (wnck_screen), "window-closed",
Expand All @@ -106,7 +105,8 @@ xkb_free (t_xkb *xkb)
g_free (xkb->settings);
g_object_unref (xkb->tray);

gtk_widget_destroy (xkb->popup);
gtk_widget_destroy (xkb->rb_mouse_popup);
gtk_widget_destroy (xkb->lb_mouse_popup);
}

void
Expand All @@ -117,7 +117,7 @@ xkb_save_config (t_xkb *xkb, const gchar *config_file)
GKeyFile *cfg_file = g_key_file_new();
g_key_file_set_list_separator (cfg_file, ',');

g_key_file_set_integer(cfg_file, "xkb config", "display_type", xkb->display_type);
//g_key_file_set_integer(cfg_file, "xkb config", "display_type", xkb->display_type);
g_key_file_set_integer(cfg_file, "xkb config", "group_policy", xkb->settings->group_policy);
g_key_file_set_integer(cfg_file, "xkb config", "default_group", xkb->settings->default_group);
g_key_file_set_boolean(cfg_file, "xkb config", "never_modify_config", xkb->settings->never_modify_config);
Expand Down Expand Up @@ -154,7 +154,7 @@ xkb_load_config (t_xkb *xkb, const gchar *filename)
return FALSE;
}

xkb->display_type = g_key_file_get_integer(cfg_file, "xkb config", "display_type", &error);
//xkb->display_type = g_key_file_get_integer(cfg_file, "xkb config", "display_type", &error);
xkb->settings->group_policy = g_key_file_get_integer(cfg_file, "xkb config", "group_policy", &error);
if (xkb->settings->group_policy != GROUP_POLICY_GLOBAL)
{
Expand Down Expand Up @@ -186,7 +186,7 @@ xkb_load_default (t_xkb *xkb)
{
xkb->settings->kbd_config = g_new0 (t_xkb_kbd_config, 1);
}
xkb->display_type = DISPLAY_TYPE_TEXT;
//xkb->display_type = DISPLAY_TYPE_TEXT;
xkb->settings->group_policy = GROUP_POLICY_PER_APPLICATION;
xkb->settings->never_modify_config = FALSE;
xkb->settings->kbd_config->model = g_strdup("pc105");
Expand All @@ -199,18 +199,42 @@ xkb_load_default (t_xkb *xkb)
void
xkb_initialize_menu (t_xkb *xkb)
{
if (G_UNLIKELY (xkb == NULL)) return;

// Right button click menu
GtkWidget *mi;

if (xkb->rb_mouse_popup)
gtk_widget_destroy (xkb->rb_mouse_popup);

xkb->rb_mouse_popup = gtk_menu_new();

mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_DIALOG_INFO, NULL);
g_signal_connect(G_OBJECT(mi), "activate", (GCallback)xkb_about, NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (xkb->rb_mouse_popup), mi);
gtk_widget_show (mi);

mi = gtk_menu_item_new ();
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (xkb->rb_mouse_popup), mi);
gtk_widget_set_sensitive (mi, FALSE);

mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
g_signal_connect(G_OBJECT(mi), "activate", (GCallback)gtk_main_quit, NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (xkb->rb_mouse_popup), mi);
gtk_widget_show (mi);

// Left cutton click menu
gint i;
GdkPixbuf *handle = NULL;
GdkPixbuf *pixbuf;
gchar *imgfilename;
GtkWidget *image;
GtkWidget *menu_item;

if (G_UNLIKELY (xkb == NULL)) return;
if (xkb->lb_mouse_popup)
gtk_widget_destroy (xkb->lb_mouse_popup);

if (xkb->popup)
gtk_widget_destroy (xkb->popup);

xkb->popup = gtk_menu_new ();
xkb->lb_mouse_popup = gtk_menu_new ();

gint width, height;
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
Expand All @@ -219,12 +243,15 @@ xkb_initialize_menu (t_xkb *xkb)
{
gchar *layout_string;

imgfilename = xkb_util_get_flag_filename (xkb_config_get_group_name (i));
handle = gdk_pixbuf_new_from_file_at_scale(imgfilename, width, height, TRUE, NULL);
g_free (imgfilename);

layout_string =
xkb_util_get_layout_string (xkb_config_get_group_name (i),
xkb_config_get_variant (i));
layout_string = g_ascii_strup (layout_string, -1);

handle = text_to_gtk_pixbuf(xkb, layout_string);
layout_string = g_ascii_strup (layout_string, -1);

menu_item = gtk_image_menu_item_new_with_label (layout_string);
g_free (layout_string);
Expand All @@ -236,90 +263,49 @@ xkb_initialize_menu (t_xkb *xkb)
{
image = gtk_image_new ();

pixbuf = gdk_pixbuf_scale_simple (handle, width, height, GDK_INTERP_BILINEAR);

gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
gtk_image_set_from_pixbuf (GTK_IMAGE (image), handle);
gtk_widget_show (image);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);

g_object_unref (G_OBJECT (pixbuf));
g_object_unref (handle);
}

gtk_widget_show (menu_item);

gtk_menu_shell_append (GTK_MENU_SHELL (xkb->popup), menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (xkb->lb_mouse_popup), menu_item);
}

GtkWidget *sep = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL (xkb->popup), sep);
gtk_widget_show (sep);
menu_item = gtk_image_menu_item_new_with_label ("Quit");

g_signal_connect (G_OBJECT (menu_item), "activate",
G_CALLBACK (gtk_main_quit), NULL);

image = gtk_image_new_from_stock(GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU);

gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
gtk_widget_show (menu_item);

gtk_menu_shell_append (GTK_MENU_SHELL (xkb->popup), menu_item);
}

void
xkb_refresh(t_xkb *xkb)
{
gchar *text = g_ascii_strup(xkb_util_get_layout_string (xkb_config_get_group_name (-1),
xkb_config_get_variant (-1)), -1);

GdkPixbuf * pixmap = text_to_gtk_pixbuf(xkb, text);
gtk_status_icon_set_from_pixbuf(xkb->tray, pixmap);
gchar *text = xkb_util_get_layout_string (xkb_config_get_group_name (-1),
xkb_config_get_variant (-1));

gchar *filepath = xkb_util_get_flag_filename(text);
g_free(text);
}

GdkPixbuf *
text_to_gtk_pixbuf(t_xkb *xkb, gchar *text)
{
GtkWidget *scratch = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_realize (scratch);
PangoLayout *layout = gtk_widget_create_pango_layout (scratch, NULL);
gtk_widget_destroy (scratch);

gchar *markup = g_strdup_printf ("%s", text);
pango_layout_set_markup (layout, markup, -1);
g_free (markup);

int width = 0;
int heigth = 0;
pango_layout_get_size (layout, &width, &heigth);

// offset for draw label centered
int woffset = (width/PANGO_SCALE+4)/2-(width/PANGO_SCALE)/2;
int hoffset = (width/PANGO_SCALE+4)/2-(width/PANGO_SCALE)/2;

width = width/PANGO_SCALE+4;
heigth = heigth/PANGO_SCALE+4;

GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, heigth);
GdkPixbuf * pixmap = gdk_pixbuf_new_from_file_at_size(filepath, 24, 24, NULL);

gdk_pixbuf_fill(pb, 0xffffffff);
if (!pixmap)
return;

GdkPixmap *pm = gdk_pixmap_new (NULL, width, heigth, 24);
GdkGC *gc = gdk_gc_new (pm);
gdk_draw_pixbuf (pm, gc, pb, 0, 0, 0, 0, width, heigth, GDK_RGB_DITHER_NONE, 0, 0);

gdk_draw_layout (pm, gc, woffset, hoffset, layout);


g_object_unref(layout);
gdk_gc_unref(gc);
gtk_status_icon_set_from_pixbuf(xkb->tray, pixmap);
}

GdkPixbuf *ret = gdk_pixbuf_get_from_drawable (NULL, pm, NULL, 0, 0, 0, 0, width, heigth);
g_object_unref(pm);
g_object_unref(pb);
return ret;
void
xkb_about(t_xkb *xkb)
{
GtkWidget *about_dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"%s\nX11 Keyboard switcher\nAuthor: Dmitriy Poltavchenko <%s>", PACKAGE_STRING, PACKAGE_BUGREPORT);
/* Destroy the dialog when the user responds to it (e.g. clicks a button) */
g_signal_connect_swapped (about_dialog, "response",
G_CALLBACK (gtk_widget_hide),
about_dialog);
gtk_widget_show (about_dialog);
}

int main (int argc, char *argv[])
Expand Down Expand Up @@ -357,7 +343,7 @@ int main (int argc, char *argv[])

if (xkb_config_initialize (xkb->settings, xkb_state_changed, xkb))
{
xkb_config_update_settings(xkb->settings);
//xkb_config_update_settings(xkb->settings);
xkb_refresh(xkb);
xkb_initialize_menu (xkb);
}
Expand All @@ -375,3 +361,5 @@ int main (int argc, char *argv[])
return 0;
}



37 changes: 37 additions & 0 deletions images/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
imagesdir = @datarootdir@/gxkb/flags
images_DATA = \
am.png \
bg.png \
by.png \
cz.png \
de.png \
ee.png \
gb.png \
es.png \
fi.png \
fr.png \
ge.png \
gr.png \
hr.png \
hu.png \
is.png \
it.png \
kz.png \
lt.png \
lv.png \
no.png \
pl.png \
pt.png \
ro.png \
ru.png \
se.png \
si.png \
sk.png \
sr.png \
ua.png \
us.png \
uz.png \
zz.png


EXTRA_DIST = $(images_DATA)
Binary file added images/am.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/by.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/de.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/es.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/fi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/fr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/hr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/hu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/is.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/it.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/kz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/lt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/lv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/no.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/pl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/pt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ru.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/se.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/si.png
Binary file added images/sk.png
Binary file added images/sr.png
Binary file added images/ua.png
Binary file added images/us.png
Binary file added images/uz.png
Binary file added images/zz.png
Loading

0 comments on commit 50edee1

Please sign in to comment.