mirror of
https://github.com/LukeSmithxyz/st.git
synced 2024-11-22 15:25:58 +01:00
use XCreateWindow(), set gravity bit.
This commit is contained in:
parent
273d4ba938
commit
8c3757986a
1 changed files with 25 additions and 17 deletions
42
st.c
42
st.c
|
@ -104,6 +104,7 @@ typedef struct {
|
||||||
/* Purely graphic info */
|
/* Purely graphic info */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Display* dis;
|
Display* dis;
|
||||||
|
Colormap cmap;
|
||||||
Window win;
|
Window win;
|
||||||
Pixmap buf;
|
Pixmap buf;
|
||||||
int scr;
|
int scr;
|
||||||
|
@ -1121,11 +1122,10 @@ void
|
||||||
xloadcols(void) {
|
xloadcols(void) {
|
||||||
int i, r, g, b;
|
int i, r, g, b;
|
||||||
XColor color;
|
XColor color;
|
||||||
Colormap cmap = DefaultColormap(xw.dis, xw.scr);
|
|
||||||
unsigned long white = WhitePixel(xw.dis, xw.scr);
|
unsigned long white = WhitePixel(xw.dis, xw.scr);
|
||||||
|
|
||||||
for(i = 0; i < 16; i++) {
|
for(i = 0; i < 16; i++) {
|
||||||
if (!XAllocNamedColor(xw.dis, cmap, colorname[i], &color, &color)) {
|
if (!XAllocNamedColor(xw.dis, xw.cmap, colorname[i], &color, &color)) {
|
||||||
dc.col[i] = white;
|
dc.col[i] = white;
|
||||||
fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
|
fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
|
||||||
} else
|
} else
|
||||||
|
@ -1139,7 +1139,7 @@ xloadcols(void) {
|
||||||
color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
|
color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
|
||||||
color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
|
color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
|
||||||
color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
|
color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
|
||||||
if (!XAllocColor(xw.dis, cmap, &color)) {
|
if (!XAllocColor(xw.dis, xw.cmap, &color)) {
|
||||||
dc.col[i] = white;
|
dc.col[i] = white;
|
||||||
fprintf(stderr, "Could not allocate color %d\n", i);
|
fprintf(stderr, "Could not allocate color %d\n", i);
|
||||||
} else
|
} else
|
||||||
|
@ -1149,7 +1149,7 @@ xloadcols(void) {
|
||||||
|
|
||||||
for(r = 0; r < 24; r++, i++) {
|
for(r = 0; r < 24; r++, i++) {
|
||||||
color.red = color.green = color.blue = 0x0808 + 0x0a0a * r;
|
color.red = color.green = color.blue = 0x0808 + 0x0a0a * r;
|
||||||
if (!XAllocColor(xw.dis, cmap, &color)) {
|
if (!XAllocColor(xw.dis, xw.cmap, &color)) {
|
||||||
dc.col[i] = white;
|
dc.col[i] = white;
|
||||||
fprintf(stderr, "Could not allocate color %d\n", i);
|
fprintf(stderr, "Could not allocate color %d\n", i);
|
||||||
} else
|
} else
|
||||||
|
@ -1184,6 +1184,8 @@ xhints(void)
|
||||||
|
|
||||||
void
|
void
|
||||||
xinit(void) {
|
xinit(void) {
|
||||||
|
XSetWindowAttributes attrs;
|
||||||
|
|
||||||
if(!(xw.dis = XOpenDisplay(NULL)))
|
if(!(xw.dis = XOpenDisplay(NULL)))
|
||||||
die("Can't open display\n");
|
die("Can't open display\n");
|
||||||
xw.scr = XDefaultScreen(xw.dis);
|
xw.scr = XDefaultScreen(xw.dis);
|
||||||
|
@ -1197,26 +1199,33 @@ xinit(void) {
|
||||||
xw.ch = dc.font->ascent + dc.font->descent;
|
xw.ch = dc.font->ascent + dc.font->descent;
|
||||||
|
|
||||||
/* colors */
|
/* colors */
|
||||||
|
xw.cmap = XDefaultColormap(xw.dis, xw.scr);
|
||||||
xloadcols();
|
xloadcols();
|
||||||
|
|
||||||
/* windows */
|
/* window - default size */
|
||||||
xw.bufh = term.row * xw.ch;
|
xw.bufh = 24 * xw.ch;
|
||||||
xw.bufw = term.col * xw.cw;
|
xw.bufw = 80 * xw.cw;
|
||||||
xw.h = xw.bufh + 2*BORDER;
|
xw.h = xw.bufh + 2*BORDER;
|
||||||
xw.w = xw.bufw + 2*BORDER;
|
xw.w = xw.bufw + 2*BORDER;
|
||||||
xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
|
|
||||||
xw.w, xw.h, 0,
|
attrs.background_pixel = dc.col[DefaultBG];
|
||||||
dc.col[DefaultBG],
|
attrs.border_pixel = dc.col[DefaultBG];
|
||||||
dc.col[DefaultBG]);
|
attrs.bit_gravity = NorthWestGravity;
|
||||||
|
attrs.event_mask = ExposureMask | KeyPressMask
|
||||||
|
| StructureNotifyMask | FocusChangeMask | PointerMotionMask
|
||||||
|
| ButtonPressMask | ButtonReleaseMask;
|
||||||
|
attrs.colormap = xw.cmap;
|
||||||
|
|
||||||
|
xw.win = XCreateWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
|
||||||
|
xw.w, xw.h, 0, XDefaultDepth(xw.dis, xw.scr), InputOutput,
|
||||||
|
XDefaultVisual(xw.dis, xw.scr),
|
||||||
|
CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
|
||||||
|
| CWColormap,
|
||||||
|
&attrs);
|
||||||
xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
|
xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
|
||||||
/* gc */
|
/* gc */
|
||||||
dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
|
dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
|
||||||
|
|
||||||
/* event mask */
|
|
||||||
XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask
|
|
||||||
| StructureNotifyMask | FocusChangeMask | PointerMotionMask
|
|
||||||
| ButtonPressMask | ButtonReleaseMask);
|
|
||||||
|
|
||||||
XMapWindow(xw.dis, xw.win);
|
XMapWindow(xw.dis, xw.win);
|
||||||
xhints();
|
xhints();
|
||||||
XStoreName(xw.dis, xw.win, opt_title ? opt_title : "st");
|
XStoreName(xw.dis, xw.win, opt_title ? opt_title : "st");
|
||||||
|
@ -1432,7 +1441,6 @@ resize(XEvent *e) {
|
||||||
xw.bufw = MAX(1, xw.bufw);
|
xw.bufw = MAX(1, xw.bufw);
|
||||||
XFreePixmap(xw.dis, xw.buf);
|
XFreePixmap(xw.dis, xw.buf);
|
||||||
xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
|
xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
|
||||||
draw(SCREEN_REDRAW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue