void win_open(win_t *win) { win_env_t *e; XClassHint classhint; XColor col; char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; Pixmap none; int gmask; if (win == NULL) return; e = &win->env; /* determine window offsets, width & height */ if (options->geometry == NULL) gmask = 0; else gmask = XParseGeometry(options->geometry, &win->x, &win->y, &win->w, &win->h); if ((gmask & WidthValue) != 0) win->sizehints.flags |= USSize; else win->w = WIN_WIDTH; if ((gmask & HeightValue) != 0) win->sizehints.flags |= USSize; else win->h = WIN_HEIGHT; if ((gmask & XValue) != 0) { if ((gmask & XNegative) != 0) { win->x += e->scrw - win->w; win->sizehints.win_gravity = NorthEastGravity; } win->sizehints.flags |= USPosition; } else { win->x = (e->scrw - win->w) / 2; } if ((gmask & YValue) != 0) { if ((gmask & YNegative) != 0) { win->y += e->scrh - win->h; if (win->sizehints.win_gravity == NorthEastGravity) win->sizehints.win_gravity = SouthEastGravity; else win->sizehints.win_gravity = SouthWestGravity; } win->sizehints.flags |= USPosition; } else { win->y = (e->scrh - win->h) / 2; } win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), win->x, win->y, win->w, win->h, 0, e->depth, InputOutput, e->vis, 0, None); if (win->xwin == None) die("could not create window"); XSelectInput(e->dpy, win->xwin, ExposureMask | ButtonReleaseMask | ButtonPressMask | KeyPressMask | PointerMotionMask | StructureNotifyMask); carrow = XCreateFontCursor(e->dpy, XC_left_ptr); chand = XCreateFontCursor(e->dpy, XC_fleur); cwatch = XCreateFontCursor(e->dpy, XC_watch); if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black", &col, &col) == 0) { die("could not allocate color: black"); } none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); gc = XCreateGC(e->dpy, win->xwin, 0, None); win_set_title(win, "sxiv"); classhint.res_class = "Sxiv"; classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv"; XSetClassHint(e->dpy, win->xwin, &classhint); XSetWMProtocols(e->dpy, win->xwin, &wm_delete_win, 1); win->h -= win->bar.h; win_update_sizehints(win); XMapWindow(e->dpy, win->xwin); XFlush(e->dpy); if (options->fullscreen) win_toggle_fullscreen(win); }
void win_open(win_t *win) { win_env_t *e; XClassHint classhint; XColor col; char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; Pixmap none; int gmask; if (!win) return; e = &win->env; /* determine window offsets, width & height */ if (!options->geometry) gmask = 0; else gmask = XParseGeometry(options->geometry, &win->x, &win->y, &win->w, &win->h); if (!(gmask & WidthValue)) win->w = WIN_WIDTH; if (win->w > e->scrw) win->w = e->scrw; if (!(gmask & HeightValue)) win->h = WIN_HEIGHT; if (win->h > e->scrh) win->h = e->scrh; if (!(gmask & XValue)) win->x = (e->scrw - win->w) / 2; else if (gmask & XNegative) win->x += e->scrw - win->w; if (!(gmask & YValue)) win->y = (e->scrh - win->h) / 2; else if (gmask & YNegative) win->y += e->scrh - win->h; win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), win->x, win->y, win->w, win->h, 0, e->depth, InputOutput, e->vis, 0, None); if (win->xwin == None) die("could not create window"); XSelectInput(e->dpy, win->xwin, StructureNotifyMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask); carrow = XCreateFontCursor(e->dpy, XC_left_ptr); chand = XCreateFontCursor(e->dpy, XC_fleur); cwatch = XCreateFontCursor(e->dpy, XC_watch); if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black", &col, &col)) { die("could not allocate color: black"); } none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); gc = XCreateGC(e->dpy, win->xwin, 0, None); win_set_title(win, "sxiv"); classhint.res_name = "sxiv"; classhint.res_class = "sxiv"; XSetClassHint(e->dpy, win->xwin, &classhint); if (options->fixed_win) win_set_sizehints(win); XMapWindow(e->dpy, win->xwin); XFlush(e->dpy); wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False); XSetWMProtocols(e->dpy, win->xwin, &wm_delete_win, 1); if (options->fullscreen) win_toggle_fullscreen(win); }
void win_open(win_t *win) { int c, i, j, n; long parent; win_env_t *e; XClassHint classhint; unsigned long *icon_data; XColor col; Cursor *cnone = &cursors[CURSOR_NONE].icon; char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; Pixmap none; int gmask; XSizeHints sizehints; Bool fullscreen = options->fullscreen && fs_support; e = &win->env; parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr); sizehints.flags = PWinGravity; sizehints.win_gravity = NorthWestGravity; /* determine window offsets, width & height */ if (options->geometry == NULL) gmask = 0; else gmask = XParseGeometry(options->geometry, &win->x, &win->y, &win->w, &win->h); if ((gmask & WidthValue) != 0) sizehints.flags |= USSize; else win->w = WIN_WIDTH; if ((gmask & HeightValue) != 0) sizehints.flags |= USSize; else win->h = WIN_HEIGHT; if ((gmask & XValue) != 0) { if ((gmask & XNegative) != 0) { win->x += e->scrw - win->w; sizehints.win_gravity = NorthEastGravity; } sizehints.flags |= USPosition; } else { win->x = 0; } if ((gmask & YValue) != 0) { if ((gmask & YNegative) != 0) { win->y += e->scrh - win->h; sizehints.win_gravity = sizehints.win_gravity == NorthEastGravity ? SouthEastGravity : SouthWestGravity; } sizehints.flags |= USPosition; } else { win->y = 0; } win->xwin = XCreateWindow(e->dpy, parent, win->x, win->y, win->w, win->h, 0, e->depth, InputOutput, e->vis, 0, NULL); if (win->xwin == None) error(EXIT_FAILURE, 0, "Error creating X window"); XSelectInput(e->dpy, win->xwin, ButtonReleaseMask | ButtonPressMask | KeyPressMask | PointerMotionMask | StructureNotifyMask); for (i = 0; i < ARRLEN(cursors); i++) { if (i != CURSOR_NONE) cursors[i].icon = XCreateFontCursor(e->dpy, cursors[i].name); } if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black", &col, &col) == 0) { error(EXIT_FAILURE, 0, "Error allocating color 'black'"); } none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); *cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); gc = XCreateGC(e->dpy, win->xwin, 0, None); n = icons[ARRLEN(icons)-1].size; icon_data = emalloc((n * n + 2) * sizeof(*icon_data)); for (i = 0; i < ARRLEN(icons); i++) { n = 0; icon_data[n++] = icons[i].size; icon_data[n++] = icons[i].size; for (j = 0; j < icons[i].cnt; j++) { for (c = icons[i].data[j] >> 4; c >= 0; c--) icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F]; } XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32, i == 0 ? PropModeReplace : PropModeAppend, (unsigned char *) icon_data, n); } free(icon_data); win_set_title(win, "sxiv"); classhint.res_class = RES_CLASS; classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv"; XSetClassHint(e->dpy, win->xwin, &classhint); XSetWMProtocols(e->dpy, win->xwin, &atoms[ATOM_WM_DELETE_WINDOW], 1); sizehints.width = win->w; sizehints.height = win->h; sizehints.x = win->x; sizehints.y = win->y; XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints); win->h -= win->bar.h; win->buf.w = e->scrw; win->buf.h = e->scrh; win->buf.pm = XCreatePixmap(e->dpy, win->xwin, win->buf.w, win->buf.h, e->depth); XSetForeground(e->dpy, gc, fullscreen ? win->black.pixel : win->bg.pixel); XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm); XMapWindow(e->dpy, win->xwin); XFlush(e->dpy); if (fullscreen) win_toggle_fullscreen(win); }
void runner_change_callback( resolver* RS, const char* key, size_t key_len, const char* val, size_t val_len ) { if( g_changeStack >= MAX_CHANGE_STACK ) { fprintf( stderr, "ERROR: exceeded change stack (%d changes)\n", MAX_CHANGE_STACK ); return; } g_changeStack++; #define ISKEY( s ) ( key_len == sizeof(s)-1 && !memcmp( s, key, sizeof(s)-1 ) ) #define PARSEINT() str_to_int( val ) #define PARSEENUM( enumstr ) enumstr_to_int( val, enumstr ) #define NOTNULL() ( val_len && ( val[0] != '0' || val[1] != 0 ) ) X_DBG( printf( "CHANGE \"%.*s\" = \"%.*s\"\n", key_len, key, val_len, val ) ); if( ISKEY( "quit" ) ){ if( NOTNULL() ) win_quit(); } else if( ISKEY( "run" ) ){ if( NOTNULL() ) runner_run( val ); } else if( ISKEY( "test" ) ) { if( NOTNULL() ) { if( g_inTest ) { fprintf( stderr, "ERROR: 'test' action recursion, cannot start testing in testing progress callback\n" ); return; } g_inTest = 1; runner_fsproc( 1 ); g_inTest = 0; } } else if( ISKEY( "window.width" ) ){ g_window_width = PARSEINT(); g_requested_changes |= REQCHG_WINDOWSIZE; } else if( ISKEY( "window.height" ) ){ g_window_height = PARSEINT(); g_requested_changes |= REQCHG_WINDOWSIZE; } else if( ISKEY( "window.image" ) ){ win_set_background_image( PARSEINT() ); } else if( ISKEY( "window.title" ) ) { win_set_title( val ); } else if( key_len && *key == '#' ) { /* CONTROL SETTINGS */ const char* nkey = NULL; int ctlid = str_to_int_ext( key + 1, &nkey ); if( ctlid < 0 ) { fprintf( stderr, "ERROR: invalid control id=%d\n", ctlid ); goto end; } if( ctlid > MAX_CONTROLS ) { fprintf( stderr, "ERROR: exceeded MAX_CONTROLS with id=%d\n", ctlid ); goto end; } if( ctlid >= g_numControls ) win_ctl_resize( ctlid + 1 ); key_len -= nkey - key; key = nkey; runner_change_ctl_handler( RS, &g_controls[ ctlid ], key, key_len, val, val_len ); } else if( key_len >= sizeof("event.control")-1 && !strncmp( key, "event.control", sizeof( "event.control" )-1 ) ) { key += sizeof("event.control")-1; key_len -= sizeof("event.control")-1; runner_change_ctl_handler( RS, g_event_control, key, key_len, val, val_len ); } end: g_changeStack--; }
void win_open(win_t *win) { int c, i, j, n; win_env_t *e; XClassHint classhint; XSetWindowAttributes attr; unsigned long attr_mask; unsigned long *icon_data; XColor col; char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; Pixmap none; int gmask; XSizeHints sizehints; if (win == NULL) return; e = &win->env; sizehints.flags = PWinGravity; sizehints.win_gravity = NorthWestGravity; /* determine window offsets, width & height */ if (options->geometry == NULL) gmask = 0; else gmask = XParseGeometry(options->geometry, &win->x, &win->y, &win->w, &win->h); if ((gmask & WidthValue) != 0) sizehints.flags |= USSize; else win->w = WIN_WIDTH; if ((gmask & HeightValue) != 0) sizehints.flags |= USSize; else win->h = WIN_HEIGHT; if ((gmask & XValue) != 0) { if ((gmask & XNegative) != 0) { win->x += e->scrw - win->w; sizehints.win_gravity = NorthEastGravity; } sizehints.flags |= USPosition; } else { win->x = 0; } if ((gmask & YValue) != 0) { if ((gmask & YNegative) != 0) { win->y += e->scrh - win->h; sizehints.win_gravity = sizehints.win_gravity == NorthEastGravity ? SouthEastGravity : SouthWestGravity; } sizehints.flags |= USPosition; } else { win->y = 0; } attr.background_pixel = win->bgcol; attr_mask = CWBackPixel; win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), win->x, win->y, win->w, win->h, 0, e->depth, InputOutput, e->vis, attr_mask, &attr); if (win->xwin == None) die("could not create window"); XSelectInput(e->dpy, win->xwin, ExposureMask | ButtonReleaseMask | ButtonPressMask | KeyPressMask | PointerMotionMask | StructureNotifyMask); carrow = XCreateFontCursor(e->dpy, XC_left_ptr); chand = XCreateFontCursor(e->dpy, XC_fleur); cwatch = XCreateFontCursor(e->dpy, XC_watch); if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black", &col, &col) == 0) { die("could not allocate color: black"); } none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8); cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0); gc = XCreateGC(e->dpy, win->xwin, 0, None); n = icons[ARRLEN(icons)-1].size; icon_data = s_malloc((n * n + 2) * sizeof(*icon_data)); for (i = 0; i < ARRLEN(icons); i++) { n = 0; icon_data[n++] = icons[i].size; icon_data[n++] = icons[i].size; for (j = 0; j < icons[i].cnt; j++) { for (c = icons[i].data[j] >> 4; c >= 0; c--) icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F]; } XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32, i == 0 ? PropModeReplace : PropModeAppend, (unsigned char *) icon_data, n); } free(icon_data); win_set_title(win, "sxiv"); classhint.res_class = "Sxiv"; classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv"; XSetClassHint(e->dpy, win->xwin, &classhint); XSetWMProtocols(e->dpy, win->xwin, &atoms[ATOM_WM_DELETE_WINDOW], 1); sizehints.width = win->w; sizehints.height = win->h; sizehints.x = win->x; sizehints.y = win->y; XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints); win->h -= win->bar.h; XMapWindow(e->dpy, win->xwin); XFlush(e->dpy); if (options->fullscreen) win_toggle_fullscreen(win); }