Skip to content

Commit

Permalink
Add filter to show only needed modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
sneetsher committed Feb 22, 2015
1 parent f4ad0ac commit f4a3762
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ https://code.launchpad.net/~sneetsher/+recipe/indicator-xkbmod-daily

debuild -us -uc
sudo dpkg -i indicator-xkbmod*.deb

### Running

- default mode:

indicator-xkbmod

- label mode:

indicator-xkbmod -l

- filter needed modifiers (10110011 binary = 205 decimal)

indicator-xkbmod -f 205

shows only shift,control,alt,super,altgr
5 changes: 5 additions & 0 deletions data/man/indicator-xkbmod.1
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ indicator-xkbmod \- simple Ubuntu keyboard modifiers indicator
.B indicator-xkbmod
[\fB\-l\fR]
[\fB\-\-use\-label\fR]
[\fB\-f\fR \fIBITS\fR]
[\fB\-\-filter\fR \fIBITS\fR]
.SH DESCRIPTION
.B indicator-xkbmod
simple Ubuntu keyboard modifiers indicator.
.SH OPTIONS
.TP
.BR \-l ", " \-\-use-label
Use indicator label instead of icon to show the state.
.TP
.BR \-f ", " \-\-filter =\fIBITS\fR
Show state only for specific modifiers (bitwise).
24 changes: 20 additions & 4 deletions src/indicator-xkbmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

//commandline options
static gboolean show_label = FALSE;
static gint show_filter = 255;
static gint icon_count = 8;
static GOptionEntry option_entries[] = {
{ "use-label", 'l', 0, G_OPTION_ARG_NONE, &show_label, "Use indicator label instead of icon", NULL },
{ "filter", 'f', 255, G_OPTION_ARG_INT, &show_filter, "Which modifiers to show", NULL },
{ NULL }
};

Expand Down Expand Up @@ -104,7 +107,7 @@ static gboolean update_xkb_state (gpointer data)
GString *svg_template[] = {
g_string_new("\
<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n\
<svg width='144' xmlns='http://www.w3.org/2000/svg' version='1.1' height='22'>\n"),
<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='22' width='%i'>\n"),
g_string_new("\
<svg>\n\
<defs>\n\
Expand All @@ -117,24 +120,28 @@ static gboolean update_xkb_state (gpointer data)
<rect style='fill:#f00' mask='url(#m%i)' rx='2' height='4' width='4' y='14' x='%i'/>\n\
</svg>\n"),
g_string_new("</svg>")};
GString *svg = g_string_new(svg_template[0]->str);
GString *svg = g_string_new("");
g_string_append_printf (svg, svg_template[0]->str, icon_count*18);
gsize *bytes_written;

register int i;
register int i,j;
unsigned bit;

g_debug("xkbState - base %02X, latched %02X, locked %02X, effective %02X, compact %02X", xkbState.base_mods, xkbState.latched_mods, xkbState.locked_mods, xkbState.mods, xkbState.compat_state);

//loop taken from xkbwatch source
j=icon_count-1;
for (i = XkbNumModifiers - 1, bit = 0x80; i >= 0; i--, bit >>= 1)
{
if (!(show_filter & bit)) continue;
//todo: change constant with xkb modifier constant (defined in the headers)

g_string_prepend (label, (xkbState.mods & bit)?label_template[i]->str:"");
g_string_prepend (label, (xkbState.locked_mods & bit)?" ˳":" ");

g_string_append_printf (svg, svg_template[1]->str, i, 18*i, 18*i+9, label_template[i]->str, (xkbState.mods & bit)?"#dfdbd2":"#7E7D77", i, 18*i+1, i, (xkbState.locked_mods & bit)?18*i+2:-5);
g_string_append_printf (svg, svg_template[1]->str, i, 18*j, 18*j+9, label_template[i]->str, (xkbState.mods & bit)?"#dfdbd2":"#7E7D77", i, 18*j+1, i, (xkbState.locked_mods & bit)?18*j+2:-5);

j--;
}

//g_string_prepend (label, "");
Expand Down Expand Up @@ -201,6 +208,15 @@ int main (int argc, char **argv)
return 5;
}


icon_count = 0;
unsigned char c = (unsigned char) show_filter;
while ( c!=0 && icon_count<8 ) {
icon_count += c%2;
c>>=1;
}


gtk_init (&argc, &argv);

XkbIgnoreExtension(False);
Expand Down

0 comments on commit f4a3762

Please sign in to comment.