aboutsummaryrefslogtreecommitdiff
path: root/fbxkb.c
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-10-10 10:27:32 -0400
committerB. Stack <bgstack15@gmail.com>2022-10-10 10:29:47 -0400
commitd5c3cd287aed5684cd60f90eb88e19403079887e (patch)
treecc7d5f7c8350a15fd55f349304412629c04169ef /fbxkb.c
parentreadd all images (diff)
downloadfbxkb-d5c3cd287aed5684cd60f90eb88e19403079887e.tar.gz
fbxkb-d5c3cd287aed5684cd60f90eb88e19403079887e.tar.bz2
fbxkb-d5c3cd287aed5684cd60f90eb88e19403079887e.zip
restore to orig tgz for dpkg-build prep
Diffstat (limited to 'fbxkb.c')
-rw-r--r--fbxkb.c103
1 files changed, 32 insertions, 71 deletions
diff --git a/fbxkb.c b/fbxkb.c
index fb5f665..c6eccbc 100644
--- a/fbxkb.c
+++ b/fbxkb.c
@@ -40,7 +40,7 @@ typedef struct _kbd_info {
#define IMGPREFIX PREFIX "/share/fbxkb/images/"
/******************************************************************
- * GLOBAL VARIABLES *
+ * GLOBAL VARSIABLES *
******************************************************************/
/* X11 common stuff */
@@ -48,7 +48,7 @@ static Atom a_XKB_RULES_NAMES;
static Display *dpy;
static int xkb_event_type;
-/* internal state machine */
+/* internal state mashine */
static int cur_group;
static int ngroups;
static GHashTable *sym2pix;
@@ -170,7 +170,7 @@ app_menu_about(GtkWidget *widget, gpointer data)
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
- "fbxkb %s\nX11 Keyboard switcher\nOriginal author: Anatoly Asviyan <aanatoly@users.sf.net>\ncustomized for stackrpms by bgstack15", version);
+ "fbxkb %s\nX11 Keyboard switcher\nAuthor: Anatoly Asviyan <aanatoly@users.sf.net>", version);
/* 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),
@@ -205,12 +205,6 @@ static void docklet_destroyed(GtkWidget *widget, void *data)
RET();
}
-int scroll_input_method(int no) {
- no = (cur_group + no) % ngroups;
- DBG("no=%d\n", no);
- XkbLockGroup(dpy, XkbUseCoreKbd, no);
- return no;
-}
void docklet_clicked(GtkWidget *button, GdkEventButton *event, void *data)
{
@@ -219,9 +213,13 @@ void docklet_clicked(GtkWidget *button, GdkEventButton *event, void *data)
if (event->type != GDK_BUTTON_PRESS)
RET();
- if (event->button == 2) {
- scroll_input_method(1);
- } else if (event->button == 1) {
+ if (event->button == 1) {
+ int no;
+
+ no = (cur_group + 1) % ngroups;
+ DBG("no=%d\n", no);
+ XkbLockGroup(dpy, XkbUseCoreKbd, no);
+ } else if (event->button == 2) {
gtk_menu_popup(GTK_MENU(flag_menu), NULL, NULL, NULL, NULL, event->button, event->time);
} else if (event->button == 3) {
gtk_menu_popup(GTK_MENU(app_menu), NULL, NULL, NULL, NULL, event->button, event->time);
@@ -229,26 +227,6 @@ void docklet_clicked(GtkWidget *button, GdkEventButton *event, void *data)
RET();
}
-void docklet_scrolled(GtkWidget *button, GdkEventScroll *event, void *data) {
- char *i = NULL;
- int no = 0;
- switch (event->direction) {
- case GDK_SCROLL_UP:
- case GDK_SCROLL_LEFT:
- i = "up";
- no = -1;
- break;
- case GDK_SCROLL_DOWN:
- case GDK_SCROLL_RIGHT:
- i = "down";
- no = 1;
- break;
- }
- if (i) {
- scroll_input_method(no);
- }
-}
-
static int
docklet_create()
{
@@ -262,7 +240,6 @@ docklet_create()
g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(docklet_embedded), NULL);
g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_destroyed), NULL);
g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_clicked), NULL);
- g_signal_connect(G_OBJECT(docklet), "scroll-event", G_CALLBACK(docklet_scrolled), NULL);
gtk_container_set_border_width(GTK_CONTAINER(box), 0);
@@ -280,7 +257,7 @@ docklet_create()
static gboolean
my_str_equal (gchar *a, gchar *b)
{
- return strcmp(a,b) == 0;
+ return (a[0] == b[0] && a[1] == b[1]);
}
@@ -289,6 +266,7 @@ sym2flag(char *sym)
{
GdkPixbuf *flag;
static GString *s = NULL;
+ char tmp[3];
ENTER;
g_assert(sym != NULL && strlen(sym) > 1);
@@ -296,16 +274,17 @@ sym2flag(char *sym)
if (flag)
RET(flag);
- if (!s)
- s = g_string_new(IMGPREFIX);
- else
- s = g_string_assign(s,IMGPREFIX);
- s = g_string_append(s, sym);
- s = g_string_append(s, ".png");
+ if (!s)
+ s = g_string_new(IMGPREFIX "tt.png");
+ s->str[s->len-6] = sym[0];
+ s->str[s->len-5] = sym[1];
flag = gdk_pixbuf_new_from_file_at_size(s->str, 24, 24, NULL);
if (!flag)
RET(zzflag);
- g_hash_table_insert(sym2pix, g_strdup(sym), flag);
+ tmp[0] = sym[0];
+ tmp[1] = sym[1];
+ tmp[2] = 0;
+ g_hash_table_insert(sym2pix, tmp, flag);
RET(flag);
}
@@ -366,7 +345,7 @@ read_kbd_description()
// parse kbd info
if (sym_name_atom != None) {
- char *sym_name, *tmp, *tok, *tmp2, *tmp3;
+ char *sym_name, *tmp, *tok;
int no;
sym_name = XGetAtomName(dpy, sym_name_atom);
@@ -377,7 +356,6 @@ read_kbd_description()
* 150 pc/pc(pc101)+pc/us+pc/ru(phonetic):2+group(shift_toggle)
* 470 pc(pc105)+us+ru(phonetic):2+il(phonetic):3+group(shifts_toggle)+group(switch)
*/
- tmp3 = malloc(30 * sizeof(char));
DBG("sym_name=%s\n", sym_name);
for (tok = strtok(sym_name, "+"); tok; tok = strtok(NULL, "+")) {
DBG("tok=%s\n", tok);
@@ -390,46 +368,30 @@ read_kbd_description()
} else {
no = 0;
}
- if((tmp2 = strchr(tok, '('))) {
- // these next two statements could be done cleverly in one statement but the compiler warns if you try it.
- // strip left paren, and then right paren
- tmp2++;
- tmp2[strlen(tmp2)-1] = '\0';
- }
- DBG("tmp2=%s\n", tmp2);
for (tmp = tok; isalpha(*tmp); tmp++);
*tmp = 0;
DBG("map=%s no=%d\n", tok, no);
- if (!strcmp(tok, "pc") || (strlen(tok) != 2))
+ if (!strcmp(tok, "pc") || !strcmp(tok, "group"))
continue;
g_assert((no >= 0) && (no < ngroups));
if (group2info[no].sym != NULL) {
ERR("xkb group #%d is already defined\n", no);
}
- strcpy(tmp3, tok);
- if (tmp2 != 0) {
- strcat(tmp3,",");
- // add variant to end of string for the png lookup
- strcat(tmp3,tmp2);
- *tmp2 = 0;
- }
- DBG("tmp3=%s\n",tmp3);
- group2info[no].sym = g_strdup(tmp3);
- group2info[no].flag = sym2flag(tmp3);
+ group2info[no].sym = g_strdup(tok);
+ group2info[no].flag = sym2flag(tok);
group2info[no].name = XGetAtomName(dpy, kbd_desc_ptr->names->groups[no]);
- *tmp3 = 0;
}
XFree(sym_name);
}
out:
XkbFreeKeyboard(kbd_desc_ptr, 0, True);
- // sanity check: group numbering must be continuous
+ // sanity check: group numbering must be continous
for (i = 0; (i < XkbNumKbdGroups) && (group2info[i].sym != NULL); i++);
if (i != ngroups) {
- ERR("kbd group numbering is not continuous\n");
- ERR("run 'xlsatoms | grep pc' to know what happens\n");
+ ERR("kbd group numbering is not continous\n");
+ ERR("run 'xlsatoms | grep pc' to know what hapends\n");
exit(1);
}
out_us:
@@ -454,7 +416,6 @@ static void update_flag(int no)
g_assert(k != NULL);
DBG("k->sym=%s\n", k->sym);
gtk_image_set_from_pixbuf(GTK_IMAGE(image), k->flag);
- gtk_widget_set_tooltip_text(docklet, k->name);
RET();
}
@@ -473,9 +434,8 @@ filter( XEvent *xev, GdkEvent *event, gpointer data)
if (xkbev->any.xkb_type == XkbStateNotify) {
DBG("XkbStateNotify: %d\n", xkbev->state.group);
cur_group = xkbev->state.group;
- if (cur_group < ngroups) {
+ if (cur_group < ngroups)
update_flag(cur_group);
- }
} else if (xkbev->any.xkb_type == XkbNewKeyboardNotify) {
DBG("XkbNewKeyboardNotify\n");
read_kbd_description();
@@ -496,7 +456,7 @@ init()
ENTER;
sym2pix = g_hash_table_new(g_str_hash, (GEqualFunc) my_str_equal);
- dpy = gdk_x11_get_default_xdisplay();
+ dpy = GDK_DISPLAY();
a_XKB_RULES_NAMES = XInternAtom(dpy, "_XKB_RULES_NAMES", False);
if (a_XKB_RULES_NAMES == None)
ERR("_XKB_RULES_NAMES - can't get this atom\n");
@@ -554,7 +514,8 @@ int
main(int argc, char *argv[], char *env[])
{
ENTER;
- setlocale(LC_ALL, "");
+ setlocale(LC_CTYPE, "");
+ gtk_set_locale();
gtk_init(&argc, &argv);
XSetLocaleModifiers("");
XSetErrorHandler((XErrorHandler) Xerror_handler);
@@ -575,7 +536,7 @@ Xerror_handler(Display * d, XErrorEvent * ev)
char buf[256];
ENTER;
- XGetErrorText(gdk_x11_get_default_xdisplay(), ev->error_code, buf, 256);
+ XGetErrorText(GDK_DISPLAY(), ev->error_code, buf, 256);
ERR( "fbxkb : X error: %s\n", buf);
RET();
}
bgstack15