Skip to content
Snippets Groups Projects
winwidget.c 27.1 KiB
Newer Older
/* winwidget.c

Copyright (C) 1999-2003 Tom Gilbert.

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 "filelist.h"
#include "winwidget.h"
#include "options.h"

static void winwidget_unregister(winwidget win);
static void winwidget_register(winwidget win);
static winwidget winwidget_allocate(void);


int window_num = 0;		/* For window list */
winwidget *windows = NULL;	/* List of windows to loop though */

static winwidget winwidget_allocate(void)
	winwidget ret = NULL;

	ret = emalloc(sizeof(_winwidget));

	ret->win = 0;
	ret->w = 0;
	ret->h = 0;
	ret->full_screen = 0;
	ret->im_w = 0;
	ret->im_h = 0;
	ret->im_angle = 0;
	ret->bg_pmap = 0;
	ret->bg_pmap_cache = 0;
	ret->im = NULL;
	ret->name = NULL;
	ret->file = NULL;
	ret->type = WIN_TYPE_UNSET;
	ret->visible = 0;
	ret->caption_entry = 0;

	/* Zoom stuff */
	ret->mode = MODE_NORMAL;

	ret->gc = None;

	/* New stuff */
	ret->im_x = 0;
	ret->im_y = 0;
	ret->zoom = 1.0;
	ret->old_zoom = 1.0;

	ret->click_offset_x = 0;
	ret->click_offset_y = 0;
	ret->has_rotated = 0;

winwidget winwidget_create_from_image(Imlib_Image im, char *name, char type)
	ret = winwidget_allocate();
	ret->type = type;
	ret->im = im;
	ret->w = ret->im_w = gib_imlib_image_get_width(ret->im);
	ret->h = ret->im_h = gib_imlib_image_get_height(ret->im);
	if (name)
		ret->name = estrdup(name);
	else
		ret->name = estrdup(PACKAGE);
	if (opt.full_screen && (type != WIN_TYPE_THUMBNAIL))
		ret->full_screen = True;
	winwidget_create_window(ret, ret->w, ret->h);
	winwidget_render_image(ret, 1, 1);
winwidget winwidget_create_from_file(gib_list * list, char *name, char type)
	winwidget ret = NULL;
	feh_file *file = FEH_FILE(list->data);

	if (!file || !file->filename)

	ret = winwidget_allocate();
	ret->file = list;
	ret->type = type;
	if (name)
		ret->name = estrdup(name);
	else
		ret->name = estrdup(file->filename);

	if (winwidget_loadimage(ret, file) == 0) {
		winwidget_destroy(ret);
	}

	if (!ret->win) {
		ret->w = ret->im_w = gib_imlib_image_get_width(ret->im);
		ret->h = ret->im_h = gib_imlib_image_get_height(ret->im);
		D(("image is %dx%d pixels, format %s\n", ret->w, ret->h, gib_imlib_image_format(ret->im)));
		if (opt.full_screen)
			ret->full_screen = True;
		winwidget_create_window(ret, ret->w, ret->h);
		winwidget_render_image(ret, 1, 1);
	}

void winwidget_create_window(winwidget ret, int w, int h)
	XSetWindowAttributes attr;
	XEvent ev;
	XClassHint *xch;
	MWMHints mwmhints;
	Atom prop = None;
	int x = 0;
	int y = 0;
	D(("winwidget_create_window %dx%d\n", w, h));
	if (ret->full_screen) {
		w = scr->width;
		h = scr->height;

#ifdef HAVE_LIBXINERAMA
		if (opt.xinerama && xinerama_screens) {
			w = xinerama_screens[xinerama_screen].width;
			h = xinerama_screens[xinerama_screen].height;
		}
#endif				/* HAVE_LIBXINERAMA */
	} else if (opt.geom_flags) {
		if (opt.geom_flags & WidthValue) {
			w = opt.geom_w;
		}
		if (opt.geom_flags & HeightValue) {
			h = opt.geom_h;
		}
		if (opt.geom_flags & XValue) {
			if (opt.geom_flags & XNegative) {
				x = scr->width - opt.geom_x;
			} else {
				x = opt.geom_x;
			}
		}
		if (opt.geom_flags & YValue) {
			if (opt.geom_flags & YNegative) {
				y = scr->height - opt.geom_y;
			} else {
				y = opt.geom_y;
			}
		}
	} else if (opt.screen_clip) {
		if (w > scr->width)
			w = scr->width;
		if (h > scr->height)
			h = scr->height;

#ifdef HAVE_LIBXINERAMA
		if (opt.xinerama && xinerama_screens) {
			if (w > xinerama_screens[xinerama_screen].width)
				w = xinerama_screens[xinerama_screen].width;
			if (h > xinerama_screens[xinerama_screen].height)
				h = xinerama_screens[xinerama_screen].height;
		}
#endif				/* HAVE_LIBXINERAMA */
	}

Loading
Loading full blame...