Skip to content

Instantly share code, notes, and snippets.

@fgiobergia
Created October 20, 2013 10:09
Show Gist options
  • Save fgiobergia/7067502 to your computer and use it in GitHub Desktop.
Save fgiobergia/7067502 to your computer and use it in GitHub Desktop.
Touchpad switch, for enabling/disabling the touchpad (using xinput)
#include <stdio.h>
#include <string.h>
/*
* `xinput list` shows a list
* of devices from which you
* can get your device's id.
*/
#define DEVICE 12
int main () {
FILE *pp;
int v;
char line[512],cmd[32];
sprintf (cmd, "xinput list-props %d",DEVICE);
pp = popen (cmd,"r");
while (fgets(line,sizeof(line),pp)) {
if (strstr (line,"Device Enabled")) {
sscanf (strchr(line,':')+1,"%d",&v);
if (v) {
// Enabled (switch do Disabled)
sprintf (cmd,"xinput disable %d",DEVICE);
pclose(popen(cmd,"r"));
}
else {
// Disabled (switch to Enabled)
sprintf(cmd,"xinput enable %d",DEVICE);
pclose(popen(cmd,"r"));
}
break;
}
}
pclose (pp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment