Great. Thanks for the code update. On Tue, Jan 25, 2011 at 6:35 PM, Steven L. Seed <[email protected]> wrote: > Here is our modified version of the monitor_wacom.c code. His original code > was checking for the screen saver to go off to load the settings. In our > case, we want to load the settings whenever the tablet is plugged in, so we > modified it to listen on the org.freedesktop.Hal.Manager interface for the > "DeviceAdded" singal. > > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > #include <unistd.h> > #include <time.h> > #include <assert.h> > > void log_msg(const char *msg) { > > > FILE *log_file = fopen("/tmp/monitor_wacom.log", "a"); > > if (log_file) { > time_t time_g; > time(&time_g); > char date_str[100]; > strcpy(date_str, asctime(localtime(&time_g))); > date_str[strlen(date_str) - 1] = '\0'; /* get rid of the \n > */ > fprintf(log_file, "%s : %s\n", date_str, msg); > } > > fclose(log_file); > } > > void run_script(const char *filename) { /* only run xsetwacom lines */ > FILE *script_file = fopen(filename, "r"); > > if (!script_file) { > log_msg("Failed to open script (double check your entry in > Startup Applications). Terminating."); > exit(1); > } > > char buf[1024]; > char l_buf[1024]; > int count = 0; > while ((fgets(buf, 1023, script_file))) { > if (strstr(buf, "xsetwacom")) { > int r = system(buf); > if (r != 0) { > sprintf(buf, "xsetwacom returned error on > line - %s", buf); > log_msg(l_buf); > } > ++count; > } > } > > sprintf(l_buf, "Script ran. %d matching lines executed.", count); > > log_msg(l_buf); > } > > int main(int argc, char **argv) { > > char script_name[1024]; > > if (argc != 2) { > log_msg("Script not specified, using .xinitrc"); > strcpy(script_name, ".xinitrc"); > } else { > strcpy(script_name, argv[1]); > } > > run_script(script_name); > > FILE* in = popen("dbus-monitor --system > type='signal',interface='org.freedesktop.Hal.Manager',member='DeviceAdded'", > "r"); > > if (!in) { > log_msg("Cannot spawn dbus-monitor process. Terminating."); > return 1; > } > while (1) { > char buf[1024]; > assert(fgets(buf, 1023, in)); > > if (buf[0] == 's' /* early exit optimization */ && > strstr(buf, "DeviceAdded") != NULL) { > /* resumed */ > log_msg("Device plugged in. Running > script."); > run_script(script_name); > } > } > } > >
------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d _______________________________________________ Linuxwacom-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel
