windowmaker-wl/src/framewin.c

1259 lines
37 KiB
C

/*
* Window Maker window manager
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "wconfig.h"
#ifdef KEEP_XKB_LOCK_STATUS
#endif /* KEEP_XKB_LOCK_STATUS */
#include <stdlib.h>
#include <string.h>
#include <wraster.h>
#include "WindowMaker.h"
#include "GNUstep.h"
#include "texture.h"
#include "resources.h"
#include "screen.h"
#include "wcore.h"
#include "window.h"
#include "framewin.h"
#include "stacking.h"
#include "misc.h"
#include "event.h"
static void handleExpose(WObjDescriptor * desc, WBackendEvent * event);
static void handleButtonExpose(WObjDescriptor * desc, WBackendEvent * event);
static void buttonMouseDown(WObjDescriptor * desc, WBackendEvent * event);
static void titlebarMouseDown(WObjDescriptor * desc, WBackendEvent * event);
static void resizebarMouseDown(WObjDescriptor * desc, WBackendEvent * event);
static void checkTitleSize(WFrameWindow * fwin);
static void paintButton(WCoreWindow * button, WTexture * texture,
unsigned long color, WPixmap * image, int pushed);
static void updateTitlebar(WFrameWindow * fwin);
static void allocFrameBorderPixel(WMNativeColormap colormap, const char *color_name, unsigned long **pixel);
static void allocFrameBorderPixel(WMNativeColormap colormap, const char *color_name, unsigned long **pixel) {
wm_backend->frame_alloc_border_pixel((unsigned long)colormap, color_name, pixel);
}
WFrameWindow *wFrameWindowCreate(WScreen * scr, int wlevel, int x, int y,
int width, int height, int *clearance,
int *title_min, int *title_max, int flags,
WTexture ** title_texture, WTexture ** resize_texture,
WMColor ** color, WMFont ** font,
int depth, Visual *visual, WMNativeColormap colormap)
{
WFrameWindow *fwin;
fwin = wmalloc(sizeof(WFrameWindow));
fwin->screen_ptr = scr;
fwin->flags.single_texture = (flags & WFF_SINGLE_STATE) ? 1 : 0;
fwin->title_texture = title_texture;
fwin->resizebar_texture = resize_texture;
fwin->title_color = color;
fwin->title_clearance = clearance;
fwin->title_min_height = title_min;
fwin->title_max_height = title_max;
fwin->font = font;
#ifdef KEEP_XKB_LOCK_STATUS
fwin->languagemode = WKB_GROUP1_INDEX;
fwin->last_languagemode = WKB_GROUP2_INDEX;
#endif
fwin->depth = depth;
fwin->visual = visual;
fwin->colormap = colormap;
fwin->core = wCoreCreateTopLevel(scr, x, y, width, height, (flags & WFF_BORDER)
? scr->frame_border_width : 0, fwin->depth, fwin->visual, fwin->colormap, scr->frame_border_pixel);
/* setup stacking information */
fwin->core->stacking = wmalloc(sizeof(WStacking));
fwin->core->stacking->above = NULL;
fwin->core->stacking->under = NULL;
fwin->core->stacking->child_of = NULL;
fwin->core->stacking->window_level = wlevel;
AddToStackList(fwin->core);
wFrameWindowUpdateBorders(fwin, flags);
return fwin;
}
void wFrameWindowUpdateBorders(WFrameWindow * fwin, int flags)
{
int theight;
int bsize;
int width, height;
int i;
WScreen *scr = fwin->screen_ptr;
width = fwin->core->width;
if (flags & WFF_IS_SHADED)
height = -1;
else
height = fwin->core->height - fwin->top_width - fwin->bottom_width;
if (flags & WFF_TITLEBAR) {
theight = WMFontHeight(*fwin->font) + (*fwin->title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
if (theight > *fwin->title_max_height)
theight = *fwin->title_max_height;
if (theight < *fwin->title_min_height)
theight = *fwin->title_min_height;
} else {
theight = 0;
}
if (wPreferences.new_style == TS_NEW) {
bsize = theight;
} else if (wPreferences.new_style == TS_OLD) {
bsize = theight - 7;
} else {
bsize = theight - 8;
}
if (fwin->titlebar) {
/* if we had a titlebar and is requesting for one,
* check if the size has changed and resize it */
if (flags & WFF_TITLEBAR) {
fwin->top_width = theight;
fwin->flags.need_texture_remake = 1;
if (wPreferences.new_style == TS_NEW) {
if (fwin->left_button)
wCoreConfigure(fwin->left_button, 0, 0, bsize, bsize);
#ifdef XKB_BUTTON_HINT
if (fwin->language_button) {
if (fwin->flags.hide_left_button || !fwin->left_button
|| fwin->flags.lbutton_dont_fit)
wCoreConfigure(fwin->language_button, 0, 0, bsize, bsize);
else
wCoreConfigure(fwin->language_button, bsize, 0, bsize, bsize);
}
#endif
if (fwin->right_button)
wCoreConfigure(fwin->right_button, width - bsize + 1, 0, bsize, bsize);
} else { /* !new_style */
if (fwin->left_button)
wCoreConfigure(fwin->left_button, 3, (theight - bsize) / 2, bsize, bsize);
#ifdef XKB_BUTTON_HINT
if (fwin->language_button)
wCoreConfigure(fwin->language_button, 6 + bsize, (theight - bsize) / 2,
bsize, bsize);
#endif
if (fwin->right_button)
wCoreConfigure(fwin->right_button, width - bsize - 3,
(theight - bsize) / 2, bsize, bsize);
}
updateTitlebar(fwin);
} else {
/* we had a titlebar, but now we don't need it anymore */
for (i = 0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
FREE_PIXMAP(fwin->title_back[i]);
if (wPreferences.new_style == TS_NEW) {
FREE_PIXMAP(fwin->lbutton_back[i]);
FREE_PIXMAP(fwin->rbutton_back[i]);
#ifdef XKB_BUTTON_HINT
FREE_PIXMAP(fwin->languagebutton_back[i]);
#endif
}
}
if (fwin->left_button)
wCoreDestroy(fwin->left_button);
fwin->left_button = NULL;
#ifdef XKB_BUTTON_HINT
if (fwin->language_button)
wCoreDestroy(fwin->language_button);
fwin->language_button = NULL;
#endif
if (fwin->right_button)
wCoreDestroy(fwin->right_button);
fwin->right_button = NULL;
wCoreDestroy(fwin->titlebar);
fwin->titlebar = NULL;
fwin->top_width = 0;
}
} else {
/* if we didn't have a titlebar and are being requested for
* one, create it */
if (flags & WFF_TITLEBAR) {
fwin->top_width = theight;
fwin->flags.titlebar = 1;
fwin->titlebar = wCoreCreate(fwin->core, 0, 0, width + 1, theight);
if (flags & WFF_LEFT_BUTTON) {
fwin->flags.left_button = 1;
if (wPreferences.new_style == TS_NEW) {
fwin->left_button = wCoreCreate(fwin->core, 0, 0, bsize, bsize);
if (width < theight * 4)
fwin->flags.lbutton_dont_fit = 1;
else
wm_backend->window_map_raised(fwin->left_button->window);
} else if (wPreferences.new_style == TS_OLD) {
fwin->left_button =
wCoreCreate(fwin->titlebar, 3, (theight - bsize) / 2, bsize, bsize);
wm_backend->window_set_background(fwin->left_button->window,
scr->widget_texture->normal.pixel);
if (width < theight * 3)
fwin->flags.lbutton_dont_fit = 1;
else
wm_backend->window_map_raised(fwin->left_button->window);
} else {
fwin->left_button =
wCoreCreate(fwin->titlebar, 3, (theight-bsize)/2,
bsize, bsize);
wm_backend->window_set_background(fwin->left_button->window,
scr->widget_texture->dark.pixel);
if (width < theight * 3)
fwin->flags.lbutton_dont_fit = 1;
else
wm_backend->window_map_raised(fwin->left_button->window);
}
}
#ifdef XKB_BUTTON_HINT
if (flags & WFF_LANGUAGE_BUTTON) {
fwin->flags.language_button = 1;
if (wPreferences.new_style == TS_NEW) {
fwin->language_button = wCoreCreate(fwin->core, bsize, 0, bsize, bsize);
if (width < theight * 4)
fwin->flags.languagebutton_dont_fit = 1;
else
wm_backend->window_map_raised(fwin->language_button->window);
} else {
fwin->language_button =
wCoreCreate(fwin->titlebar, bsize + 6, (theight - bsize) / 2,
bsize, bsize);
wm_backend->window_set_background(fwin->language_button->window,
scr->widget_texture->normal.pixel);
if (width < theight * 3)
fwin->flags.languagebutton_dont_fit = 1;
else
wm_backend->window_map_raised(fwin->language_button->window);
}
}
#endif
if (flags & WFF_RIGHT_BUTTON) {
fwin->flags.right_button = 1;
if (wPreferences.new_style == TS_NEW) {
fwin->right_button =
wCoreCreate(fwin->core, width - bsize + 1, 0, bsize, bsize);
} else if (wPreferences.new_style == TS_OLD) {
fwin->right_button =
wCoreCreate(fwin->titlebar, width - bsize - 3,
(theight - bsize) / 2, bsize, bsize);
wm_backend->window_set_background(fwin->right_button->window,
scr->widget_texture->normal.pixel);
} else {
fwin->right_button =
wCoreCreate(fwin->titlebar, width-bsize-3,
(theight-bsize)/2, bsize, bsize);
wm_backend->window_set_background(fwin->right_button->window,
scr->widget_texture->dark.pixel);
}
if (width < theight * 2)
fwin->flags.rbutton_dont_fit = 1;
else
wm_backend->window_map_raised(fwin->right_button->window);
}
if (wPreferences.new_style == TS_NEW)
updateTitlebar(fwin);
wm_backend->window_map_raised(fwin->titlebar->window);
fwin->flags.need_texture_remake = 1;
}
}
checkTitleSize(fwin);
if (flags & WFF_RESIZEBAR) {
fwin->bottom_width = RESIZEBAR_HEIGHT;
if (!fwin->resizebar) {
fwin->flags.resizebar = 1;
fwin->resizebar = wCoreCreate(fwin->core, 0,
height + fwin->top_width, width, RESIZEBAR_HEIGHT);
fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
if (width < RESIZEBAR_CORNER_WIDTH * 2 + RESIZEBAR_MIN_WIDTH) {
fwin->resizebar_corner_width = (width - RESIZEBAR_MIN_WIDTH) / 2;
if (fwin->resizebar_corner_width < 0)
fwin->resizebar_corner_width = 0;
}
wm_backend->window_map(fwin->resizebar->window);
wm_backend->stacking_lower(fwin->resizebar->window);
fwin->flags.need_texture_remake = 1;
} else {
if (height + fwin->top_width + fwin->bottom_width != fwin->core->height)
wCoreConfigure(fwin->resizebar, 0, height + fwin->top_width,
width, RESIZEBAR_HEIGHT);
}
} else {
fwin->bottom_width = 0;
if (fwin->resizebar) {
fwin->bottom_width = 0;
wCoreDestroy(fwin->resizebar);
fwin->resizebar = NULL;
}
}
if (height + fwin->top_width + fwin->bottom_width != fwin->core->height && !(flags & WFF_IS_SHADED))
wFrameWindowResize(fwin, width, height + fwin->top_width + fwin->bottom_width);
if (flags & WFF_BORDER)
wm_backend->window_set_border_width(fwin->core->window, scr->frame_border_width);
else
wm_backend->window_set_border_width(fwin->core->window, 0);
/* setup object descriptors */
if (fwin->titlebar) {
fwin->titlebar->descriptor.handle_expose = handleExpose;
fwin->titlebar->descriptor.parent = fwin;
fwin->titlebar->descriptor.parent_type = WCLASS_FRAME;
fwin->titlebar->descriptor.handle_mousedown = titlebarMouseDown;
}
if (fwin->resizebar) {
fwin->resizebar->descriptor.handle_expose = handleExpose;
fwin->resizebar->descriptor.parent = fwin;
fwin->resizebar->descriptor.parent_type = WCLASS_FRAME;
fwin->resizebar->descriptor.handle_mousedown = resizebarMouseDown;
}
if (fwin->left_button) {
fwin->left_button->descriptor.handle_expose = handleButtonExpose;
fwin->left_button->descriptor.parent = fwin;
fwin->left_button->descriptor.parent_type = WCLASS_FRAME;
fwin->left_button->descriptor.handle_mousedown = buttonMouseDown;
}
#ifdef XKB_BUTTON_HINT
if (fwin->language_button) {
fwin->language_button->descriptor.handle_expose = handleButtonExpose;
fwin->language_button->descriptor.parent = fwin;
fwin->language_button->descriptor.parent_type = WCLASS_FRAME;
fwin->language_button->descriptor.handle_mousedown = buttonMouseDown;
}
#endif
if (fwin->right_button) {
fwin->right_button->descriptor.parent = fwin;
fwin->right_button->descriptor.parent_type = WCLASS_FRAME;
fwin->right_button->descriptor.handle_expose = handleButtonExpose;
fwin->right_button->descriptor.handle_mousedown = buttonMouseDown;
}
checkTitleSize(fwin);
char *desc;
desc = WMGetColorRGBDescription(scr->frame_border_color);
allocFrameBorderPixel(fwin->colormap, desc, &fwin->border_pixel);
wfree(desc);
desc = WMGetColorRGBDescription(scr->frame_focused_border_color);
allocFrameBorderPixel(fwin->colormap, desc, &fwin->focused_border_pixel);
wfree(desc);
desc = WMGetColorRGBDescription(scr->frame_selected_border_color);
allocFrameBorderPixel(fwin->colormap, desc, &fwin->selected_border_pixel);
wfree(desc);
if (flags & WFF_SELECTED) {
if (fwin->selected_border_pixel)
wm_backend->window_set_border(fwin->core->window, *fwin->selected_border_pixel);
} else {
if (fwin->flags.state == WS_FOCUSED) {
if (fwin->focused_border_pixel)
wm_backend->window_set_border(fwin->core->window, *fwin->focused_border_pixel);
} else {
if (fwin->border_pixel)
wm_backend->window_set_border(fwin->core->window, *fwin->border_pixel);
}
}
}
void wFrameWindowDestroy(WFrameWindow * fwin)
{
int i;
if (fwin->left_button)
wCoreDestroy(fwin->left_button);
#ifdef XKB_BUTTON_HINT
if (fwin->language_button)
wCoreDestroy(fwin->language_button);
#endif
if (fwin->right_button)
wCoreDestroy(fwin->right_button);
if (fwin->resizebar)
wCoreDestroy(fwin->resizebar);
if (fwin->titlebar)
wCoreDestroy(fwin->titlebar);
RemoveFromStackList(fwin->core);
wCoreDestroy(fwin->core);
if (fwin->title)
wfree(fwin->title);
for (i = 0; i < (fwin->flags.single_texture ? 1 : 3); i++) {
FREE_PIXMAP(fwin->title_back[i]);
if (wPreferences.new_style == TS_NEW) {
FREE_PIXMAP(fwin->lbutton_back[i]);
#ifdef XKB_BUTTON_HINT
FREE_PIXMAP(fwin->languagebutton_back[i]);
#endif
FREE_PIXMAP(fwin->rbutton_back[i]);
}
}
wfree(fwin);
}
void wFrameWindowChangeState(WFrameWindow * fwin, int state)
{
if (fwin->flags.state == state)
return;
fwin->flags.state = state;
fwin->flags.need_texture_change = 1;
if (fwin->flags.state == WS_FOCUSED) {
if (fwin->focused_border_pixel)
wm_backend->window_set_border(fwin->core->window, *fwin->focused_border_pixel);
} else {
if (fwin->border_pixel)
wm_backend->window_set_border(fwin->core->window, *fwin->border_pixel);
}
wm_backend->frame_paint(fwin);
}
static void updateTitlebar(WFrameWindow * fwin)
{
int x, w;
int theight;
theight = WMFontHeight(*fwin->font) + (*fwin->title_clearance + TITLEBAR_EXTEND_SPACE) * 2;
if (theight > *fwin->title_max_height)
theight = *fwin->title_max_height;
if (theight < *fwin->title_min_height)
theight = *fwin->title_min_height;
x = 0;
w = fwin->core->width + 1;
if (wPreferences.new_style == TS_NEW) {
if (fwin->flags.hide_left_button || !fwin->left_button || fwin->flags.lbutton_dont_fit) {
x = 0;
#ifdef XKB_BUTTON_HINT
if (fwin->language_button)
wCoreConfigure(fwin->language_button, 0, 0,
fwin->language_button->width, fwin->language_button->width);
#endif
} else {
#ifdef XKB_BUTTON_HINT
if (fwin->language_button)
wCoreConfigure(fwin->language_button, fwin->left_button->width, 0,
fwin->language_button->width, fwin->language_button->width);
#endif
x = fwin->left_button->width;
w -= fwin->left_button->width;
}
#ifdef XKB_BUTTON_HINT
if (fwin->flags.hide_language_button || !fwin->language_button
|| fwin->flags.languagebutton_dont_fit) {
} else {
x += fwin->language_button->width;
w -= fwin->language_button->width;
}
#endif
}
#ifdef XKB_BUTTON_HINT
else {
int bsize = theight - 7;
if (fwin->flags.hide_left_button || !fwin->left_button || fwin->flags.lbutton_dont_fit) {
if (fwin->language_button)
wCoreConfigure(fwin->language_button, 3, (theight - bsize) / 2,
fwin->language_button->width, fwin->language_button->width);
} else {
if (fwin->language_button)
wCoreConfigure(fwin->language_button,
6 + fwin->left_button->width, (theight - bsize) / 2,
fwin->language_button->width, fwin->language_button->width);
}
}
#endif
if (wPreferences.new_style == TS_NEW) {
if (!fwin->flags.hide_right_button && fwin->right_button && !fwin->flags.rbutton_dont_fit)
w -= fwin->right_button->width;
}
if (wPreferences.new_style == TS_NEW || fwin->titlebar->width != w)
fwin->flags.need_texture_remake = 1;
wCoreConfigure(fwin->titlebar, x, 0, w, theight);
}
void wFrameWindowHideButton(WFrameWindow * fwin, int flags)
{
if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button) {
if (fwin->right_button->window) wm_backend->window_unmap((WNativeWindow)fwin->right_button->window);
fwin->flags.hide_right_button = 1;
}
if ((flags & WFF_LEFT_BUTTON) && fwin->left_button) {
if (fwin->left_button->window) wm_backend->window_unmap((WNativeWindow)fwin->left_button->window);
fwin->flags.hide_left_button = 1;
}
#ifdef XKB_BUTTON_HINT
if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button) {
if (fwin->language_button->window) wm_backend->window_unmap((WNativeWindow)fwin->language_button->window);
fwin->flags.hide_language_button = 1;
}
#endif
if (fwin->titlebar) {
if (wPreferences.new_style == TS_NEW) {
updateTitlebar(fwin);
} else {
#ifdef XKB_BUTTON_HINT
updateTitlebar(fwin);
#else
if (fwin->titlebar->window) wm_backend->window_clear((WNativeWindow)fwin->titlebar->window);
wm_backend->frame_paint(fwin);
#endif
}
checkTitleSize(fwin);
}
}
void wFrameWindowShowButton(WFrameWindow * fwin, int flags)
{
if ((flags & WFF_RIGHT_BUTTON) && fwin->right_button && fwin->flags.hide_right_button) {
if (!fwin->flags.rbutton_dont_fit && fwin->right_button->window)
wm_backend->window_map((WNativeWindow)fwin->right_button->window);
fwin->flags.hide_right_button = 0;
}
#ifdef XKB_BUTTON_HINT
if ((flags & WFF_LANGUAGE_BUTTON) && fwin->language_button && fwin->flags.hide_language_button) {
if (!fwin->flags.languagebutton_dont_fit && fwin->language_button->window)
wm_backend->window_map((WNativeWindow)fwin->language_button->window);
fwin->flags.hide_language_button = 0;
}
#endif
if ((flags & WFF_LEFT_BUTTON) && fwin->left_button && fwin->flags.hide_left_button) {
if (!fwin->flags.lbutton_dont_fit && fwin->left_button->window)
wm_backend->window_map((WNativeWindow)fwin->left_button->window);
fwin->flags.hide_left_button = 0;
}
if (fwin->titlebar) {
if (wPreferences.new_style == TS_NEW) {
updateTitlebar(fwin);
}
wm_backend->frame_paint(fwin);
checkTitleSize(fwin);
}
}
static void
#ifdef XKB_BUTTON_HINT
renderTexture(WScreen * scr, WTexture * texture, int width, int height,
int bwidth, int bheight, int left, int language, int right,
WMNativePixmap * title, WMNativePixmap * lbutton, WMNativePixmap * languagebutton, WMNativePixmap * rbutton)
#else
renderTexture(WScreen * scr, WTexture * texture, int width, int height,
int bwidth, int bheight, int left, int right, WMNativePixmap * title, WMNativePixmap * lbutton, WMNativePixmap * rbutton)
#endif
{
RImage *img;
RImage *limg, *rimg, *mimg;
#ifdef XKB_BUTTON_HINT
RImage *timg;
#endif
int x, w;
*title = WM_NATIVE_NONE;
*lbutton = WM_NATIVE_NONE;
*rbutton = WM_NATIVE_NONE;
#ifdef XKB_BUTTON_HINT
*languagebutton = WM_NATIVE_NONE;
#endif
img = wTextureRenderImage(texture, width, height, WREL_FLAT);
if (!img) {
wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
return;
}
if (wPreferences.new_style == TS_NEW) {
if (left)
limg = RGetSubImage(img, 0, 0, bwidth, bheight);
else
limg = NULL;
x = 0;
w = img->width;
#ifdef XKB_BUTTON_HINT
if (language)
timg = RGetSubImage(img, bwidth * left, 0, bwidth, bheight);
else
timg = NULL;
#endif
if (limg) {
RBevelImage(limg, RBEV_RAISED2);
if (!RConvertImage(scr->rcontext, limg, lbutton))
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
x += limg->width;
w -= limg->width;
RReleaseImage(limg);
}
#ifdef XKB_BUTTON_HINT
if (timg) {
RBevelImage(timg, RBEV_RAISED2);
if (!RConvertImage(scr->rcontext, timg, languagebutton))
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
x += timg->width;
w -= timg->width;
RReleaseImage(timg);
}
#endif
if (right)
rimg = RGetSubImage(img, width - bwidth, 0, bwidth, bheight);
else
rimg = NULL;
if (rimg) {
RBevelImage(rimg, RBEV_RAISED2);
if (!RConvertImage(scr->rcontext, rimg, rbutton))
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
w -= rimg->width;
RReleaseImage(rimg);
}
if (w != width) {
mimg = RGetSubImage(img, x, 0, w, img->height);
RBevelImage(mimg, RBEV_RAISED2);
if (!RConvertImage(scr->rcontext, mimg, title))
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
RReleaseImage(mimg);
} else {
RBevelImage(img, RBEV_RAISED2);
if (!RConvertImage(scr->rcontext, img, title))
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
}
} else {
RBevelImage(img, RBEV_RAISED2);
if (!RConvertImage(scr->rcontext, img, title))
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
}
RReleaseImage(img);
}
static void
renderResizebarTexture(WScreen * scr, WTexture * texture, int width, int height, int cwidth, WMNativePixmap * pmap)
{
RImage *img;
RColor light;
RColor dark;
*pmap = WM_NATIVE_NONE;
img = wTextureRenderImage(texture, width, height, WREL_FLAT);
if (!img) {
wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
return;
}
light.alpha = 0;
light.red = light.green = light.blue = 80;
dark.alpha = 0;
dark.red = dark.green = dark.blue = 40;
ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
if (width > 1)
ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2,
width - cwidth - 2, height - 1, &dark);
ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
#ifdef SHADOW_RESIZEBAR
ROperateLine(img, RAddOperation, 0, 1, 0, height - 1, &light);
ROperateLine(img, RSubtractOperation, width - 1, 1, width - 1, height - 1, &dark);
ROperateLine(img, RSubtractOperation, 0, height - 1, width - 1, height - 1, &dark);
#endif /* SHADOW_RESIZEBAR */
if (!RConvertImage(scr->rcontext, img, pmap))
wwarning(_("error rendering image: %s"), RMessageForError(RErrorCode));
RReleaseImage(img);
}
static void updateTexture(WFrameWindow * fwin)
{
wm_backend->frame_update_texture(fwin);
}
static void remakeTexture(WFrameWindow * fwin, int state)
{
WMNativePixmap pmap, lpmap, rpmap;
#ifdef XKB_BUTTON_HINT
WMNativePixmap tpmap;
#endif
/* Phase 19: Wayland — no X11 rendering context; RConvertImage would crash */
if (!fwin->screen_ptr->rcontext)
return;
if (fwin->title_texture[state] && fwin->titlebar) {
FREE_PIXMAP(fwin->title_back[state]);
if (wPreferences.new_style == TS_NEW) {
FREE_PIXMAP(fwin->lbutton_back[state]);
FREE_PIXMAP(fwin->rbutton_back[state]);
#ifdef XKB_BUTTON_HINT
FREE_PIXMAP(fwin->languagebutton_back[state]);
#endif
}
if (fwin->title_texture[state]->any.type != WTEX_SOLID) {
int left, right;
int width;
#ifdef XKB_BUTTON_HINT
int language;
#endif
/* eventually surrounded by if new_style */
left = fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit;
#ifdef XKB_BUTTON_HINT
language = fwin->language_button && !fwin->flags.hide_language_button
&& !fwin->flags.languagebutton_dont_fit;
#endif
right = fwin->right_button && !fwin->flags.hide_right_button
&& !fwin->flags.rbutton_dont_fit;
width = fwin->core->width + 1;
#ifdef XKB_BUTTON_HINT
renderTexture(fwin->screen_ptr, fwin->title_texture[state],
width, fwin->titlebar->height,
fwin->titlebar->height, fwin->titlebar->height,
left, language, right, &pmap, &lpmap, &tpmap, &rpmap);
#else
renderTexture(fwin->screen_ptr, fwin->title_texture[state],
width, fwin->titlebar->height,
fwin->titlebar->height, fwin->titlebar->height,
left, right, &pmap, &lpmap, &rpmap);
#endif
fwin->title_back[state] = pmap;
if (wPreferences.new_style == TS_NEW) {
fwin->lbutton_back[state] = lpmap;
fwin->rbutton_back[state] = rpmap;
#ifdef XKB_BUTTON_HINT
fwin->languagebutton_back[state] = tpmap;
#endif
}
}
}
if (fwin->resizebar_texture && fwin->resizebar_texture[0]
&& fwin->resizebar && state == 0) {
FREE_PIXMAP(fwin->resizebar_back[0]);
if (fwin->resizebar_texture[0]->any.type != WTEX_SOLID) {
renderResizebarTexture(fwin->screen_ptr,
fwin->resizebar_texture[0],
fwin->resizebar->width,
fwin->resizebar->height, fwin->resizebar_corner_width, &pmap);
fwin->resizebar_back[0] = pmap;
}
/* this part should be in updateTexture() */
if (fwin->resizebar_texture[0]->any.type != WTEX_SOLID)
wm_backend->window_set_background_pixmap(fwin->resizebar->window, fwin->resizebar_back[0]);
else
wm_backend->window_set_background(fwin->resizebar->window,
fwin->resizebar_texture[0]->solid.normal.pixel);
wm_backend->window_clear(fwin->resizebar->window);
}
}
void wFrameWindowPaint(WFrameWindow * fwin)
{
WScreen *scr = fwin->screen_ptr;
int state;
state = fwin->flags.state;
if (fwin->flags.is_client_window_frame)
fwin->flags.justification = wPreferences.title_justification;
if (fwin->flags.need_texture_remake) {
int i;
fwin->flags.need_texture_remake = 0;
fwin->flags.need_texture_change = 0;
if (fwin->flags.single_texture) {
remakeTexture(fwin, 0);
updateTexture(fwin);
} else {
remakeTexture(fwin, state);
updateTexture(fwin);
for (i = 0; i < 3; i++) {
if (i != state)
remakeTexture(fwin, i);
}
}
}
if (fwin->flags.need_texture_change) {
fwin->flags.need_texture_change = 0;
updateTexture(fwin);
}
if (fwin->titlebar && !fwin->flags.repaint_only_resizebar
&& fwin->title_texture[state]->any.type == WTEX_SOLID) {
wDrawBevel(fwin->titlebar->window, fwin->titlebar->width,
fwin->titlebar->height, (WTexSolid *) fwin->title_texture[state], WREL_RAISED);
}
if (fwin->resizebar && fwin->resizebar->window
&& !fwin->flags.repaint_only_titlebar
&& fwin->resizebar_texture[0]->any.type == WTEX_SOLID) {
wm_backend->frame_paint_resizebar(fwin);
}
if (fwin->titlebar && !fwin->flags.repaint_only_resizebar) {
wm_backend->frame_paint_titlebar(fwin, state);
if (fwin->left_button)
handleButtonExpose(&fwin->left_button->descriptor, NULL);
if (fwin->right_button)
handleButtonExpose(&fwin->right_button->descriptor, NULL);
#ifdef XKB_BUTTON_HINT
if (fwin->language_button)
handleButtonExpose(&fwin->language_button->descriptor, NULL);
#endif
}
}
static void reconfigure(WFrameWindow * fwin, int x, int y, int width, int height, Bool dontMove)
{
int k = (wPreferences.new_style == TS_NEW ? 4 : 3);
int resizedHorizontally = 0;
if (fwin->core->window) {
if (dontMove)
wm_backend->window_resize((WNativeWindow)fwin->core->window, width, height);
else
wm_backend->frame_configure((WNativeWindow)fwin->core->window, x, y, width, height);
}
if (fwin->core->width != width) {
fwin->flags.need_texture_remake = 1;
resizedHorizontally = 1;
}
fwin->core->width = width;
fwin->core->height = height;
if (fwin->titlebar && resizedHorizontally) {
/* Check if the titlebar is wide enough to hold the buttons.
* Temporarily remove them if can't
*/
if (fwin->left_button) {
if (width < fwin->top_width * k && !fwin->flags.lbutton_dont_fit) {
if (!fwin->flags.hide_left_button && fwin->left_button->window)
wm_backend->window_unmap((WNativeWindow)fwin->left_button->window);
fwin->flags.lbutton_dont_fit = 1;
} else if (width >= fwin->top_width * k && fwin->flags.lbutton_dont_fit) {
if (!fwin->flags.hide_left_button && fwin->left_button->window)
wm_backend->window_map((WNativeWindow)fwin->left_button->window);
fwin->flags.lbutton_dont_fit = 0;
}
}
#ifdef XKB_BUTTON_HINT
if (fwin->language_button) {
if (width < fwin->top_width * k && !fwin->flags.languagebutton_dont_fit) {
if (!fwin->flags.hide_language_button && fwin->language_button->window)
wm_backend->window_unmap((WNativeWindow)fwin->language_button->window);
fwin->flags.languagebutton_dont_fit = 1;
} else if (width >= fwin->top_width * k && fwin->flags.languagebutton_dont_fit) {
if (!fwin->flags.hide_language_button && fwin->language_button->window)
wm_backend->window_map((WNativeWindow)fwin->language_button->window);
fwin->flags.languagebutton_dont_fit = 0;
}
}
#endif
if (fwin->right_button) {
if (width < fwin->top_width * 2 && !fwin->flags.rbutton_dont_fit) {
if (!fwin->flags.hide_right_button && fwin->right_button->window)
wm_backend->window_unmap((WNativeWindow)fwin->right_button->window);
fwin->flags.rbutton_dont_fit = 1;
} else if (width >= fwin->top_width * 2 && fwin->flags.rbutton_dont_fit) {
if (!fwin->flags.hide_right_button && fwin->right_button->window)
wm_backend->window_map((WNativeWindow)fwin->right_button->window);
fwin->flags.rbutton_dont_fit = 0;
}
}
if (wPreferences.new_style == TS_NEW) {
if (fwin->right_button && fwin->right_button->window) {
wm_backend->window_move(fwin->right_button->window,
width - fwin->right_button->width + 1, 0);
}
} else {
if (fwin->right_button && fwin->right_button->window)
wm_backend->window_move(fwin->right_button->window,
width - fwin->right_button->width - 3,
(fwin->titlebar->height - fwin->right_button->height) / 2);
}
updateTitlebar(fwin);
checkTitleSize(fwin);
}
if (fwin->resizebar) {
wCoreConfigure(fwin->resizebar, 0,
fwin->core->height - fwin->resizebar->height,
fwin->core->width, fwin->resizebar->height);
fwin->resizebar_corner_width = RESIZEBAR_CORNER_WIDTH;
if (fwin->core->width < RESIZEBAR_CORNER_WIDTH * 2 + RESIZEBAR_MIN_WIDTH)
fwin->resizebar_corner_width = fwin->core->width / 2;
}
}
void wFrameWindowConfigure(WFrameWindow * fwin, int x, int y, int width, int height)
{
reconfigure(fwin, x, y, width, height, False);
wm_backend->frame_paint(fwin);
}
void wFrameWindowResize(WFrameWindow * fwin, int width, int height)
{
reconfigure(fwin, 0, 0, width, height, True);
wm_backend->frame_paint(fwin);
}
int wFrameWindowChangeTitle(WFrameWindow *fwin, const char *new_title)
{
if (new_title == NULL)
return 0;
/* check if the title is the same as before */
if (fwin->title) {
if (strcmp(fwin->title, new_title) == 0)
return 0;
}
if (fwin->title)
wfree(fwin->title);
fwin->title = wstrdup(new_title);
if (fwin->titlebar) {
wm_backend->window_clear(fwin->titlebar->window);
wm_backend->frame_paint(fwin);
}
checkTitleSize(fwin);
return 1;
}
#ifdef XKB_BUTTON_HINT
void wFrameWindowUpdateLanguageButton(WFrameWindow * fwin)
{
paintButton(fwin->language_button, fwin->title_texture[fwin->flags.state],
WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->languagebutton_image, True);
}
#endif /* XKB_BUTTON_HINT */
/*********************************************************************/
static void handleExpose(WObjDescriptor * desc, WBackendEvent * event)
{
WFrameWindow *fwin = (WFrameWindow *) desc->parent;
if (fwin->titlebar && fwin->titlebar->window == event->u.expose.window)
fwin->flags.repaint_only_titlebar = 1;
if (fwin->resizebar && fwin->resizebar->window == event->u.expose.window)
fwin->flags.repaint_only_resizebar = 1;
wm_backend->frame_paint(fwin);
fwin->flags.repaint_only_titlebar = 0;
fwin->flags.repaint_only_resizebar = 0;
}
static void checkTitleSize(WFrameWindow * fwin)
{
int width;
if (!fwin->title) {
fwin->flags.incomplete_title = 0;
return;
}
/* Phase 19: Wayland — no wmscreen for WMWidthOfString */
if (!fwin->screen_ptr->wmscreen) {
fwin->flags.incomplete_title = 0;
return;
}
if (!fwin->titlebar) {
fwin->flags.incomplete_title = 1;
return;
} else {
width = fwin->titlebar->width - 6 - 6;
}
if (wPreferences.new_style != TS_NEW) {
if (fwin->left_button && !fwin->flags.hide_left_button && !fwin->flags.lbutton_dont_fit)
width -= fwin->left_button->width + 3;
#ifdef XKB_BUTTON_HINT
if (fwin->language_button && !fwin->flags.hide_language_button
&& !fwin->flags.languagebutton_dont_fit)
width -= fwin->language_button->width + 3;
#endif
if (fwin->right_button && !fwin->flags.hide_right_button && !fwin->flags.rbutton_dont_fit)
width -= fwin->right_button->width + 3;
}
if (WMWidthOfString(*fwin->font, fwin->title, strlen(fwin->title)) > width)
fwin->flags.incomplete_title = 1;
else
fwin->flags.incomplete_title = 0;
}
static void paintButton(WCoreWindow * button, WTexture * texture, unsigned long color, WPixmap * image, int pushed)
{
wm_backend->frame_paint_button(button, texture, color, image, pushed);
}
static void handleButtonExpose(WObjDescriptor * desc, WBackendEvent * event)
{
WFrameWindow *fwin = (WFrameWindow *) desc->parent;
WCoreWindow *button = (WCoreWindow *) desc->self;
/* Parameter not used, but tell the compiler that it is ok */
(void) event;
/* During wFrameWindowUpdateBorders, frame_paint may be called via
* wFrameWindowResize before descriptor parents are wired up. The
* buttons exist but their descriptor->parent is still NULL. */
if (!fwin)
return;
#ifdef XKB_BUTTON_HINT
if (button == fwin->language_button) {
if (wPreferences.modelock)
paintButton(button, fwin->title_texture[fwin->flags.state],
WMColorPixel(fwin->title_color[fwin->flags.state]),
fwin->languagebutton_image, False);
} else
#endif
if (button == fwin->left_button)
paintButton(button, fwin->title_texture[fwin->flags.state],
WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->lbutton_image, False);
else
paintButton(button, fwin->title_texture[fwin->flags.state],
WMColorPixel(fwin->title_color[fwin->flags.state]), fwin->rbutton_image, False);
}
static void titlebarMouseDown(WObjDescriptor * desc, WBackendEvent * event)
{
WFrameWindow *fwin = desc->parent;
WCoreWindow *titlebar = desc->self;
if (IsDoubleClick(fwin->core->screen_ptr, event)) {
if (fwin->on_dblclick_titlebar)
(*fwin->on_dblclick_titlebar) (titlebar, fwin->child, event);
} else {
if (fwin->on_mousedown_titlebar)
(*fwin->on_mousedown_titlebar) (titlebar, fwin->child, event);
}
}
static void resizebarMouseDown(WObjDescriptor * desc, WBackendEvent * event)
{
WFrameWindow *fwin = desc->parent;
WCoreWindow *resizebar = desc->self;
if (fwin->on_mousedown_resizebar)
(*fwin->on_mousedown_resizebar) (resizebar, fwin->child, event);
}
static void buttonMouseDown(WObjDescriptor * desc, WBackendEvent * event)
{
WFrameWindow *fwin = desc->parent;
WCoreWindow *button = desc->self;
WPixmap *image;
WMEvent ev;
int done = 0, execute = 1;
WTexture *texture;
unsigned long pixel;
int clickButton = event->u.button.button;
if (IsDoubleClick(fwin->core->screen_ptr, event)) {
if (button == fwin->right_button && fwin->on_dblclick_right)
(*fwin->on_dblclick_right) (button, fwin->child, event);
return;
}
if (button == fwin->left_button)
image = fwin->lbutton_image;
else
image = fwin->rbutton_image;
#ifdef XKB_BUTTON_HINT
if (button == fwin->language_button) {
if (!wPreferences.modelock)
return;
image = fwin->languagebutton_image;
}
#endif
pixel = WMColorPixel(fwin->title_color[fwin->flags.state]);
texture = fwin->title_texture[fwin->flags.state];
paintButton(button, texture, pixel, image, True);
while (!done) {
WMMaskEvent(fwin->core->screen_ptr->wmscreen, WM_EVMASK_LEAVE_WINDOW | WM_EVMASK_ENTER_WINDOW | WM_EVMASK_BUTTON_RELEASE
| WM_EVMASK_BUTTON_PRESS | WM_EVMASK_EXPOSURE, &ev);
switch (ev.type) {
case WME_LEAVE:
execute = 0;
paintButton(button, texture, pixel, image, False);
break;
case WME_ENTER:
execute = 1;
paintButton(button, texture, pixel, image, True);
break;
case WME_BUTTON_PRESS:
break;
case WME_BUTTON_RELEASE:
if (ev.u.button.button == clickButton)
done = 1;
break;
default:
WMHandleEvent(&ev);
}
}
paintButton(button, texture, pixel, image, False);
if (execute) {
if (button == fwin->left_button) {
if (fwin->on_click_left)
(*fwin->on_click_left) (button, fwin->child, &ev);
} else if (button == fwin->right_button) {
if (fwin->on_click_right)
(*fwin->on_click_right) (button, fwin->child, &ev);
}
#ifdef XKB_BUTTON_HINT
else if (button == fwin->language_button) {
if (fwin->on_click_language)
(*fwin->on_click_language) (button, fwin->child, &ev);
}
#endif
}
}