From 5298849122d7e3f2576a89a690dc31ddd42f6dd7 Mon Sep 17 00:00:00 2001 From: kojima Date: Tue, 16 Mar 1999 11:27:01 +0000 Subject: [PATCH] WPrefs appearance stuff update (shows preview) --- ChangeLog | 1 + WINGs/WINGs.h | 6 +- WINGs/wfilepanel.c | 7 +- WINGs/wwindow.c | 56 ++++++++--- WPrefs.app/Appearance.c | 250 ++++++++++++++++++++++++++++++++++++++-------- WPrefs.app/TexturePanel.c | 5 +- src/client.c | 8 +- src/main.c | 4 +- src/window.c | 7 +- 9 files changed, 269 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37a86bf1..5b1426a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ Changes since version 0.51.2: - added a dot to mark hidden applications (compile time) (id@windowmaker.org) - enhancements to the modelock patch (id@windowmaker.org) - show kbd mode for modelock (id@windowmaker.org) +- enhanced positioning of transient windows Changes since version 0.51.1: diff --git a/WINGs/WINGs.h b/WINGs/WINGs.h index eefc5f76..0691530d 100644 --- a/WINGs/WINGs.h +++ b/WINGs/WINGs.h @@ -6,7 +6,7 @@ #include #include -#define WINGS_H_VERSION 990222 +#define WINGS_H_VERSION 990316 #ifdef __cplusplus @@ -660,6 +660,10 @@ void WMSetWindowMiniwindowImage(WMWindow *win, WMPixmap *pixmap); void WMSetWindowCloseAction(WMWindow *win, WMAction *action, void *clientData); +void WMSetWindowUPosition(WMWindow *win, int x, int y); + +void WMSetWindowUSize(WMWindow *win, unsigned width, unsigned height); + void WMSetWindowMaxSize(WMWindow *win, unsigned width, unsigned height); void WMSetWindowMinSize(WMWindow *win, unsigned width, unsigned height); diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 7811ffa3..5768be23 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -344,15 +344,14 @@ WMRunModalFilePanelForDirectory(WMFilePanel *panel, WMWindow *owner, break; } + WMSetWindowUPosition(panel->win, + (scr->rootView->size.width - WMWidgetWidth(panel->win))/2, + (scr->rootView->size.height - WMWidgetHeight(panel->win))/2); WMSetLabelText(panel->titleLabel, name); scr->modalView = W_VIEW(panel->win); WMMapWidget(panel->win); - WMMoveWidget(panel->win, - (scr->rootView->size.width - WMWidgetWidth(panel->win))/2, - (scr->rootView->size.height - WMWidgetHeight(panel->win))/2); - scr->modal = 1; while (!panel->flags.done) { WMNextEvent(scr->display, &event); diff --git a/WINGs/wwindow.c b/WINGs/wwindow.c index 145bbbc9..5646f23b 100644 --- a/WINGs/wwindow.c +++ b/WINGs/wwindow.c @@ -26,6 +26,9 @@ typedef struct W_Window { WMSize minSize; WMSize maxSize; + WMPoint upos; + WMSize usize; + WMAction *closeAction; void *closeData; @@ -35,7 +38,8 @@ typedef struct W_Window { unsigned style:4; unsigned configured:1; unsigned documentEdited:1; - unsigned moved:1; + + unsigned upos_set:1; } flags; } _Window; @@ -76,7 +80,7 @@ static void moveWindow(WMWidget *, int, int); struct W_ViewProcedureTable _WindowViewProcedures = { NULL, resizeWindow, - moveWindow + NULL }; @@ -267,14 +271,6 @@ WMSetWindowCloseAction(WMWindow *win, WMAction *action, void *clientData) } -static void -moveWindow(WMWidget *w, int x, int y) -{ - ((WMWindow*)w)->flags.moved = 1; - - W_MoveView(W_VIEW(w), x, y); -} - static void resizeWindow(WMWidget *w, unsigned width, unsigned height) @@ -311,6 +307,17 @@ setSizeHints(WMWindow *win) } hints->flags = 0; + + if (win->flags.upos_set) { + hints->flags |= USPosition; + hints->x = win->upos.x; + hints->y = win->upos.y; + } + if (win->usize.width>0 && win->usize.height>0) { + hints->flags |= USSize; + hints->width = win->usize.width; + hints->height = win->usize.height; + } if (win->minSize.width>0 && win->minSize.height>0) { hints->flags |= PMinSize; hints->min_width = win->minSize.width; @@ -389,12 +396,6 @@ realizeWindow(WMWindow *win) Atom atoms[4]; int count; - if (!win->flags.moved && win->owner!=NULL) { - W_MoveView(win->view, - (scr->rootView->size.width-win->view->size.width)/2, - (scr->rootView->size.height-win->view->size.height)/2); - } - classHint = XAllocClassHint(); classHint->res_name = win->wname; classHint->res_class = WMGetApplicationName(); @@ -442,6 +443,29 @@ realizeWindow(WMWindow *win) } + +void +WMSetWindowUPosition(WMWindow *win, int x, int y) +{ + win->flags.upos_set = 1; + win->upos.x = x; + win->upos.y = y; + if (win->view->flags.realized) + setSizeHints(win); +} + + + +void +WMSetWindowUSize(WMWindow *win, unsigned width, unsigned height) +{ + win->usize.width = width; + win->usize.height = height; + if (win->view->flags.realized) + setSizeHints(win); +} + + void WMSetWindowMinSize(WMWindow *win, unsigned width, unsigned height) { diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index 5e0ff5a0..afe985de 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -26,6 +26,8 @@ #include #include + + #include "TexturePanel.h" typedef struct _Panel { @@ -36,7 +38,7 @@ typedef struct _Panel { WMWindow *win; - WMButton *prevB; + WMLabel *prevL; WMPopUpButton *secP; @@ -69,15 +71,7 @@ typedef struct _Panel { WMPixmap *onLed; WMPixmap *offLed; - /* for preview shit */ Pixmap preview; - Pixmap ftitle; - Pixmap utitle; - Pixmap otitle; - Pixmap icon; - Pixmap back; - Pixmap mtitle; - Pixmap mitem; char *fprefix; } _Panel; @@ -99,6 +93,8 @@ typedef struct { static void showData(_Panel *panel); +static void OpenExtractPanelFor(_Panel *panel, char *path); + #define ICON_FILE "appearance" #define TNEW_FILE "tnew" @@ -235,7 +231,7 @@ dumpRImage(char *path, RImage *image) static Pixmap renderTexture(WMScreen *scr, proplist_t texture, int width, int height, - char *path, Bool bordered) + char *path, int border) { char *type; RImage *image; @@ -324,7 +320,15 @@ renderTexture(WMScreen *scr, proplist_t texture, int width, int height, path = wfindfileinarray(GetObjectForKey("PixmapPath"), str); timage = RLoadImage(rc, path, 0); free(path); - if (timage) { + + if (toupper(type[0]) == 'T') { + if (timage->width < TEXPREV_WIDTH + || timage->height < TEXPREV_HEIGHT) { + image = RMakeTiledImage(timage, TEXPREV_WIDTH, TEXPREV_HEIGHT); + RDestroyImage(timage); + timage = image; + } + } else if (timage) { w = timage->width; h = timage->height; @@ -336,12 +340,17 @@ renderTexture(WMScreen *scr, proplist_t texture, int width, int height, image = RScaleImage(timage, w, h); RDestroyImage(timage); + timage = image; } } if (path) { dumpRImage(path, image); } + + if (border) { + RBevelImage(image, border); + } RConvertImage(rc, image, &pixmap); RDestroyImage(image); @@ -350,7 +359,8 @@ renderTexture(WMScreen *scr, proplist_t texture, int width, int height, } -#if 0 + + static void updatePreviewBox(_Panel *panel, int elements) { @@ -358,28 +368,78 @@ updatePreviewBox(_Panel *panel, int elements) Display *dpy = WMScreenDisplay(scr); /* RContext *rc = WMScreenRContext(scr);*/ int refresh = 0; - char *tmp; + Pixmap pix; + GC gc; + + gc = XCreateGC(dpy, WMWidgetXID(panel->win), 0, NULL); + if (!panel->preview) { + WMColor *color; + panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win), 220-4, 185-4, WMScreenDepth(scr)); + color = WMGrayColor(scr); + XFillRectangle(dpy, panel->preview, WMColorGC(color), + 0, 0, 220-4, 185-4); + WMReleaseColor(color); + refresh = -1; } if (elements & FTITLE) { - if (panel->ftitle) - XFreePixmap(dpy, panel->ftitle); + pix = renderTexture(scr, panel->ftitleTex, 180, 20, NULL, + RBEV_RAISED2); + + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 180, 20, 5, 10); - panel->ftitle = renderTexture(scr, tmp, 180, 20, NULL, True); - free(tmp); + XFreePixmap(dpy, pix); } + if (elements & UTITLE) { + pix = renderTexture(scr, panel->utitleTex, 180, 20, NULL, + RBEV_RAISED2); - /* have to repaint everything to make things simple, eliminating - * clipping stuff */ - if (refresh) { - + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 180, 20, 10, 35); + + XFreePixmap(dpy, pix); + } + if (elements & OTITLE) { + pix = renderTexture(scr, panel->ptitleTex, 180, 20, NULL, + RBEV_RAISED2); + + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 180, 20, 15, 60); + + XFreePixmap(dpy, pix); + } + if (elements & MTITLE) { + pix = renderTexture(scr, panel->mtitleTex, 100, 20, NULL, + RBEV_RAISED2); + + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 20, 20, 95); + + XFreePixmap(dpy, pix); + } + if (elements & MITEM) { + pix = renderTexture(scr, panel->menuTex, 100, 18, NULL, + RBEV_RAISED2); + + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 20, 20, 115); + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 20, 20, 115+18); + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 100, 20, 20, 115+36); + + XFreePixmap(dpy, pix); } + if (elements & ICON) { + pix = renderTexture(scr, panel->iconTex, 64, 64, NULL, + RBEV_RAISED3); + + XCopyArea(dpy, pix, panel->preview, gc, 0, 0, 64, 64, 130, 100); + + XFreePixmap(dpy, pix); + } + + if (refresh<0) { WMPixmap *pix; @@ -389,22 +449,10 @@ updatePreviewBox(_Panel *panel, int elements) WMSetLabelImage(panel->prevL, pix); WMReleasePixmap(pix); } -} - - -static char* -getStrArrayForKey(char *key) -{ - proplist_t v; - - v = GetObjectForKey(key); - if (!v) - return NULL; - - return PLGetDescription(v); + XFreeGC(dpy, gc); } -#endif + @@ -469,7 +517,7 @@ okNewTexture(void *data) titem->path = makeFileName(panel->fprefix, name); titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, - titem->path, False); + titem->path, 0); item = WMAddListItem(panel->texLs, ""); item->clientData = titem; @@ -514,7 +562,7 @@ okEditTexture(void *data) XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview); titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, - titem->path, False); + titem->path, 0); WMRedisplayWidget(panel->texLs); } @@ -601,6 +649,34 @@ deleteTexture(WMWidget *w, void *data) } + + +static void +extractTexture(WMWidget *w, void *data) +{ + _Panel *panel = (_Panel*)data; + char *path; + WMOpenPanel *opanel; + WMScreen *scr = WMWidgetScreen(w); + + opanel = WMGetOpenPanel(scr); + WMSetFilePanelCanChooseDirectories(opanel, False); + WMSetFilePanelCanChooseFiles(opanel, True); + + if (WMRunModalFilePanelForDirectory(opanel, panel->win, wgethomedir(), + _("Select File"), NULL)) { + path = WMGetFilePanelFileName(opanel); + + puts(path); + OpenExtractPanelFor(panel, path); + + free(path); + } +} + + + + static void changePage(WMWidget *w, void *data) { @@ -782,7 +858,7 @@ fillTextureList(WMList *lPtr) titem->preview = loadRImage(scr, titem->path); if (!titem->preview) { titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, - TEXPREV_HEIGHT, NULL, False); + TEXPREV_HEIGHT, NULL, 0); } item = WMAddListItem(lPtr, ""); item->clientData = titem; @@ -832,10 +908,10 @@ createPanel(Panel *p) WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP); /* preview box */ - panel->prevB = WMCreateCommandButton(panel->frame); - WMResizeWidget(panel->prevB, 260, 165); - WMMoveWidget(panel->prevB, 15, 10); - WMSetButtonImagePosition(panel->prevB, WIPImageOnly); + panel->prevL = WMCreateLabel(panel->frame); + WMResizeWidget(panel->prevL, 260, 165); + WMMoveWidget(panel->prevL, 15, 10); + WMSetLabelImagePosition(panel->prevL, WIPImageOnly); panel->secP = WMCreatePopUpButton(panel->frame); WMResizeWidget(panel->secP, 260, 20); @@ -899,6 +975,7 @@ createPanel(Panel *p) WMSetButtonFont(panel->ripB, font); WMSetButtonImagePosition(panel->ripB, WIPAbove); WMSetButtonText(panel->ripB, _("Extract...")); + WMSetButtonAction(panel->ripB, extractTexture, panel); SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE); WMSetButtonEnabled(panel->ripB, False); @@ -962,7 +1039,7 @@ setupTextureFor(WMList *list, char *key, char *defValue, char *title, titem->selectedFor = 1<preview = renderTexture(WMWidgetScreen(list), titem->prop, - TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, False); + TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0); item = WMAddListItem(list, ""); item->clientData = titem; @@ -1006,6 +1083,8 @@ showData(_Panel *panel) "(solid, black)", "[Workspace]", i); panel->textureIndex[i] = i++; */ + + updatePreviewBox(panel, EVERYTHING); } @@ -1085,3 +1164,88 @@ InitAppearance(WMScreen *scr, WMWindow *win) return panel; } + + + +/****************************************************************************/ + + + +typedef struct ExtractPanel { + WMWindow *win; + + WMLabel *label; + WMList *list; + + WMButton *closeB; + WMButton *extrB; +} ExtractPanel; + + + +static void +OpenExtractPanelFor(_Panel *panel, char *path) +{ + ExtractPanel *epanel; + WMColor *color; + WMFont *font; + WMScreen *scr = WMWidgetScreen(panel->win); + + epanel = wmalloc(sizeof(ExtractPanel)); + epanel->win = WMCreatePanelWithStyleForWindow(panel->win, "extract", + WMTitledWindowMask + |WMClosableWindowMask); + WMResizeWidget(epanel->win, 245, 250); + WMSetWindowTitle(epanel->win, _("Extract Texture")); + + epanel->label = WMCreateLabel(epanel->win); + WMResizeWidget(epanel->label, 225, 18); + WMMoveWidget(epanel->label, 10, 10); + WMSetLabelTextAlignment(epanel->label, WACenter); + WMSetLabelRelief(epanel->label, WRSunken); + + color = WMDarkGrayColor(scr); + WMSetWidgetBackgroundColor(epanel->label, color); + WMReleaseColor(color); + + color = WMWhiteColor(scr); + WMSetLabelTextColor(epanel->label, color); + WMReleaseColor(color); + + font = WMBoldSystemFontOfSize(scr, 12); + WMSetLabelFont(epanel->label, font); + WMReleaseFont(font); + + WMSetLabelText(epanel->label, _("Textures")); + + epanel->list = WMCreateList(epanel->win); + WMResizeWidget(epanel->list, 225, 165); + WMMoveWidget(epanel->list, 10, 30); + + + + epanel->closeB = WMCreateCommandButton(epanel->win); + WMResizeWidget(epanel->closeB, 74, 24); + WMMoveWidget(epanel->closeB, 165, 215); + WMSetButtonText(epanel->closeB, _("Close")); + + epanel->extrB = WMCreateCommandButton(epanel->win); + WMResizeWidget(epanel->extrB, 74, 24); + WMMoveWidget(epanel->extrB, 80, 215); + WMSetButtonText(epanel->extrB, _("Extract")); + + WMMapSubwidgets(epanel->win); + + + /* take textures from file */ + + + + WMRealizeWidget(epanel->win); + + WMMapWidget(epanel->win); +} + + + + diff --git a/WPrefs.app/TexturePanel.c b/WPrefs.app/TexturePanel.c index c54040e5..637b7bac 100644 --- a/WPrefs.app/TexturePanel.c +++ b/WPrefs.app/TexturePanel.c @@ -36,9 +36,8 @@ #include "WPrefs.h" -//#include "TexturePanel.h" +#include "TexturePanel.h" -typedef struct _TexturePanel TexturePanel; #define MAX_SECTION_PARTS 4 @@ -1012,7 +1011,7 @@ SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array) TexturePanel* CreateTexturePanel(WMWindow *keyWindow) -//CreateTexturePanel(WMScreen *scr) +/*CreateTexturePanel(WMScreen *scr)*/ { TexturePanel *panel; WMScreen *scr = WMWidgetScreen(keyWindow); diff --git a/src/client.c b/src/client.c index 2c1045ec..9052b1e2 100644 --- a/src/client.c +++ b/src/client.c @@ -641,8 +641,8 @@ void wClientGetNormalHints(WWindow *wwin, XWindowAttributes *wattribs, Bool geometry, int *x, int *y, unsigned *width, unsigned *height) { - int pre_icccm=0; - + int pre_icccm = 0; /* not used */ + /* find a position for the window */ if (!wwin->normal_hints) wwin->normal_hints = XAllocSizeHints(); @@ -714,8 +714,7 @@ wClientGetNormalHints(WWindow *wwin, XWindowAttributes *wattribs, Bool geometry, wwin->normal_hints->min_width = wwin->normal_hints->max_width; } - /* pre ICCCM (old) client */ - if (pre_icccm && !wwin->screen_ptr->flags.startup && geometry) { + if (/*pre_icccm && */!wwin->screen_ptr->flags.startup && geometry) { #ifdef DEBUG printf("PRE ICCCM\n"); #endif @@ -723,6 +722,7 @@ wClientGetNormalHints(WWindow *wwin, XWindowAttributes *wattribs, Bool geometry, wwin->normal_hints->flags &= ~PPosition; #endif if (wwin->normal_hints->flags & (USPosition|PPosition)) { + puts("QWEWQEWQ"); *x = wwin->normal_hints->x; *y = wwin->normal_hints->y; } diff --git a/src/main.c b/src/main.c index cea20407..b51095bc 100644 --- a/src/main.c +++ b/src/main.c @@ -502,9 +502,9 @@ main(int argc, char **argv) sprintf(str, "DISPLAY=%s", DisplayName); putenv(str); -//#ifdef DEBUG +#ifdef DEBUG XSynchronize(dpy, True); -//#endif +#endif wXModifierInitialize(); diff --git a/src/window.c b/src/window.c index eba6abf0..0640bac1 100644 --- a/src/window.c +++ b/src/window.c @@ -816,7 +816,9 @@ wManageWindow(WScreen *scr, Window window) if (win_state && win_state->state->use_geometry) { x = win_state->state->x; y = win_state->state->y; - } else if (wwin->transient_for==None && !scr->flags.startup + } else if ((wwin->transient_for==None + || wPreferences.window_placement!=WPM_MANUAL) + && !scr->flags.startup && workspace == scr->current_workspace && !wwin->flags.miniaturized && !wwin->flags.maximized @@ -861,7 +863,7 @@ wManageWindow(WScreen *scr, Window window) /* setup button images */ wWindowUpdateButtonImages(wwin); - + /* hide unused buttons */ foo = 0; if (WFLAGP(wwin, no_close_button)) @@ -917,6 +919,7 @@ wManageWindow(WScreen *scr, Window window) if (gy > 0) y -= wwin->frame->top_width + wwin->frame->bottom_width; } + /* * wWindowConfigure() will init the client window's size * (wwin->client.{width,height}) and all other geometry -- 2.11.4.GIT