Put some useful information in the window title
This commit is contained in:
parent
eeb58886a5
commit
08018427c6
23
main.c
23
main.c
|
@ -31,6 +31,8 @@ void on_keypress(XEvent*);
|
||||||
void on_configurenotify(XEvent*);
|
void on_configurenotify(XEvent*);
|
||||||
void on_expose(XEvent*);
|
void on_expose(XEvent*);
|
||||||
|
|
||||||
|
void update_title();
|
||||||
|
|
||||||
static void (*handler[LASTEvent])(XEvent*) = {
|
static void (*handler[LASTEvent])(XEvent*) = {
|
||||||
[Expose] = on_expose,
|
[Expose] = on_expose,
|
||||||
[ConfigureNotify] = on_configurenotify,
|
[ConfigureNotify] = on_configurenotify,
|
||||||
|
@ -44,6 +46,9 @@ const char **filenames;
|
||||||
unsigned int filecnt;
|
unsigned int filecnt;
|
||||||
unsigned int fileidx;
|
unsigned int fileidx;
|
||||||
|
|
||||||
|
#define TITLE_LEN 256
|
||||||
|
char win_title[TITLE_LEN];
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
|
||||||
|
@ -90,6 +95,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
img_load(&img, filenames[fileidx]);
|
img_load(&img, filenames[fileidx]);
|
||||||
img_display(&img, &win);
|
img_display(&img, &win);
|
||||||
|
update_title();
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
@ -127,6 +133,7 @@ void on_keypress(XEvent *ev) {
|
||||||
if (fileidx + 1 < filecnt) {
|
if (fileidx + 1 < filecnt) {
|
||||||
img_load(&img, filenames[++fileidx]);
|
img_load(&img, filenames[++fileidx]);
|
||||||
img_display(&img, &win);
|
img_display(&img, &win);
|
||||||
|
update_title();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XK_p:
|
case XK_p:
|
||||||
|
@ -134,6 +141,7 @@ void on_keypress(XEvent *ev) {
|
||||||
if (fileidx > 0) {
|
if (fileidx > 0) {
|
||||||
img_load(&img, filenames[--fileidx]);
|
img_load(&img, filenames[--fileidx]);
|
||||||
img_display(&img, &win);
|
img_display(&img, &win);
|
||||||
|
update_title();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -153,3 +161,18 @@ void on_expose(XEvent *ev) {
|
||||||
img_render(&img, &win, ev->xexpose.x, ev->xexpose.y,
|
img_render(&img, &win, ev->xexpose.x, ev->xexpose.y,
|
||||||
ev->xexpose.width, ev->xexpose.height);
|
ev->xexpose.width, ev->xexpose.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_title() {
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] <%d%%> %s", fileidx + 1,
|
||||||
|
filecnt, (int) (img.zoom * 100.0), filenames[fileidx]);
|
||||||
|
|
||||||
|
if (n >= TITLE_LEN) {
|
||||||
|
win_title[TITLE_LEN - 2] = '.';
|
||||||
|
win_title[TITLE_LEN - 3] = '.';
|
||||||
|
win_title[TITLE_LEN - 4] = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
win_set_title(&win, win_title);
|
||||||
|
}
|
||||||
|
|
14
window.c
14
window.c
|
@ -72,8 +72,7 @@ void win_open(win_t *win) {
|
||||||
XSelectInput(e->dpy, win->xwin,
|
XSelectInput(e->dpy, win->xwin,
|
||||||
StructureNotifyMask | ExposureMask | KeyPressMask);
|
StructureNotifyMask | ExposureMask | KeyPressMask);
|
||||||
|
|
||||||
XStoreName(e->dpy, win->xwin, "sxiv");
|
win_set_title(win, "sxiv");
|
||||||
XSetIconName(e->dpy, win->xwin, "Sxiv");
|
|
||||||
|
|
||||||
if ((classhint = XAllocClassHint())) {
|
if ((classhint = XAllocClassHint())) {
|
||||||
classhint->res_name = "sxiv";
|
classhint->res_name = "sxiv";
|
||||||
|
@ -94,6 +93,17 @@ void win_close(win_t *win) {
|
||||||
XCloseDisplay(win->env.dpy);
|
XCloseDisplay(win->env.dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void win_set_title(win_t *win, const char *title) {
|
||||||
|
if (!win)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!title)
|
||||||
|
title = "sxiv";
|
||||||
|
|
||||||
|
XStoreName(win->env.dpy, win->xwin, title);
|
||||||
|
XSetIconName(win->env.dpy, win->xwin, title);
|
||||||
|
}
|
||||||
|
|
||||||
int win_configure(win_t *win, XConfigureEvent *cev) {
|
int win_configure(win_t *win, XConfigureEvent *cev) {
|
||||||
int changed;
|
int changed;
|
||||||
|
|
||||||
|
|
2
window.h
2
window.h
|
@ -46,6 +46,8 @@ typedef struct win_s {
|
||||||
void win_open(win_t*);
|
void win_open(win_t*);
|
||||||
void win_close(win_t*);
|
void win_close(win_t*);
|
||||||
|
|
||||||
|
void win_set_title(win_t*, const char*);
|
||||||
|
|
||||||
int win_configure(win_t*, XConfigureEvent*);
|
int win_configure(win_t*, XConfigureEvent*);
|
||||||
void win_clear(win_t*);
|
void win_clear(win_t*);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue