diff options
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 85 |
1 files changed, 54 insertions, 31 deletions
@@ -1,19 +1,19 @@ -/* sxiv: window.c - * Copyright (c) 2012 Bert Muennich <be.muennich at googlemail.com> +/* Copyright 2011-2013 Bert Muennich * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. + * This file is part of sxiv. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * sxiv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * sxiv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with sxiv. If not, see <http://www.gnu.org/licenses/>. */ #define _POSIX_C_SOURCE 200112L @@ -52,7 +52,8 @@ static struct { static int fontheight; static int barheight; -void win_init_font(Display *dpy, const char *fontstr) { +void win_init_font(Display *dpy, const char *fontstr) +{ int n; char *def, **missing; @@ -84,7 +85,8 @@ void win_init_font(Display *dpy, const char *fontstr) { barheight = fontheight + 2 * V_TEXT_PAD; } -unsigned long win_alloc_color(win_t *win, const char *name) { +unsigned long win_alloc_color(win_t *win, const char *name) +{ XColor col; if (win == NULL) @@ -98,7 +100,8 @@ unsigned long win_alloc_color(win_t *win, const char *name) { return col.pixel; } -void win_init(win_t *win) { +void win_init(win_t *win) +{ win_env_t *e; if (win == NULL) @@ -135,7 +138,8 @@ void win_init(win_t *win) { wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False); } -void win_set_sizehints(win_t *win) { +void win_set_sizehints(win_t *win) +{ if (win == NULL || win->xwin == None) return; @@ -156,7 +160,8 @@ void win_set_sizehints(win_t *win) { XSetWMNormalHints(win->env.dpy, win->xwin, &win->sizehints); } -void win_open(win_t *win) { +void win_open(win_t *win) +{ win_env_t *e; XClassHint classhint; XColor col; @@ -261,7 +266,8 @@ void win_open(win_t *win) { win_toggle_fullscreen(win); } -void win_close(win_t *win) { +void win_close(win_t *win) +{ if (win == NULL || win->xwin == None) return; @@ -276,7 +282,8 @@ void win_close(win_t *win) { XCloseDisplay(win->env.dpy); } -bool win_configure(win_t *win, XConfigureEvent *c) { +bool win_configure(win_t *win, XConfigureEvent *c) +{ bool changed; if (win == NULL || c == NULL) @@ -298,7 +305,8 @@ bool win_configure(win_t *win, XConfigureEvent *c) { return changed; } -void win_expose(win_t *win, XExposeEvent *e) { +void win_expose(win_t *win, XExposeEvent *e) +{ if (win == NULL || win->xwin == None || win->pm == None || e == NULL) return; @@ -306,7 +314,8 @@ void win_expose(win_t *win, XExposeEvent *e) { e->x, e->y, e->width, e->height, e->x, e->y); } -bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) { +bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) +{ if (win == NULL || win->xwin == None) return false; @@ -328,10 +337,16 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) { XMoveResizeWindow(win->env.dpy, win->xwin, x, y, w, h); + if (win->pm != None) { + XFreePixmap(win->env.dpy, win->pm); + win->pm = None; + } + return true; } -void win_toggle_fullscreen(win_t *win) { +void win_toggle_fullscreen(win_t *win) +{ XEvent ev; XClientMessageEvent *cm; @@ -355,7 +370,8 @@ void win_toggle_fullscreen(win_t *win) { SubstructureNotifyMask | SubstructureRedirectMask, &ev); } -void win_toggle_bar(win_t *win) { +void win_toggle_bar(win_t *win) +{ if (win == NULL || win->xwin == None) return; @@ -368,7 +384,8 @@ void win_toggle_bar(win_t *win) { } } -void win_clear(win_t *win) { +void win_clear(win_t *win) +{ int h; win_env_t *e; @@ -385,7 +402,8 @@ void win_clear(win_t *win) { XFillRectangle(e->dpy, win->pm, gc, 0, 0, win->w, h); } -void win_draw_bar(win_t *win) { +void win_draw_bar(win_t *win) +{ int len, olen, x, y, w, tw; char rest[3]; const char *dots = "..."; @@ -440,7 +458,8 @@ void win_draw_bar(win_t *win) { } } -void win_draw(win_t *win) { +void win_draw(win_t *win) +{ if (win == NULL || win->xwin == None || win->pm == None) return; @@ -469,7 +488,8 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h); } -int win_textwidth(const char *text, unsigned int len, bool with_padding) { +int win_textwidth(const char *text, unsigned int len, bool with_padding) +{ XRectangle r; int padding = with_padding ? 2 * H_TEXT_PAD : 0; @@ -481,7 +501,8 @@ int win_textwidth(const char *text, unsigned int len, bool with_padding) { } } -void win_set_title(win_t *win, const char *title) { +void win_set_title(win_t *win, const char *title) +{ if (win == NULL || win->xwin == None) return; @@ -501,14 +522,16 @@ void win_set_title(win_t *win, const char *title) { PropModeReplace, (unsigned char *) title, strlen(title)); } -void win_set_bar_info(win_t *win, char *linfo, char *rinfo) { +void win_set_bar_info(win_t *win, char *linfo, char *rinfo) +{ if (win != NULL) { win->bar.l = linfo; win->bar.r = rinfo; } } -void win_set_cursor(win_t *win, cursor_t cursor) { +void win_set_cursor(win_t *win, cursor_t cursor) +{ if (win == NULL || win->xwin == None) return; |