Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
	int listmask = 0, rootflag = 0;

	ARGBEGIN {
		case 'a': listmask |= LIST_ALL; break;
		case 'u': listmask |= LIST_HIDDEN; break;
		case 'o': listmask |= LIST_IGNORE; break;
		case 'r': rootflag = 1; break;
		default : usage();
	} ARGEND;

	init_xcb(&conn);
	get_screen(conn, &scrn);

	if (rootflag == 1) {
		printf("0x%08x\n", scrn->root);
		return 0;
	}

	if (argc == 0)
		list_windows(scrn->root, listmask);

	while (*argv)
		list_windows(strtoul(*argv++, NULL, 16), listmask);

	kill_xcb(&conn);

	return 0;
}
Ejemplo n.º 2
0
void handle_keypress_event(XEvent * e)
{
	XEvent event;
	XGrabKey(display, AnyKey, AnyModifier, root, True, GrabModeAsync, GrabModeAsync);
        XMaskEvent (display, KeyPressMask, &event);
	XDefineCursor(display, selected, (XCreateFontCursor(display, CURSOR)));
	unsigned int key = XLookupKeysym((XKeyEvent *) &event, 0);
	if (key >= '0' && key <= '9')
	{
		XUngrabKey(display, AnyKey, AnyModifier, root);
		grab_keyboard();
		select_window(key - '0');
		return;
	}
	switch (key)
        {       
		case KEY_TERMINAL:
			spawn(TERMINAL);
			break;
		case KEY_MENU:
			spawn(MENU);
			break;
		case KEY_STATUS:
			echo_output(STATUS);
			break;
		case KEY_WINLIST:
			if(TIMEOUT > 0)
			{
				list_windows();
			}			
			break;
		case KEY_KILL:
			XDestroyWindow(display, selected);
			selected = root;
			break;
		case KEY_PREV:
			if(get_prev_window() != -1){
				select_window(get_prev_window());
			} else {
				message("Can't access previous window!");
			}
			break;
		case KEY_NEXT:
			if(get_next_window() != -1)
			{
				select_window(get_next_window());
			} else {
				message("Can't access next window!");
			}
			break;
                default:
                        message("Key \"%c\" is unbound!", (char)key);
	}

	XUngrabKey(display, AnyKey, AnyModifier, root);
	grab_keyboard();
	XSetInputFocus (display, selected, RevertToParent, CurrentTime);
}
Ejemplo n.º 3
0
//Gives the contents of a directory
static int x11fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
	(void) offset;
	(void) fi;

	//If the path is to a non existant window says so
	int wid;
	if((wid = get_winid(path)) != -1 && !exists(wid)){
		return -ENOENT;
	}

	bool exists = false;
	bool dir = false;


	//Iterate through our filesystem layout
	size_t files_length = sizeof(x11fs_files)/sizeof(struct x11fs_file);
	for(size_t i=0; i<files_length; i++){

		//If the path was to a window replace the wildcard in the layout with the actual window we're looking at
		char *matchpath;
		if((wid != -1) && (get_winid(x11fs_files[i].path) != -1)){
			matchpath=malloc(strlen(x11fs_files[i].path)+8);
			sprintf(matchpath, "/0x%08x", wid);
			sprintf(matchpath+11, x11fs_files[i].path+4);
		}
		else
			matchpath=strdup(x11fs_files[i].path);


		//As the path for the root directory is just a / with no text we need to treat it as being 0 length
		//This is for when we check if something in our layout is in the folder we're looking at, but not in a subfolder
		int len = !strcmp(path, "/") ? 0 : strlen(path);

		//If the file exists in our layout
		if(!strncmp(path, matchpath, strlen(path))){
			exists = true;

			//Check that to see if an element in our layout is directly below the folder we're looking at in the heirarchy
			//If so add it to the directory listing
			if((strlen(matchpath) > strlen(path))
					&& ((matchpath+len)[0] == '/')
					&& !strchr(matchpath+len+1, '/')){
				dir = true;

				//If it's a wildcarded window in our layout with the list of actual windows
				if(!strcmp(matchpath, "/0x*")){
					//Get the list of windows
					int *wins = list_windows();

					//Add each window to our directory listing
					for(int j=0; wins[j]; j++){
						int win = wins[j];
						char *win_string;

						win_string = malloc(sizeof(char)*(WID_STRING_LENGTH));
						sprintf(win_string, "0x%08x", win);

						filler(buf, win_string, NULL, 0);

						free(win_string);
					}

					free(wins);
				}
				//Otherwise just add the file to our directory listing
				else
					filler(buf, matchpath+len+1, NULL, 0);
			}
		}
		free(matchpath);
	}

	if(!exists)
		return -ENOENT;

	//Add any extra needed elements to the directory list
	if(dir){
		filler(buf, ".", NULL, 0);
		filler(buf, "..", NULL, 0);
	}else
		return -ENOTDIR;

	return 0;
}