aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'window.c')
-rw-r--r--window.c87
1 files changed, 67 insertions, 20 deletions
diff --git a/window.c b/window.c
index 76a8e87..857b3b5 100644
--- a/window.c
+++ b/window.c
@@ -26,9 +26,10 @@
#include "util.h"
#include "window.h"
-static Cursor arrow;
-static Cursor hand;
-static GC bgc;
+static Cursor carrow;
+static Cursor chand;
+static Cursor cwatch;
+static GC gc;
Atom wm_delete_win;
@@ -49,7 +50,8 @@ void win_set_sizehints(win_t *win) {
void win_open(win_t *win) {
win_env_t *e;
XClassHint classhint;
- XColor bgcol;
+ XColor col;
+ XGCValues gcval;
int gmask;
if (!win)
@@ -66,13 +68,18 @@ void win_open(win_t *win) {
e->cmap = DefaultColormap(e->dpy, e->scr);
e->depth = DefaultDepth(e->dpy, e->scr);
- if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
- &bgcol, &bgcol))
+ if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
+ &col, &col))
+ win->bgcol = col.pixel;
+ else
+ die("could not allocate color: %s", BG_COLOR);
+ if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), SEL_COLOR,
+ &col, &col))
+ win->selcol = col.pixel;
+ else
die("could not allocate color: %s", BG_COLOR);
- win->bgcol = bgcol.pixel;
win->pm = 0;
-
win->fullscreen = 0;
/* determine window offsets, width & height */
@@ -107,10 +114,12 @@ void win_open(win_t *win) {
XSelectInput(e->dpy, win->xwin, StructureNotifyMask | KeyPressMask |
ButtonPressMask | ButtonReleaseMask | Button2MotionMask);
- arrow = XCreateFontCursor(e->dpy, XC_left_ptr);
- hand = XCreateFontCursor(e->dpy, XC_fleur);
+ carrow = XCreateFontCursor(e->dpy, XC_left_ptr);
+ chand = XCreateFontCursor(e->dpy, XC_fleur);
+ cwatch = XCreateFontCursor(e->dpy, XC_watch);
- bgc = XCreateGC(e->dpy, win->xwin, 0, None);
+ gcval.line_width = 2;
+ gc = XCreateGC(e->dpy, win->xwin, GCLineWidth, &gcval);
win_set_title(win, "sxiv");
@@ -135,10 +144,11 @@ void win_close(win_t *win) {
if (!win)
return;
- XFreeCursor(win->env.dpy, arrow);
- XFreeCursor(win->env.dpy, hand);
+ XFreeCursor(win->env.dpy, carrow);
+ XFreeCursor(win->env.dpy, chand);
+ XFreeCursor(win->env.dpy, cwatch);
- XFreeGC(win->env.dpy, bgc);
+ XFreeGC(win->env.dpy, gc);
XDestroyWindow(win->env.dpy, win->xwin);
XCloseDisplay(win->env.dpy);
@@ -211,6 +221,18 @@ void win_toggle_fullscreen(win_t *win) {
SubstructureNotifyMask, &ev);
}
+Pixmap win_create_pixmap(win_t *win, int w, int h) {
+ if (!win)
+ return 0;
+
+ return XCreatePixmap(win->env.dpy, win->xwin, w, h, win->env.depth);
+}
+
+void win_free_pixmap(win_t *win, Pixmap pm) {
+ if (win && pm)
+ XFreePixmap(win->env.dpy, pm);
+}
+
void win_clear(win_t *win) {
win_env_t *e;
XGCValues gcval;
@@ -219,15 +241,37 @@ void win_clear(win_t *win) {
return;
e = &win->env;
-
+ gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
+ win->bgcol;
if (win->pm)
XFreePixmap(e->dpy, win->pm);
win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
- gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) : win->bgcol;
- XChangeGC(e->dpy, bgc, GCForeground, &gcval);
+ XChangeGC(e->dpy, gc, GCForeground, &gcval);
+ XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh);
+}
- XFillRectangle(e->dpy, win->pm, bgc, 0, 0, e->scrw, e->scrh);
+void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
+ if (win)
+ XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y);
+}
+
+void win_draw_rect(win_t *win, int x, int y, int w, int h, Bool sel) {
+ win_env_t *e;
+ XGCValues gcval;
+
+ if (!win)
+ return;
+
+ e = &win->env;
+
+ if (sel)
+ gcval.foreground = win->selcol;
+ else
+ gcval.foreground = win->fullscreen ? BlackPixel(e->dpy, e->scr) :
+ win->bgcol;
+ XChangeGC(e->dpy, gc, GCForeground, &gcval);
+ XDrawRectangle(e->dpy, win->pm, gc, x, y, w, h);
}
void win_draw(win_t *win) {
@@ -264,11 +308,14 @@ void win_set_cursor(win_t *win, win_cur_t cursor) {
switch (cursor) {
case CURSOR_HAND:
- XDefineCursor(win->env.dpy, win->xwin, hand);
+ XDefineCursor(win->env.dpy, win->xwin, chand);
+ break;
+ case CURSOR_WATCH:
+ XDefineCursor(win->env.dpy, win->xwin, cwatch);
break;
case CURSOR_ARROW:
default:
- XDefineCursor(win->env.dpy, win->xwin, arrow);
+ XDefineCursor(win->env.dpy, win->xwin, carrow);
break;
}
}