changeset: 49:48dd9648a0d9
user: Anselm R. Garbe <arg_AT_suckless.org>
date: Fri Mar 02 15:24:59 2007 +0100
summary: enabling UTF8/locale support in st
diff -r 6375affefa2f -r 48dd9648a0d9 main.c
--- a/main.c Fri Mar 02 15:17:04 2007 +0100
+++ b/main.c Fri Mar 02 15:24:59 2007 +0100
@@ -4,6 +4,7 @@
#include "st.h"
#include <locale.h>
#include <stdio.h>
+#include <X11/Xutil.h>
#include <X11/cursorfont.h>
/* static */
@@ -64,7 +65,7 @@ initfont(const char *fontstr) {
missing = NULL;
if(dc.font.set)
XFreeFontSet(dpy, dc.font.set);
- dc.font.set = NULL;//XCreateFontSet(dpy, fontstr, &missing, &n, &def);
+ dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
if(missing) {
while(n--)
fprintf(stderr, "missing fontset: %s\n", missing[n]);
@@ -105,9 +106,53 @@ initfont(const char *fontstr) {
wh = screen_rows * dc.font.height;
}
+static void
+initwin(void) {
+ char *args[] = { NULL };
+ XSizeHints sh;
+ XWMHints wmh;
+ XClassHint ch;
+ XGCValues gcv;
+
+ win = XCreateSimpleWindow(dpy, root, 0, 0, ww, wh, 0, dc.bg[0], dc.bg[0]);
+ XSelectInput(dpy, win, StructureNotifyMask);
+ XMapWindow(dpy, win);
+ /* Wait for the window to be mapped */
+ wait_for_specific_event(MapNotify);
+ gc = XCreateGC(dpy, win, 0, NULL);
+ XSetForeground(dpy, gc, dc.fg[0]);
+ XSetBackground(dpy, gc, dc.bg[0]);
+ if(!dc.font.set)
+ XSetFont(dpy, gc, dc.font.xfont->fid);
+ XDefineCursor(dpy, win, cursor);
+ sh.x = sh.y = 0;
+ sh.width = ww;
+ sh.height = wh;
+ sh.width_inc = dc.font.width;
+ sh.height_inc = dc.font.height;
+ sh.flags = PPosition | PSize | PResizeInc;
+ wmh.input = 1;
+ wmh.flags = InputHint;
+ ch.res_name = "st";
+ ch.res_class = "st";
+ XSetWMProperties(dpy, win, NULL, NULL, &args[0], 0, &sh, &wmh, &ch);
+ XStoreName(dpy, win, "st");
+ XSync(dpy, 0);
+ set_text_attrs(-1, 0);
+ return 0;
+}
+
/* extern */
DC dc = { 0 };
+Display *dpy;
+Window win, root;
+GC gc;
+Colormap cmap;
+Cursor cursor;
+int screen;
+int ww;
+int wh;
int
main(int argc, char **argv) {
@@ -116,13 +161,13 @@ main(int argc, char **argv) {
if(!(dpy = XOpenDisplay(0)))
eprint("cannot open display\n");
screen = DefaultScreen(dpy);
+ root = RootWindow(dpy, screen);
cmap = DefaultColormap(dpy, screen);
if(!(cursor = XCreateFontCursor(dpy, XC_xterm)))
eprint("cannot create cursor\n");
initcolors();
initfont(DEFAULT_FONT);
- if(init_window())
- return 1;
+ initwin();
if(init_vt_buffer())
return 1;
diff -r 6375affefa2f -r 48dd9648a0d9 st.h
--- a/st.h Fri Mar 02 15:17:04 2007 +0100
+++ b/st.h Fri Mar 02 15:24:59 2007 +0100
@@ -8,8 +8,7 @@
#define END_KEY "\033[4~"
#define PREV_KEY "\033[5~"
#define NEXT_KEY "\033[6~"
-#define DEFAULT_FONT "fixed"
-//"-*-proggyclean-medium-r-*-*-13-*-*-*-*-*-*-*"
+#define DEFAULT_FONT "-*-proggyclean-medium-r-*-*-13-*-*-*-*-*-*-*"
#define DEFAULT_NR_ROWS 24
#define DEFAULT_NR_COLS 80
#define DELETE_KEY "\033[3~"
@@ -82,7 +81,7 @@ extern text_row_t *text_screen;
extern text_row_t *text_screen;
extern text_letter_t text_attrs;
extern Display *dpy;
-extern Window win;
+extern Window win, root;
extern GC gc;
extern Colormap cmap;
extern Cursor cursor;
diff -r 6375affefa2f -r 48dd9648a0d9 ui.c
--- a/ui.c Fri Mar 02 15:17:04 2007 +0100
+++ b/ui.c Fri Mar 02 15:24:59 2007 +0100
@@ -5,52 +5,6 @@
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
-#include <X11/Xutil.h>
-
-Display *dpy;
-Window win;
-GC gc;
-Colormap cmap;
-Cursor cursor;
-
-int screen;
-int ww;
-int wh;
-
-int
-init_window(void) {
- char *args[] = { NULL };
- XSizeHints sh;
- XWMHints wmh;
- XClassHint ch;
-
- win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, ww, wh, 0, dc.bg[0], dc.bg[0]);
- XSelectInput(dpy, win, StructureNotifyMask);
- XMapWindow(dpy, win);
- /* Wait for the window to be mapped */
- wait_for_specific_event(MapNotify);
- gc = XCreateGC(dpy, win, 0, NULL);
- XSetForeground(dpy, gc, dc.fg[0]);
- XSetBackground(dpy, gc, dc.bg[0]);
- XDefineCursor(dpy, win, cursor);
- sh.x = sh.y = 0;
- sh.width = ww;
- sh.height = wh;
- sh.width_inc = dc.font.width;
- sh.height_inc = dc.font.height;
- sh.flags = PPosition | PSize | PResizeInc;
- wmh.input = 1;
- wmh.flags = InputHint;
- ch.res_name = "st";
- ch.res_class = "st";
- XSetWMProperties(dpy, win, NULL, NULL, &args[0], 0, &sh, &wmh, &ch);
- XStoreName(dpy, win, "st");
- XSync(dpy, 0);
- set_text_attrs(-1, 0);
- if(!dc.font.set)
- XSetFont(dpy, gc, dc.font.xfont->fid);
- return 0;
-}
void
wait_for_specific_event(int event_type) {
@@ -71,7 +25,7 @@ void
void
win_draw_string(int row, int col, char *s, int l) {
if(dc.font.set)
- XmbDrawString(dpy, win, gc, dc.font.set, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
+ XmbDrawString(dpy, win, dc.font.set, gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
else
XDrawImageString(dpy, win, gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
}
Received on Fri Mar 02 2007 - 15:27:18 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:03 UTC