Example #1
0
File: prefs.c Project: Cw1X/pnmixer
void apply_prefs(gint alsa_change) {
  gint* vol_meter_clrs;
  scroll_step = g_key_file_get_integer_with_default(keyFile,"PNMixer","MouseScrollStep",1);

  if (g_key_file_get_boolean_with_default(keyFile,"PNMixer","EnableHotKeys",FALSE)) {
    gint mk,uk,dk,mm,um,dm,hstep;
    mk = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolMuteKey", -1);
    uk = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolUpKey", -1);
    dk = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolDownKey", -1);
    mm = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolMuteMods", 0);
    um = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolUpMods", 0);
    dm = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolDownMods", 0);
    hstep = g_key_file_get_integer_with_default(keyFile,"PNMixer", "HotkeyVolumeStep", 1);
    grab_keys(mk,uk,dk,mm,um,dm,hstep);
  } else 
    grab_keys(-1,-1,-1,0,0,0,1); // will actually just ungrab everything
  
  set_notifications_booleans();

  get_icon_theme();
  if (alsa_change)
    alsa_init();
  vol_meter_clrs = get_vol_meter_colors();
  set_vol_meter_color(vol_meter_clrs[0],vol_meter_clrs[1],vol_meter_clrs[2]);
  g_free(vol_meter_clrs);
  update_status_icons();
  update_vol_text();
}
Example #2
0
/*
 * plugin activated
 */
static gboolean init (void)
{
    if (! gtk_init_check (NULL, NULL))
    {
        fprintf (stderr, "hotkey: GTK+ initialization failed.\n");
        return FALSE;
    }

    setup_filter();
    load_config ( );
    grab_keys ( );

    loaded = TRUE;
    return TRUE;
}
Example #3
0
/* Toggle whether to grab keys or not in interactive mode.
 * If not in interactive mode (see `mode') print an error.
 */
static void toggle_interactive_mode()
{
	switch (mode) {
		case INTERACTIVE:
			ungrab_keys();
			printf("interactive mode off\n");
			mode = INTERACTIVE_DISABLED;
			break;
		case INTERACTIVE_DISABLED:
			grab_keys();
			printf("interactive mode re-activated\n");
			mode = INTERACTIVE;
			break;
		default:
			fprintf(stderr, "Toggle command called in non-interactive mode.");
			break;
	}
}
void x11_hotkeys::set_comb(const std::string& val)
{
  if (comb==val)
    return;

  unsigned int modifier=0;
  KeySym key=0;
  std::string::size_type pos=std::string::npos;

  do {
    std::string::size_type prev_pos=pos;
    pos=val.find('+', pos+1);
    std::string cur;
    if (pos!=std::string::npos)
      cur.assign(val, prev_pos+1, pos-prev_pos-1);
    else
      cur.assign(val, prev_pos+1, val.length()-prev_pos-1);
    if (cur=="Ctrl") {
      modifier|=ControlMask;
    } else if (cur=="Alt") {
      modifier|=Mod1Mask;
    } else if (cur=="Shift") {
      modifier|=ShiftMask;
    } else if (cur=="Win") {
      modifier|=Mod4Mask;
    } else {
      key=XStringToKeysym(cur.c_str());
	}
  } while (pos!=std::string::npos);

  comb=val;
  pressed=false;
  grab_key.key.sym=0;
  if (key!=0) {
    ungrabkeys();
    grab_key.type=SYM;
    grab_key.event_type=PRESS;
    grab_key.key.sym=key;
    grab_key.modifier=modifier;
    grab_keys(display, &grab_key, 1);
  } else
    def_hot_keys->set_comb(val);
}
Example #5
0
File: swm.c Project: JuliusP/swm
static void
init (void) {
	uint32_t mask = 0, values[2];

	if (xcb_connection_has_error(conn = xcb_connect(NULL, NULL)))
		errx(1, "error connecting to xcb");

	scr = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;

	key_t key = 0x0DEADCA7;
	int shmid;

	if ((shmid = shmget(key, sizeof(xcb_window_t), IPC_CREAT | 0666)) < 0)
		warnx("shmget error");

	if ((focuswin = shmat(shmid, NULL, 0)) == (xcb_window_t *) -1)
		warnx("shmat error");


	(*focuswin) = scr->root;

	grab_keys();

	xcb_grab_button(conn, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
			XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
			XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 1, MOD);

	xcb_grab_button(conn, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
			XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
			XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 3, MOD);

	mask = XCB_CW_EVENT_MASK;
	values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
	xcb_change_window_attributes_checked(conn, scr->root, mask, values);
	xcb_flush(conn);
}
static void XF86AudioKeyGrab_init()
{
	gdk_window_add_filter(GDK_ROOT_PARENT(), xf86audio_filter, map);
	grab_keys();
}
Example #7
0
void mappingnotify(XEvent* event) {
   // regrab when keyboard map changes
   XMappingEvent *ev = &event->xmapping;
   XRefreshKeyboardMapping(ev);
   if(ev->request == MappingKeyboard) grab_keys();
}
Example #8
0
int main(int argc, const char **argv) {
	int i = 0;
	FILE *input = NULL;
	/* Try to connect to X server */
	if (!(dpy=XOpenDisplay(0x0))) return 1;
	/* Initialize globals */
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy,scr);
	sw = DisplayWidth(dpy,scr);
	sh = DisplayHeight(dpy,scr);
	/* parse command line arguments */
	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			if (argv[i][1] == 'h') { printf(HELP); exit(0); }
			else if (argv[i][1] == 'i') mode = INTERACTIVE;
			else if (argv[i][1] == 's') mode = STDIN;
			else if (argv[i][1] == 'c' && argc > i+1) {
				// interpret the content of the `-c' argument
				command((char *)argv[(++i)]);
				if (mode == UNSET) mode = COMMAND;
			}
		}
		else {
			/* file input; try to open the file */
			printf("in = ",argv[i]);
			input = fopen(argv[i],"r");
			if (input) mode = INPUTFILE;
		}
	}

	/* if input was only -c parameters, done */
	if (mode == COMMAND) exit(0);
	/* if no input file was opened, use stdin */
	if (!input) input = stdin;
	/* iterate over given list of commands */
	if (mode == UNSET || mode == STDIN || mode == INPUTFILE) {
		char line[MAXLINE+1];
		while (running && (fgets(line,MAXLINE,input)) != NULL)
			command(line);
		XCloseDisplay(dpy);
		if (mode == 3) fclose(input);
		return 0;
	}


	/* no args -> interactive mode: */

	/* search for config file */
	char *dir = getenv("PWD");
	chdir(getenv("XDG_CONFIG_HOME"));
	chdir("iocane");
	FILE *rcfile = fopen("config","r");
	if (!rcfile) {
		chdir(getenv("HOME"));
		rcfile = fopen(".iocanerc","r");
	}
	if (!rcfile) rcfile = fopen("/usr/share/iocane/iocanerc","r");
	if (dir) chdir(dir); /* go back to current directory */
	/* if unable to find a config file, quit */
	if (!rcfile) {
		fprintf(stderr,"IOCANE: no iocanerc file found.\n");
		XCloseDisplay(dpy);
		return 0;
	}

	/* parse config file */
	KeySym keysym;
	char *line = (char *) calloc(MAXLINE+MAXSYMLEN+2,sizeof(char));
	char *command_string;
	char keystring[MAXSYMLEN];
	keycount = 0;
	while (fgets(line,MAXLINE+MAXSYMLEN+2,rcfile) != NULL) {
		if (line[0] == '#' || line[0] == '\n') continue;
		/* split each line at space, parse into keysym,command_string */
		strncpy(keystring,line,MAXSYMLEN); *strchr(keystring,' ') = '\0';
		if ( (keysym=XStringToKeysym(keystring)) == NoSymbol ) continue;
		command_string = (char *) calloc(strlen(line) - strlen(keystring), sizeof(char));
		strcpy(command_string,strchr(line,' ')+1);
		/* check, if it's the toggle command */
		if (command_string[0] == 't') {
			/* if so, set the special toggle key */
			grab_ungrab_key = XKeysymToKeycode(dpy,keysym);
		}
		else {
			/* otherwise (normal key) add keysymbol and command to keys */
			keys = realloc(keys, (keycount+1) * sizeof(Key));
			keys[keycount].key = XKeysymToKeycode(dpy,keysym);
			keys[keycount].command = command_string;
			keycount++;
		}
	}
	/* done parsing; clean up */
	free(line);
	fclose(rcfile);

	/* actually grab the keys */
	grab_keys();

	/* loop for interactive mode
	 * Wait for event (blocks) of a grabbed key.  If the key is registered in
	 * the `keys' list, then the associated command is executed.
	 */
	XEvent ev;
	XKeyEvent *e;
	while (running && !XNextEvent(dpy,&ev)) if (ev.type == KeyPress) {
		e = &ev.xkey;
		if (e->keycode == grab_ungrab_key) {
			toggle_interactive_mode();
		}
		else {
			for (i = 0; i < keycount; i++)
				if (e->keycode == keys[i].key && keys[i].command)
					command(keys[i].command); /* execute associated command */
		}
	}

	/* program done; cleanup */
	for (i = 0; i < keycount; i++) free(keys[i].command);
	free(keys);
	XCloseDisplay(dpy); /* close connection to X server and release resources */
	return 0;
}
Example #9
0
static Bool wait_key(int screen, KeyCode* kc, unsigned int* mods)
{
    grab_keys(screen);

    KeyCode waitfor = 0;
    *kc = 0;
    Bool done = False;
    while (!done)
    {
        // Use select to make sure we check our timer(s) at least once a second
        fd_set rd;
        int fd = ConnectionNumber(dpy);
        struct timeval tv;
        tv.tv_sec = 1;
        tv.tv_usec = 0;
        FD_ZERO(&rd);
        FD_SET(fd, &rd);
        if (select(fd+1, &rd, NULL, NULL, &tv) > 0)
        {
            int nQueued = XPending(dpy);
            if (nQueued == 0)
                printf("Waiting for key...\n");
            while (nQueued > 0)
            {
                XEvent event;
                XNextEvent(dpy, &event);
                if (verbose)
                    trace("event.type=%d", event.type);
                switch (event.type)
                {
                  case KeyPress:
                    {
                        XKeyEvent* e = (XKeyEvent*)&event;
                        if (verbose)
                            trace("KeyPress 0x%x/0x%x", e->keycode, e->state);
                        if (waitfor == 0)
                        {
                            waitfor = e->keycode;
                            *mods = e->state;
                            if (verbose)
                                trace("wait for key 0x%x release...", waitfor);
                        }
                    }
                    break;
                  case KeyRelease:
                    {
                        XKeyEvent* e = (XKeyEvent*)&event;
                        if (verbose)
                            trace("KeyRelease 0x%x/0x%x", e->keycode, e->state);
                        if (e->keycode == waitfor)
                        {
                            *kc = waitfor;
                            if (verbose)
                                trace("got key 0x%x release!", waitfor);
                        }
                        done = True;
                    }
                    break;
                }
                if (!done)
                    nQueued = XPending(dpy);
                else
                    nQueued = 0;
            }
        }
    }

    ungrab_keys(screen);

    return (Bool)(*kc != 0);
}