Skip to content
Snippets Groups Projects
menu.c 36.1 KiB
Newer Older
/* menu.c

Copyright (C) 1999-2003 Tom Gilbert.
Birte Kristina Friesel's avatar
Birte Kristina Friesel committed
Copyright (C) 2010-2011 Daniel Friesel.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies of the Software and its documentation and acknowledgment shall be
given in the documentation and software packages that this Software was
used.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#include "feh.h"
#include "thumbnail.h"
#include "wallpaper.h"
#include "winwidget.h"
#include "filelist.h"
#include "options.h"

Window menu_cover = 0;
feh_menu *menu_root = NULL;
feh_menu *menu_main = NULL;
feh_menu *menu_single_win = NULL;
feh_menu *menu_thumbnail_viewer = NULL;
feh_menu *menu_thumbnail_win = NULL;
feh_menu *menu_bg = NULL;
static feh_menu_list *menus = NULL;
static int common_menus = 0;

static feh_menu *feh_menu_func_gen_info(feh_menu * m);
static void feh_menu_func_free_info(feh_menu * m);
static void feh_menu_func_free_options(feh_menu * m);
static feh_menu *feh_menu_func_gen_options(feh_menu * m);
void feh_menu_cb(feh_menu * m, feh_menu_item * i, int action, unsigned short data);
void feh_menu_cb_opt_fullscreen(feh_menu * m, feh_menu_item * i);

enum {
	CB_CLOSE = 1, CB_EXIT, CB_RELOAD, CB_REMOVE, CB_DELETE, CB_RESET,
	CB_REMOVE_THUMB, CB_DELETE_THUMB, CB_BG_TILED, CB_BG_SCALED,
	CB_BG_CENTERED, CB_BG_FILLED, CB_BG_TILED_NOFILE,
	CB_BG_SCALED_NOFILE, CB_BG_CENTERED_NOFILE, CB_BG_FILLED_NOFILE,
	CB_SORT_FILENAME, CB_SORT_IMAGENAME, CB_SORT_FILESIZE, CB_SORT_RANDOMIZE,
	CB_SAVE_IMAGE, CB_SAVE_FILELIST, CB_FIT, CB_OPT_DRAW_FILENAME,
	CB_OPT_DRAW_ACTIONS, CB_OPT_KEEP_HTTP, CB_OPT_FREEZE_WINDOW,
	CB_OPT_FULLSCREEN, CB_EDIT_ROTATE, CB_OPT_AUTO_ZOOM, CB_OPT_KEEP_ZOOM_VP

feh_menu *feh_menu_new(void)
{
	feh_menu *m;
	XSetWindowAttributes attr;
	feh_menu_list *l;
	static Imlib_Image bg = NULL;
	static Imlib_Border border;

	m = (feh_menu *) emalloc(sizeof(feh_menu));

	attr.backing_store = NotUseful;
	attr.override_redirect = True;
	attr.colormap = cm;
	attr.border_pixel = 0;
	attr.background_pixmap = None;
	attr.save_under = False;
	attr.do_not_propagate_mask = True;

	m->win = XCreateWindow(
			disp, root, 1, 1, 1, 1, 0, depth, InputOutput, vis,
			CWOverrideRedirect | CWSaveUnder | CWBackingStore
			| CWColormap | CWBackPixmap | CWBorderPixel | CWDontPropagate, &attr);
	XSelectInput(disp, m->win,
			ButtonPressMask | ButtonReleaseMask | EnterWindowMask
			| LeaveWindowMask | PointerMotionMask | ButtonMotionMask);

	m->name = NULL;
	m->fehwin = NULL;
	m->pmap = 0;
	m->x = 0;
	m->y = 0;
	m->w = 0;
	m->h = 0;
	m->visible = 0;
	m->items = NULL;
	m->next = NULL;
	m->prev = NULL;
	m->updates = NULL;
	m->needs_redraw = 1;
	m->func_free = NULL;
	m->calc = 0;
	m->bg = NULL;

	l = emalloc(sizeof(feh_menu_list));
	l->menu = m;
	l->next = menus;
	menus = l;

	if (!bg) {
		feh_load_image_char(&bg, opt.menu_bg);
		if (bg) {
			border.left = border.right = border.top = border.bottom
				= 4;
			imlib_context_set_image(bg);
			imlib_image_set_border(&border);
		}
	}

	if (bg)
		m->bg = gib_imlib_clone_image(bg);

}

void feh_menu_free(feh_menu * m)
{
	feh_menu_item *i;
	feh_menu_list *l, *pl = NULL;

	if (m->name)
		free(m->name);
	XDestroyWindow(disp, m->win);
	if (m->pmap)
		XFreePixmap(disp, m->pmap);
	if (m->updates)
		imlib_updates_free(m->updates);
	for (i = m->items; i;) {
		feh_menu_item *ii;

		ii = i;
		i = i->next;
		if (ii->text)
			free(ii->text);
		if (ii->submenu)
			free(ii->submenu);
		free(ii);
	}

	for (l = menus; l; l = l->next) {
		if (l->menu == m) {
			if (pl)
				pl->next = l->next;
			else
				menus = l->next;
			free(l);
			break;
		}
		pl = l;
	}
	if (m->bg)
		gib_imlib_free_image_and_decache(m->bg);

}

feh_menu_item *feh_menu_find_selected(feh_menu * m)
{
	feh_menu_item *i;

	D(("menu %p\n", m));

	for (i = m->items; i; i = i->next) {
		if (MENU_ITEM_IS_SELECTED(i))
}

feh_menu_item *feh_menu_find_selected_r(feh_menu * m, feh_menu ** parent)
{
	feh_menu_item *i, *ii;
	feh_menu *mm;

	D(("menu %p\n", m));

	for (i = m->items; i; i = i->next) {
		if (MENU_ITEM_IS_SELECTED(i)) {
			if (parent)
				*parent = m;
		} else if (i->submenu) {
			mm = feh_menu_find(i->submenu);
			if (mm) {
				ii = feh_menu_find_selected_r(mm, parent);
				if (ii)
Loading
Loading full blame...