Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:zhonghuaren
wm2
wm2-4.dif
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File wm2-4.dif of Package wm2
--- Client.C +++ Client.C @@ -4,6 +4,10 @@ #include <X11/Xutil.h> +#if I18N +#include <X11/Xmu/Atoms.h> +#endif + const char *const Client::m_defaultLabel = "incognito"; @@ -379,12 +383,59 @@ int format; unsigned long n, extra; int status; + Boolean retried = False; +tryagain: status = XGetWindowProperty(d, w, a, 0L, len, False, type, &realType, &format, &n, &extra, p); if (status != Success || *p == 0) return -1; if (n == 0) XFree((void *) *p); + if (type == XA_STRING || retried) { + if (realType != XA_STRING || format != 8) { +#if I18N + // XA_STRING is needed by a caller. But XGetWindowProperty() + // returns other typed data. So try to convert them. + XTextProperty textprop; + textprop.value = *p; + textprop.encoding = realType; + textprop.format = format; + textprop.nitems = n; + + char **list; + int num, cnt; + cnt = XmbTextPropertyToTextList(d, &textprop, &list, &num); + unsigned char *string; + if (cnt == Success && num > 0 && *list) { + string = (unsigned char*)NewString(*list); + XFreeStringList(list); + n = num; + } else if (cnt > Success) { + fprintf(stderr, "Something wrong, cannot conver " + "text property\n" + " original type %ld, string %s\n" + " converted string %s\n" + " decide to use original value as STRING\n", + textprop.encoding, textprop.value, *list); + string = (unsigned char*)NewString(*(char**)p); + XFreeStringList(list); + n = n; + } else if (!retried) { + retried = True; + type = AnyPropertyType; + goto tryagain; + } else { + string = NULL; + n = 0; + } + XFree((void *) *p); + *p = string; +#else + XFree((void *) *p); + *p = NULL; +#endif + } + } return n; } --- Config.h +++ Config.h @@ -2,11 +2,19 @@ #ifndef _CONFIG_H_ #define _CONFIG_H_ +#define I18N 1 + +#if I18N +#define CONFIG_NICE_FONT "-*-lucida-bold-r-*-*-14-*-75-75-*-*-*-*,-*-*-medium-r-*-*-14-*-75-75-*-*-*-*" +#define CONFIG_NICE_MENU_FONT "-*-lucida-medium-r-*-*-14-*-75-75-*-*-*-*,-*-*-medium-r-*-*-14-*-75-75-*-*-*-*" +#define CONFIG_NASTY_FONT "fixed,-*-*-*-*-*-*-14-*-75-75-*-*-*-*" +#else #define CONFIG_NICE_FONT "-*-lucida-bold-r-*-*-14-*-75-75-*-*-*-*" #define CONFIG_NICE_MENU_FONT "-*-lucida-medium-r-*-*-14-*-75-75-*-*-*-*" #define CONFIG_NASTY_FONT "fixed" +#endif -#define CONFIG_EXEC_USING_SHELL False +#define CONFIG_EXEC_USING_SHELL True #define CONFIG_NEW_WINDOW_COMMAND "xterm" #define CONFIG_EVERYTHING_ON_ROOT_MENU False @@ -43,7 +51,14 @@ // recalculated afresh every time their focus changes. This will // probably slow things down hideously, but has been reported as // necessary on some systems (possibly SunOS 4.x with OpenWindows). -#define CONFIG_PROD_SHAPE False +#define CONFIG_PROD_SHAPE True #endif + + + + + + + --- General.h +++ General.h @@ -32,7 +32,7 @@ #define NewString(x) (strcpy((char *)malloc(strlen(x)+1),(x))) #ifndef SIGNAL_CALLBACK_TYPE -#define SIGNAL_CALLBACK_TYPE (void (*)(...)) +#define SIGNAL_CALLBACK_TYPE (void (*)(int)) #endif #define signal(x,y) \ --- Makefile +++ Makefile @@ -1,8 +1,8 @@ -LIBS = -L/usr/X11/lib -lXext -lX11 -lXmu -lm +LIBS = -L/usr/X11R6/lib -lXext -lX11 -lXmu -lm CC = gcc -CCC = gcc +CCC = g++ CFLAGS = -O2 OBJECTS = Border.o Buttons.o Client.o Events.o Main.o Manager.o Rotated.o --- Manager.C +++ Manager.C @@ -1,11 +1,18 @@ #include "Manager.h" #include "Client.h" + +#if I18N +#include <X11/Xlocale.h> +#endif + #include <string.h> #include <X11/Xproto.h> #include <sys/types.h> #include <sys/wait.h> + #include "Cursors.h" +#include <X11/cursorfont.h> Atom Atoms::wm_state; Atom Atoms::wm_changeState; @@ -33,6 +40,24 @@ " %s\n Copying and redistribution encouraged. " "No warranty.\n\n", XV_COPYRIGHT); +#if I18N + if (!setlocale(LC_ALL, "")) + fprintf(stderr, + "Warning: locale not supported by C library, locale unchanged\n"); + if (!XSupportsLocale()) { + fprintf(stderr, + "Warning: locale not supported by Xlib, locale set to C\n"); + setlocale(LC_ALL, "C"); + } + if (!XSetLocaleModifiers("")) + fprintf(stderr, + "Warning: X locale modifiers not supported, using default\n"); + char* ret_setlocale = setlocale(LC_ALL, NULL); + // re-query in case overwritten + fprintf(stderr, "\n Operating system locale is \"%s\".\n", + ret_setlocale ? ret_setlocale : "(NULL)"); +#endif + if (CONFIG_AUTO_RAISE) { if (CONFIG_CLICK_TO_FOCUS) { fatal("can't have auto-raise-with-delay with click-to-focus"); @@ -161,8 +186,12 @@ XFreeCursor(m_display, m_vCursor); XFreeCursor(m_display, m_hCursor); XFreeCursor(m_display, m_vhCursor); - - XFreeFont(m_display, m_menuFont); +#if I18N + XFreeFontSet(m_display, m_fontset); +#else + XFreeFont(m_display, m_font); +#endif + XFreeGC(m_display, m_menuGC); XCloseDisplay(m_display); @@ -300,9 +329,30 @@ values.line_width = 0; values.subwindow_mode = IncludeInferiors; +#if I18N + char **ml; + int mc; + char *ds; + + m_fontset = XCreateFontSet(display(), CONFIG_NICE_MENU_FONT, + &ml, &mc, &ds); + if (!m_fontset) + m_fontset = XCreateFontSet(display(), CONFIG_NASTY_FONT, + &ml, &mc, &ds); + if (m_fontset) { + XFontStruct **fs_list; + XFontsOfFontSet(m_fontset, &fs_list, &ml); + m_menuFont = fs_list[0]; + } else { + m_menuFont = NULL; + } +#define XTextWidth(x,y,z) XmbTextEscapement(m_fontset,y,z) +#define XDrawString(t,u,v,w,x,y,z) XmbDrawString(t,u,m_fontset,v,w,x,y,z) +#else m_menuFont = XLoadQueryFont(display(), CONFIG_NICE_MENU_FONT); - if (!m_menuFont) m_menuFont = XLoadQueryFont(display(), - CONFIG_NASTY_FONT); + if (!m_menuFont) m_menuFont = XLoadQueryFont(display(), CONFIG_NASTY_FONT); +#endif + if (!m_menuFont) fatal("couldn't load default menu font\n"); values.font = m_menuFont->fid; @@ -324,7 +374,8 @@ sprintf(error, "couldn't load %s colour", desc); fatal(error); - } else return nearest.pixel; + } + return nearest.pixel; } @@ -368,7 +419,7 @@ return m_currentTime; } -void WindowManager::sigHandler() +void WindowManager::sigHandler(int) { m_signalled = True; } --- Manager.h +++ Manager.h @@ -85,7 +85,7 @@ static Boolean m_initialising; static int errorHandler(Display *, XErrorEvent *); - static void sigHandler(); + static void sigHandler(int); static int m_signalled; void initialiseScreen(); @@ -94,6 +94,7 @@ GC m_menuGC; Window m_menuWindow; XFontStruct *m_menuFont; + XFontSet m_fontset; unsigned long m_menuForegroundPixel; unsigned long m_menuBackgroundPixel; unsigned long m_menuBorderPixel; --- Rotated.C +++ Rotated.C @@ -14,15 +14,24 @@ /* ********************************************************************** */ +// Minor modifications by Chris Cannam for wm2/wmx +// Major modifications by Kazushi (Jam) Marukawa for wm2/wmx i18n patch + #include <X11/Xlib.h> #include <X11/Xutil.h> #include <stdlib.h> #include <string.h> #include <stdio.h> +#include "Config.h" #include "Rotated.h" +#if I18N +#undef NOPIXMAP +#define NOPIXMAP 1 // anyway, NOPIXMAP +#endif + /* ---------------------------------------------------------------------- */ @@ -157,7 +166,26 @@ XSetBackground(dpy, font_gc, off); /* load the font ... */ +#if I18N + char **ml; + int mc; + char *ds; + + XFontSet fontset; + fontset = XCreateFontSet(dpy, fontname, &ml, &mc, &ds); + if (fontset) { + XFontStruct **fs_list; + XFontsOfFontSet(fontset, &fs_list, &ml); + fontstruct = fs_list[0]; + } else { + fontstruct = NULL; + } +#define XTextWidth(x,y,z) XmbTextEscapement(rotfont->xfontset,y,z) +#define XDrawString(t,u,v,w,x,y,z) XmbDrawString(t,u,rotfont->xfontset,v,w,x,y,z) +#define XDrawImageString(t,u,v,w,x,y,z) XmbDrawString(t,u,rotfont->xfontset,v,w,x,y,z) +#else fontstruct = XLoadQueryFont(dpy, fontname); +#endif if (fontstruct == NULL) { xv_errno = XV_NOFONT; return NULL; @@ -190,6 +218,15 @@ rotfont->height = rotfont->max_ascent+rotfont->max_descent; /* remember xfontstruct for `normal' text ... */ +#if NOPIXMAP +#if I18N + rotfont->xfontset = fontset; +#endif + rotfont->xfontstruct = fontstruct; +#else +#if I18N + PIXMAP implementation cannot treat I18N +#endif if (dir == 0) rotfont->xfontstruct = fontstruct; else { @@ -328,6 +365,7 @@ XFreeFont(dpy, fontstruct); } +#endif /* free pixmap and GC ... */ XFreePixmap(dpy, canvas); @@ -346,12 +384,23 @@ { int ichar; +#if NOPIXMAP +#if I18N + XFreeFontSet(dpy, rotfont->xfontset); +#else + XFreeFont(dpy, rotfont->xfontstruct); +#endif +#else +#if I18N + PIXMAP implementation cannot treat I18N +#endif if (rotfont->dir == 0) XFreeFont(dpy, rotfont->xfontstruct); else /* loop through each character, freeing its pixmap ... */ for (ichar = rotfont->min_char-32; ichar <= rotfont->max_char-32; ichar++) XFreePixmap(dpy, rotfont->per_char[ichar].glyph.bm); +#endif /* rotfont should never be referenced again ... */ free((char *)rotfont->name); @@ -370,6 +419,9 @@ if (str == NULL) return 0; +#if NOPIXMAP + width = XTextWidth(rotfont->xfontstruct, str, strlen(str)); +#else if (rotfont->dir == 0) width = XTextWidth(rotfont->xfontstruct, str, strlen(str)); @@ -381,6 +433,7 @@ if (ichar >= 0 && ichar<95) width += rotfont->per_char[ichar].width; } +#endif return width; } @@ -404,11 +457,177 @@ XCopyGC(dpy, gc, GCForeground|GCBackground, my_gc); +#if NOPIXMAP + /* a horizontal string is easy ... */ + if (dir == 0) { + XSetFillStyle(dpy, my_gc, FillSolid); + XSetFont(dpy, my_gc, rotfont->xfontstruct->fid); + XDrawString(dpy, drawable, my_gc, x, y, str, len); + + return; + } + + /* vertical or upside down ... */ + + XImage *I1, *I2; + unsigned char *vertdata, *bitdata; + int vert_w, vert_h, vert_len, bit_w, bit_h, bit_len; + char val; + + /* useful macros ... */ + int screen = DefaultScreen(dpy); + Window root = DefaultRootWindow(dpy); + + int ascent = rotfont->max_ascent; + int descent = rotfont->max_descent; + int width = XRotTextWidth(rotfont, str, len); + int height = rotfont->height; + if (width < 1) width = 1; + if (height < 1) height = 1; + + /* glyph width and height when vertical ... */ + vert_w = width; + vert_h = height; + + /* width in bytes ... */ + vert_len = (vert_w-1)/8+1; + + /* create the depth 1 canvas bitmap ... */ + Pixmap canvas = XCreatePixmap(dpy, root, width, height, 1); + + /* create a GC ... */ + GC font_gc = XCreateGC(dpy, canvas, 0, 0); + XSetBackground(dpy, font_gc, 0); + + /* clear canvas */ + XSetForeground(dpy, font_gc, 0); + XFillRectangle(dpy, canvas, font_gc, 0, 0, width, height); + + /* draw the character centre top right on canvas ... */ + XSetForeground(dpy, font_gc, 1); + XSetFont(dpy, font_gc, rotfont->xfontstruct->fid); + XDrawImageString(dpy, canvas, font_gc, 0, height-descent, str, len); + + /* reserve memory for first XImage ... */ + vertdata = (unsigned char *) malloc((unsigned)(vert_len*vert_h)); + if (vertdata == NULL) { + xv_errno = XV_NOMEM; + return; + } + + /* create the XImage ... */ + I1 = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, + 0, (char *)vertdata, vert_w, vert_h, 8, 0); + + if (I1 == NULL) { + xv_errno = XV_NOXIMAGE; + return; + } + + I1->byte_order = I1->bitmap_bit_order = MSBFirst; + + /* extract character from canvas ... */ + XGetSubImage(dpy, canvas, 0, 0, + vert_w, vert_h, 1, XYPixmap, I1, 0, 0); + I1->format = XYBitmap; + + /* width, height of rotated character ... */ + if (dir == 2) { + bit_w = vert_w; + bit_h = vert_h; + } else { + bit_w = vert_h; + bit_h = vert_w; + } + + /* width in bytes ... */ + bit_len = (bit_w-1)/8 + 1; + + /* reserve memory for the rotated image ... */ + bitdata = (unsigned char *)calloc((unsigned)(bit_h*bit_len), 1); + if (bitdata == NULL) { + xv_errno = XV_NOMEM; + return; + } + + /* create the image ... */ + I2 = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, 0, + (char *)bitdata, bit_w, bit_h, 8, 0); + + if (I2 == NULL) { + xv_errno = XV_NOXIMAGE; + return; + } + + I2->byte_order = I2->bitmap_bit_order = MSBFirst; + + /* map vertical data to rotated character ... */ + int j; + for (j = 0; j < bit_h; j++) { + for (i = 0; i < bit_w; i++) { + /* map bits ... */ + if (dir == 1) + val = vertdata[i*vert_len + (vert_w-j-1)/8] & + (128>>((vert_w-j-1)%8)); + + else if (dir == 2) + val = vertdata[(vert_h-j-1)*vert_len + (vert_w-i-1)/8] & + (128>>((vert_w-i-1)%8)); + + else + val = vertdata[(vert_h-i-1)*vert_len + j/8] & + (128>>(j%8)); + + if (val) + bitdata[j*bit_len + i/8] = bitdata[j*bit_len + i/8] | + (128>>(i%8)); + } + } + + /* create this character's bitmap ... */ + Pixmap image = XCreatePixmap(dpy, root, bit_w, bit_h, 1); + + /* put the image into the bitmap ... */ + XPutImage(dpy, image, font_gc, I2, 0, 0, 0, 0, bit_w, bit_h); + + /* free the image and data ... */ + XDestroyImage(I1); + XDestroyImage(I2); + /* free((char *)bitdata); -- XDestroyImage does this + free((char *)vertdata);*/ + + /* free pixmap and GC ... */ + XFreePixmap(dpy, canvas); + XFreeGC(dpy, font_gc); + + /* suitable offset ... */ + if (dir == 1) { + xp = x-rotfont->max_ascent; + yp = y-width; //rotfont->rbearing; + } + else if (dir == 2) { + xp = x-width; //rotfont->rbearing; + yp = y-rotfont->max_descent+1; + } + else { + xp = x-rotfont->max_descent+1; + yp = y+0; //rotfont->lbearing; + } + + XSetFillStyle(dpy, my_gc, FillStippled); + XSetStipple(dpy, my_gc, image); + XSetTSOrigin(dpy, my_gc, xp, yp); + XFillRectangle(dpy, drawable, my_gc, xp, yp, + bit_w, bit_h); + + XFreePixmap(dpy, image); +#else /* a horizontal string is easy ... */ if (dir == 0) { XSetFillStyle(dpy, my_gc, FillSolid); XSetFont(dpy, my_gc, rotfont->xfontstruct->fid); XDrawString(dpy, drawable, my_gc, x, y, str, len); + return; } @@ -454,6 +673,7 @@ y += rotfont->per_char[ichar].width; } } +#endif } --- Rotated.h +++ Rotated.h @@ -48,6 +48,7 @@ int min_char; char *name; + XFontSet xfontset; XFontStruct *xfontstruct; XRotCharStruct per_char[95];
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor