1999-10-04 15:06:00 -07:00
|
|
|
/*
|
2005-03-19 08:40:18 -08:00
|
|
|
* Copyright (C) 2000-2005 Carsten Haitzler, Geoff Harrison and various contributors
|
|
|
|
* Copyright (C) 2004-2005 Kim Woelders
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
1999-08-17 15:56:46 -07:00
|
|
|
#include "E.h"
|
2005-07-16 09:57:45 -07:00
|
|
|
#include "emodule.h"
|
|
|
|
#include "xwin.h"
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
#define BUTTON_EVENT_MASK \
|
2005-01-28 23:41:49 -08:00
|
|
|
(KeyPressMask | KeyReleaseMask | \
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask)
|
|
|
|
|
|
|
|
typedef struct _bgeometry
|
|
|
|
{
|
|
|
|
Constraints width, height;
|
|
|
|
int xorigin, yorigin;
|
|
|
|
int xabs, xrel;
|
|
|
|
int yabs, yrel;
|
|
|
|
int xsizerel, xsizeabs;
|
|
|
|
int ysizerel, ysizeabs;
|
|
|
|
char size_from_image;
|
|
|
|
}
|
|
|
|
BGeometry;
|
|
|
|
|
|
|
|
struct _button
|
|
|
|
{
|
|
|
|
EObj o;
|
|
|
|
BGeometry geom;
|
|
|
|
ImageClass *iclass;
|
|
|
|
ActionClass *aclass;
|
|
|
|
TextClass *tclass;
|
|
|
|
char *label;
|
|
|
|
int flags;
|
|
|
|
char internal;
|
|
|
|
char default_show;
|
|
|
|
char used;
|
|
|
|
|
|
|
|
int state;
|
|
|
|
Window inside_win;
|
|
|
|
Window event_win;
|
|
|
|
char left;
|
|
|
|
unsigned int ref_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
Button *button;
|
2005-03-05 04:19:48 -08:00
|
|
|
char loading_user;
|
2005-06-09 11:28:13 -07:00
|
|
|
char move_pending;
|
2005-06-30 05:37:43 -07:00
|
|
|
char action_inhibit;
|
2005-08-15 09:57:13 -07:00
|
|
|
int start_x, start_y;
|
2005-03-05 04:19:48 -08:00
|
|
|
} Mode_buttons;
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
static void ButtonHandleEvents(XEvent * ev, void *btn);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
Button *
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonCreate(const char *name, int id, ImageClass * iclass,
|
2005-03-31 08:02:56 -08:00
|
|
|
ActionClass * aclass, TextClass * tclass, const char *label,
|
|
|
|
char ontop, int flags, int minw, int maxw, int minh, int maxh,
|
|
|
|
int xo, int yo, int xa, int xr, int ya, int yr, int xsr, int xsa,
|
|
|
|
int ysr, int ysa, char simg, int desk, char sticky)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
Button *b;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if (desk < 0 || desk >= DesksGetNumber())
|
|
|
|
return NULL;
|
|
|
|
if (sticky && ontop == 1)
|
|
|
|
desk = 0;
|
|
|
|
|
|
|
|
b = Ecalloc(1, sizeof(Button));
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-02-28 07:14:02 -08:00
|
|
|
b->label = Estrdup(label);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
b->iclass = iclass;
|
|
|
|
if (!b->iclass)
|
2004-12-28 15:46:49 -08:00
|
|
|
b->iclass = ImageclassFind(NULL, 0);
|
1999-08-17 15:56:46 -07:00
|
|
|
if (b->iclass)
|
|
|
|
b->iclass->ref_count++;
|
|
|
|
|
|
|
|
b->aclass = aclass;
|
|
|
|
if (b->aclass)
|
2004-12-28 15:46:49 -08:00
|
|
|
ActionclassIncRefcount(b->aclass);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
b->tclass = tclass;
|
2004-12-28 15:46:49 -08:00
|
|
|
if (!b->tclass && b->label)
|
|
|
|
b->tclass = TextclassFind(NULL, 0);
|
1999-09-10 14:15:45 -07:00
|
|
|
if (b->tclass)
|
|
|
|
b->tclass->ref_count++;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
b->flags = flags;
|
|
|
|
b->geom.width.min = minw;
|
|
|
|
b->geom.width.max = maxw;
|
|
|
|
b->geom.height.min = minh;
|
|
|
|
b->geom.height.max = maxh;
|
|
|
|
b->geom.xorigin = xo;
|
|
|
|
b->geom.yorigin = yo;
|
|
|
|
b->geom.xabs = xa;
|
|
|
|
b->geom.xrel = xr;
|
|
|
|
b->geom.yabs = ya;
|
|
|
|
b->geom.yrel = yr;
|
|
|
|
b->geom.xsizeabs = xsa;
|
|
|
|
b->geom.xsizerel = xsr;
|
|
|
|
b->geom.ysizeabs = ysa;
|
|
|
|
b->geom.ysizerel = ysr;
|
|
|
|
b->geom.size_from_image = simg;
|
|
|
|
b->inside_win = 0;
|
|
|
|
b->event_win = 0;
|
|
|
|
b->internal = 0;
|
|
|
|
b->default_show = 1;
|
|
|
|
b->used = 0;
|
|
|
|
b->left = 0;
|
|
|
|
b->state = 0;
|
|
|
|
b->ref_count = 0;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
EoSetSticky(b, sticky);
|
|
|
|
EoSetDesk(b, desk);
|
2005-06-12 00:56:31 -07:00
|
|
|
EobjInit(EoObj(b), EOBJ_TYPE_BUTTON, None, -100, -100, 50, 50, 0, name);
|
2004-12-28 15:46:49 -08:00
|
|
|
EoSetLayer(b, ontop);
|
2005-01-12 15:10:24 -08:00
|
|
|
EoSetShadow(b, 0);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2005-04-17 06:58:09 -07:00
|
|
|
ESelectInput(EoGetWin(b), BUTTON_EVENT_MASK);
|
|
|
|
EventCallbackRegister(EoGetWin(b), 0, ButtonHandleEvents, b);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2005-04-17 06:58:09 -07:00
|
|
|
AddItemEnd(b, EoGetName(b), id, LIST_TYPE_BUTTON);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2005-01-25 13:58:28 -08:00
|
|
|
return b;
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonDestroy(Button * b)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
if (!b)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
if (b->ref_count > 0)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-01-03 04:21:52 -08:00
|
|
|
DialogOK(_("Button Error!"), _("%u references remain\n"), b->ref_count);
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
while (RemoveItemByPtr(b, LIST_TYPE_BUTTON));
|
2005-01-09 02:06:29 -08:00
|
|
|
|
2005-04-17 06:58:09 -07:00
|
|
|
EobjFini(&b->o);
|
2005-08-13 09:23:59 -07:00
|
|
|
EDestroyWindow(EoGetWin(b));
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
if (b->iclass)
|
|
|
|
b->iclass->ref_count--;
|
|
|
|
|
|
|
|
if (b->aclass)
|
2004-12-28 15:46:49 -08:00
|
|
|
ActionclassDecRefcount(b->aclass);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
if (b->tclass)
|
|
|
|
b->tclass->ref_count--;
|
|
|
|
|
|
|
|
if (b->label)
|
|
|
|
Efree(b->label);
|
|
|
|
|
|
|
|
Efree(b);
|
|
|
|
}
|
|
|
|
|
2003-12-07 01:18:55 -08:00
|
|
|
static void
|
|
|
|
ButtonCalc(Button * b)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
int w, h, x, y, xo, yo;
|
2003-11-15 14:27:17 -08:00
|
|
|
Imlib_Image *im;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
w = 32;
|
|
|
|
h = 32;
|
|
|
|
if (b->geom.size_from_image)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
if ((b->iclass) && (b->iclass->norm.normal->im_file))
|
|
|
|
{
|
|
|
|
im = ELoadImage(b->iclass->norm.normal->im_file);
|
|
|
|
if (im)
|
|
|
|
{
|
2003-11-15 14:27:17 -08:00
|
|
|
imlib_context_set_image(im);
|
|
|
|
w = imlib_image_get_width();
|
|
|
|
h = imlib_image_get_height();
|
|
|
|
imlib_free_image();
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w = 32;
|
|
|
|
h = 32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!b->iclass)
|
2004-12-28 15:46:49 -08:00
|
|
|
b->iclass = ImageclassFind(NULL, 0);
|
2003-05-22 12:15:03 -07:00
|
|
|
w = 32;
|
|
|
|
h = 32;
|
|
|
|
}
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
else
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-05-04 12:04:42 -07:00
|
|
|
w = ((b->geom.xsizerel * VRoot.w) >> 10) + b->geom.xsizeabs;
|
|
|
|
h = ((b->geom.ysizerel * VRoot.h) >> 10) + b->geom.ysizeabs;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
if (w > b->geom.width.max)
|
|
|
|
w = b->geom.width.max;
|
|
|
|
else if (w < b->geom.width.min)
|
|
|
|
w = b->geom.width.min;
|
|
|
|
if (h > b->geom.height.max)
|
|
|
|
h = b->geom.height.max;
|
|
|
|
else if (h < b->geom.height.min)
|
|
|
|
h = b->geom.height.min;
|
|
|
|
xo = (w * b->geom.xorigin) >> 10;
|
|
|
|
yo = (h * b->geom.yorigin) >> 10;
|
2004-05-04 12:04:42 -07:00
|
|
|
x = ((b->geom.xrel * VRoot.w) >> 10) + b->geom.xabs - xo;
|
|
|
|
y = ((b->geom.yrel * VRoot.h) >> 10) + b->geom.yabs - yo;
|
2005-04-17 06:58:09 -07:00
|
|
|
|
|
|
|
EoMoveResize(b, x, y, w, h);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonShow(Button * b)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonCalc(b);
|
|
|
|
ButtonDraw(b);
|
2005-04-17 06:58:09 -07:00
|
|
|
EoMap(b, 0);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2005-06-12 00:02:02 -07:00
|
|
|
void
|
|
|
|
ButtonSetSwallowed(Button * b)
|
|
|
|
{
|
|
|
|
b->internal = 1;
|
|
|
|
b->default_show = 0;
|
|
|
|
b->flags |= FLAG_FIXED;
|
|
|
|
b->used = 1;
|
|
|
|
b->ref_count++;
|
|
|
|
ButtonCalc(b);
|
|
|
|
ButtonDraw(b);
|
|
|
|
EMapWindow(EoGetWin(b));
|
|
|
|
}
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
void
|
2004-11-17 11:31:11 -08:00
|
|
|
ButtonMoveToDesktop(Button * b, int desk)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2005-06-12 00:02:02 -07:00
|
|
|
Desk *d;
|
2005-01-09 02:06:29 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if (EoIsSticky(b) && EoGetLayer(b) == 1)
|
2004-11-17 11:31:11 -08:00
|
|
|
desk = 0;
|
|
|
|
|
2005-06-12 00:02:02 -07:00
|
|
|
d = DeskGet(desk);
|
|
|
|
if (!d)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (EoGetDesk(b) != d->num)
|
|
|
|
EoReparent(b, EoObj(d), EoGetX(b), EoGetY(b));
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonHide(Button * b)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2005-04-12 09:43:39 -07:00
|
|
|
EoUnmap(b);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2003-05-30 13:26:53 -07:00
|
|
|
void
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonToggle(Button * b)
|
2003-05-30 13:26:53 -07:00
|
|
|
{
|
2003-12-07 01:18:55 -08:00
|
|
|
if (b->used)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2003-05-30 13:26:53 -07:00
|
|
|
|
2005-04-12 09:43:39 -07:00
|
|
|
if (EoIsShown(b))
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonHide(b);
|
2003-05-30 13:26:53 -07:00
|
|
|
else
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonShow(b);
|
2003-05-30 13:26:53 -07:00
|
|
|
}
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
void
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonDraw(Button * b)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2005-01-28 23:41:49 -08:00
|
|
|
ITApply(EoGetWin(b), b->iclass, NULL, EoGetW(b), EoGetH(b),
|
|
|
|
b->state, 0, 0, 0, ST_BUTTON, b->tclass, NULL, b->label);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonDrawWithState(Button * b, int state)
|
|
|
|
{
|
|
|
|
b->state = state;
|
|
|
|
ButtonDraw(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ButtonMoveToCoord(Button * b, int x, int y)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
int rx, ry, relx, rely, absx, absy;
|
|
|
|
|
|
|
|
if (b->flags & FLAG_FIXED)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((x + (EoGetW(b) >> 1)) < (VRoot.w / 3))
|
1999-08-17 15:56:46 -07:00
|
|
|
relx = 0;
|
2004-12-28 15:46:49 -08:00
|
|
|
else if ((x + (EoGetW(b) >> 1)) > ((VRoot.w * 2) / 3))
|
1999-08-17 15:56:46 -07:00
|
|
|
relx = 1024;
|
|
|
|
else
|
|
|
|
relx = 512;
|
2004-05-04 12:04:42 -07:00
|
|
|
rx = (relx * VRoot.w) >> 10;
|
1999-08-17 15:56:46 -07:00
|
|
|
absx = x - rx;
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((y + (EoGetH(b) >> 1)) < (VRoot.h / 3))
|
1999-08-17 15:56:46 -07:00
|
|
|
rely = 0;
|
2004-12-28 15:46:49 -08:00
|
|
|
else if ((y + (EoGetH(b) >> 1)) > ((VRoot.h * 2) / 3))
|
1999-08-17 15:56:46 -07:00
|
|
|
rely = 1024;
|
|
|
|
else
|
|
|
|
rely = 512;
|
2004-05-04 12:04:42 -07:00
|
|
|
ry = (rely * VRoot.h) >> 10;
|
1999-08-17 15:56:46 -07:00
|
|
|
absy = y - ry;
|
|
|
|
if (!(b->flags & FLAG_FIXED_HORIZ))
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
b->geom.xorigin = 0;
|
|
|
|
b->geom.xabs = absx;
|
|
|
|
b->geom.xrel = relx;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
if (!(b->flags & FLAG_FIXED_VERT))
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
b->geom.yorigin = 0;
|
|
|
|
b->geom.yabs = absy;
|
|
|
|
b->geom.yrel = rely;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2005-04-12 09:43:39 -07:00
|
|
|
|
2003-12-07 01:18:55 -08:00
|
|
|
ButtonCalc(b);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2003-12-07 01:18:55 -08:00
|
|
|
void
|
|
|
|
ButtonMoveRelative(Button * b, int dx, int dy)
|
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonMoveToCoord(b, EoGetX(b) + dx, EoGetY(b) + dy);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ButtonIncRefcount(Button * b)
|
|
|
|
{
|
|
|
|
b->ref_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ButtonDecRefcount(Button * b)
|
|
|
|
{
|
|
|
|
b->ref_count--;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:58:09 -07:00
|
|
|
static const char *
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonGetName(const Button * b)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2005-04-17 06:58:09 -07:00
|
|
|
return EoGetName(b);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonGetRefcount(const Button * b)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
|
|
|
return b->ref_count;
|
|
|
|
}
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
int
|
2005-01-09 02:06:29 -08:00
|
|
|
ButtonGetDesk(const Button * b)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
return EoGetDesk(b);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonGetInfo(const Button * b, RectBox * r, int desk)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2005-04-12 09:43:39 -07:00
|
|
|
if (!EoIsShown(b) || b->internal)
|
2003-12-07 01:18:55 -08:00
|
|
|
return -1;
|
2004-12-28 15:46:49 -08:00
|
|
|
if (!EoIsSticky(b) && EoGetDesk(b) != desk)
|
2003-12-07 01:18:55 -08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
r->data = NULL;
|
2004-12-28 15:46:49 -08:00
|
|
|
r->x = EoGetX(b);
|
|
|
|
r->y = EoGetY(b);
|
|
|
|
r->w = EoGetW(b);
|
|
|
|
r->h = EoGetH(b);
|
|
|
|
r->p = EoIsSticky(b);
|
2003-12-07 01:18:55 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionClass *
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonGetAClass(const Button * b)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
|
|
|
return b->aclass;
|
|
|
|
}
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
Window
|
2005-06-09 11:28:13 -07:00
|
|
|
ButtonGetWin(const Button * b)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
|
|
|
return EoGetWin(b);
|
|
|
|
}
|
|
|
|
|
2003-12-07 01:18:55 -08:00
|
|
|
int
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonGetWidth(const Button * b)
|
|
|
|
{
|
|
|
|
return EoGetW(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ButtonGetHeight(const Button * b)
|
|
|
|
{
|
|
|
|
return EoGetH(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ButtonIsFixed(const Button * b)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
|
|
|
return b->flags & FLAG_FIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonIsInternal(const Button * b)
|
|
|
|
{
|
|
|
|
return b->internal;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ButtonDoShowDefault(const Button * b)
|
|
|
|
{
|
|
|
|
return !b->internal && b->default_show;
|
|
|
|
}
|
|
|
|
|
2005-06-09 11:28:13 -07:00
|
|
|
void
|
|
|
|
ButtonDoAction(Button * b, EWin * ewin, XEvent * ev)
|
|
|
|
{
|
2005-06-30 05:37:43 -07:00
|
|
|
if (b->aclass && !Mode_buttons.action_inhibit)
|
|
|
|
ActionclassEvent(b->aclass, ev, ewin);
|
2005-06-09 11:28:13 -07:00
|
|
|
}
|
|
|
|
|
2005-06-30 05:37:43 -07:00
|
|
|
#if 1 /* Unused */
|
2004-12-28 15:46:49 -08:00
|
|
|
int
|
|
|
|
ButtonEmbedWindow(Button * b, Window WindowToEmbed)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
|
2005-04-23 01:28:04 -07:00
|
|
|
int w, h;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2005-02-02 09:12:07 -08:00
|
|
|
EReparentWindow(WindowToEmbed, EoGetWin(b), 0, 0);
|
2004-12-28 15:46:49 -08:00
|
|
|
b->inside_win = WindowToEmbed;
|
2005-03-06 13:29:46 -08:00
|
|
|
EGetGeometry(WindowToEmbed, NULL, NULL, NULL, &w, &h, NULL, NULL);
|
2005-02-02 09:12:07 -08:00
|
|
|
EMoveWindow(b->inside_win, (EoGetW(b) - w) >> 1, (EoGetH(b) - h) >> 1);
|
2004-12-28 15:46:49 -08:00
|
|
|
b->event_win = ECreateEventWindow(EoGetWin(b), 0, 0, w, h);
|
|
|
|
EventCallbackRegister(b->event_win, 0, ButtonHandleEvents, b);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2005-02-02 09:12:07 -08:00
|
|
|
ESelectInput(b->event_win,
|
2003-05-22 12:15:03 -07:00
|
|
|
ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
|
|
|
|
LeaveWindowMask | ButtonMotionMask);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2005-02-02 09:12:07 -08:00
|
|
|
EMoveWindow(b->event_win, (EoGetW(b) - w) >> 1, (EoGetH(b) - h) >> 1);
|
|
|
|
EMapRaised(b->event_win);
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2005-01-25 13:58:28 -08:00
|
|
|
return 0;
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
2005-06-30 05:37:43 -07:00
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
ButtonDragStart(Button * b)
|
|
|
|
{
|
|
|
|
if (ButtonIsFixed(b))
|
|
|
|
return;
|
|
|
|
|
|
|
|
GrabPointerSet(EoGetWin(b), ECSR_GRAB, 0);
|
|
|
|
Mode.mode = MODE_BUTTONDRAG;
|
2005-06-09 11:28:13 -07:00
|
|
|
Mode_buttons.move_pending = 1;
|
2005-08-15 09:57:13 -07:00
|
|
|
Mode_buttons.start_x = Mode.events.x;
|
|
|
|
Mode_buttons.start_y = Mode.events.y;
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ButtonDragEnd(Button * b)
|
|
|
|
{
|
|
|
|
int d;
|
|
|
|
|
|
|
|
Mode.mode = MODE_NONE;
|
2005-01-08 00:46:39 -08:00
|
|
|
|
2005-06-09 11:28:13 -07:00
|
|
|
if (!Mode_buttons.move_pending)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-08-15 09:57:13 -07:00
|
|
|
d = DesktopAt(Mode.events.x, Mode.events.y);
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonMoveToDesktop(b, d);
|
2005-01-09 02:06:29 -08:00
|
|
|
d = EoGetDesk(b);
|
2004-12-28 15:46:49 -08:00
|
|
|
ButtonMoveRelative(b, -DeskGetX(d), -DeskGetY(d));
|
|
|
|
}
|
|
|
|
else
|
2005-06-09 11:28:13 -07:00
|
|
|
Mode_buttons.move_pending = 0;
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
autosave();
|
|
|
|
}
|
|
|
|
|
2003-12-07 01:18:55 -08:00
|
|
|
/*
|
|
|
|
* Functions operating on all buttons
|
|
|
|
*/
|
|
|
|
|
|
|
|
Button *
|
|
|
|
FindButton(Window win)
|
|
|
|
{
|
|
|
|
Button *b;
|
|
|
|
Button **buttons;
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
buttons = (Button **) ListItemType(&num, LIST_TYPE_BUTTON);
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((win == EoGetWin(buttons[i])) || (win == buttons[i]->inside_win)
|
2003-12-07 01:18:55 -08:00
|
|
|
|| (win == buttons[i]->event_win))
|
|
|
|
{
|
|
|
|
b = buttons[i];
|
|
|
|
Efree(buttons);
|
2005-01-25 13:58:28 -08:00
|
|
|
return b;
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buttons)
|
|
|
|
Efree(buttons);
|
2005-01-25 13:58:28 -08:00
|
|
|
|
|
|
|
return NULL;
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Button event handlers
|
|
|
|
*/
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
ButtonEventMouseDown(Button * b, XEvent * ev)
|
|
|
|
{
|
|
|
|
Window win = ev->xbutton.window;
|
|
|
|
ActionClass *ac;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2005-03-05 04:19:48 -08:00
|
|
|
Mode_buttons.button = b;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
GrabPointerSet(win, ECSR_GRAB, 0);
|
|
|
|
|
|
|
|
if (b->inside_win)
|
|
|
|
{
|
|
|
|
ev->xbutton.window = b->inside_win;
|
|
|
|
XSendEvent(disp, b->inside_win, False, ButtonPressMask, ev);
|
|
|
|
ev->xbutton.window = win;
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
b->state = STATE_CLICKED;
|
|
|
|
ButtonDraw(b);
|
|
|
|
|
2005-06-09 11:28:13 -07:00
|
|
|
if (!b->internal)
|
|
|
|
{
|
|
|
|
ac = FindItem("ACTION_BUTTON_DRAG", 0, LIST_FINDBY_NAME,
|
|
|
|
LIST_TYPE_ACLASS);
|
2005-06-30 05:37:43 -07:00
|
|
|
if (ac && !Mode_buttons.action_inhibit)
|
|
|
|
ActionclassEvent(ac, ev, NULL);
|
2005-06-09 11:28:13 -07:00
|
|
|
}
|
|
|
|
|
2005-06-30 05:37:43 -07:00
|
|
|
if (b->aclass && !Mode_buttons.action_inhibit)
|
|
|
|
ActionclassEvent(b->aclass, ev, NULL);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
ButtonEventMouseUp(Button * b, XEvent * ev)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
|
|
|
Window win = ev->xbutton.window;
|
|
|
|
|
2005-06-30 05:37:43 -07:00
|
|
|
if (b->inside_win && !Mode_buttons.action_inhibit)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
ev->xbutton.window = b->inside_win;
|
|
|
|
XSendEvent(disp, b->inside_win, False, ButtonReleaseMask, ev);
|
|
|
|
ev->xbutton.window = win;
|
|
|
|
}
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((b->state == STATE_CLICKED) && (!b->left))
|
|
|
|
b->state = STATE_HILITED;
|
|
|
|
else
|
|
|
|
b->state = STATE_NORMAL;
|
|
|
|
ButtonDraw(b);
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2005-06-09 11:28:13 -07:00
|
|
|
#if 1 /* FIXME - Here? */
|
|
|
|
GrabPointerRelease();
|
|
|
|
#endif
|
|
|
|
|
2005-06-30 05:37:43 -07:00
|
|
|
if (b->aclass && !b->left && !Mode_buttons.action_inhibit)
|
|
|
|
ActionclassEvent(b->aclass, ev, NULL);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
b->left = 0;
|
|
|
|
|
|
|
|
if (Mode.mode == MODE_BUTTONDRAG)
|
2005-03-05 04:19:48 -08:00
|
|
|
ButtonDragEnd(Mode_buttons.button);
|
|
|
|
Mode_buttons.button = NULL;
|
2005-01-08 00:46:39 -08:00
|
|
|
|
2005-06-09 11:28:13 -07:00
|
|
|
#if 0 /* FIXME - Move? */
|
2005-01-08 00:46:39 -08:00
|
|
|
GrabPointerRelease();
|
2005-06-09 11:28:13 -07:00
|
|
|
#endif
|
2005-06-30 05:37:43 -07:00
|
|
|
Mode_buttons.action_inhibit = 0;
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ButtonEventMotion(Button * b, XEvent * ev __UNUSED__)
|
|
|
|
{
|
|
|
|
int dx, dy;
|
|
|
|
|
|
|
|
if (Mode.mode != MODE_BUTTONDRAG)
|
|
|
|
return;
|
|
|
|
|
2005-08-15 09:57:13 -07:00
|
|
|
dx = Mode.events.x - Mode.events.px;
|
|
|
|
dy = Mode.events.y - Mode.events.py;
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2005-06-09 11:28:13 -07:00
|
|
|
if (Mode_buttons.move_pending)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
2005-08-15 09:57:13 -07:00
|
|
|
x = Mode.events.x - Mode_buttons.start_x;
|
|
|
|
y = Mode.events.y - Mode_buttons.start_y;
|
2004-12-28 15:46:49 -08:00
|
|
|
if (x < 0)
|
|
|
|
x = -x;
|
|
|
|
if (y < 0)
|
|
|
|
y = -y;
|
|
|
|
if ((x > Conf.button_move_resistance) ||
|
|
|
|
(y > Conf.button_move_resistance))
|
2005-06-09 11:28:13 -07:00
|
|
|
Mode_buttons.move_pending = 0;
|
2005-06-30 05:37:43 -07:00
|
|
|
Mode_buttons.action_inhibit = 1;
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2005-06-09 11:28:13 -07:00
|
|
|
if (!Mode_buttons.move_pending)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
|
|
|
if (b)
|
|
|
|
{
|
|
|
|
ButtonMoveRelative(b, dx, dy);
|
2005-04-23 00:31:18 -07:00
|
|
|
#if 0 /* FIXME - Not active */
|
2004-12-28 15:46:49 -08:00
|
|
|
if (Conf.deskmode == MODE_DESKRAY)
|
|
|
|
{
|
2005-02-26 08:40:36 -08:00
|
|
|
DeskMove(Mode.deskdrag, DeskGetX(Mode.deskdrag),
|
|
|
|
DeskGetY(Mode.deskdrag) + dy);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2005-04-23 00:31:18 -07:00
|
|
|
#endif
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
}
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
ButtonEventMouseIn(Button * b, XEvent * ev)
|
|
|
|
{
|
|
|
|
if (b->state == STATE_CLICKED)
|
|
|
|
b->left = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b->state = STATE_HILITED;
|
|
|
|
ButtonDraw(b);
|
2005-06-30 05:37:43 -07:00
|
|
|
if (b->aclass && !Mode_buttons.action_inhibit)
|
|
|
|
ActionclassEvent(b->aclass, ev, NULL);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
ButtonEventMouseOut(Button * b, XEvent * ev)
|
|
|
|
{
|
|
|
|
if (b->state == STATE_CLICKED)
|
|
|
|
b->left = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b->state = STATE_NORMAL;
|
|
|
|
ButtonDraw(b);
|
2005-06-30 05:37:43 -07:00
|
|
|
if (b->aclass && !Mode_buttons.action_inhibit)
|
|
|
|
ActionclassEvent(b->aclass, ev, NULL);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
ButtonHandleEvents(XEvent * ev, void *prm)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
Button *b = (Button *) prm;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
switch (ev->type)
|
|
|
|
{
|
|
|
|
case ButtonPress:
|
|
|
|
ButtonEventMouseDown(b, ev);
|
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
|
|
|
ButtonEventMouseUp(b, ev);
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
ButtonEventMotion(b, ev);
|
|
|
|
break;
|
|
|
|
case EnterNotify:
|
|
|
|
ButtonEventMouseIn(b, ev);
|
|
|
|
break;
|
|
|
|
case LeaveNotify:
|
|
|
|
ButtonEventMouseOut(b, ev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
/*
|
|
|
|
* Configuration load/save
|
|
|
|
*/
|
|
|
|
#include "conf.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
ButtonsConfigLoad(FILE * ConfigFile)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
char s[FILEPATH_LEN_MAX];
|
|
|
|
char s2[FILEPATH_LEN_MAX];
|
|
|
|
int i1;
|
|
|
|
char *name = NULL;
|
|
|
|
char *label = NULL;
|
|
|
|
ActionClass *ac = NULL;
|
|
|
|
ImageClass *ic = NULL;
|
|
|
|
TextClass *tc = NULL;
|
|
|
|
Button *bt = NULL;
|
|
|
|
Button *pbt = NULL;
|
|
|
|
char ontop = 0;
|
|
|
|
int flags = 0, minw = 1, maxw = 99999, minh = 1;
|
|
|
|
int maxh = 99999, xo = 0, yo = 0, xa = 0;
|
|
|
|
int xr = 0, ya = 0, yr = 0;
|
|
|
|
int xsr = 0, xsa = 0, ysr = 0, ysa = 0;
|
|
|
|
char simg = 0;
|
|
|
|
int desk = 0;
|
|
|
|
char sticky = 0;
|
|
|
|
char show = 1;
|
|
|
|
char internal = 0;
|
|
|
|
int fields;
|
|
|
|
|
|
|
|
while (GetLine(s, sizeof(s), ConfigFile))
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
s2[0] = 0;
|
|
|
|
i1 = CONFIG_INVALID;
|
|
|
|
fields = sscanf(s, "%i %4000s", &i1, s2);
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if (fields < 1)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
i1 = CONFIG_INVALID;
|
|
|
|
}
|
|
|
|
else if (i1 == CONFIG_CLOSE)
|
|
|
|
{
|
|
|
|
if (fields != 1)
|
|
|
|
{
|
|
|
|
RecoverUserConfig();
|
|
|
|
Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (i1 != CONFIG_INVALID)
|
|
|
|
{
|
|
|
|
if (fields != 2)
|
|
|
|
{
|
|
|
|
RecoverUserConfig();
|
|
|
|
Alert(_("CONFIG: missing required data in \"%s\"\n"), s);
|
|
|
|
i1 = CONFIG_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (i1)
|
|
|
|
{
|
|
|
|
case CONFIG_CLOSE:
|
2005-03-05 04:19:48 -08:00
|
|
|
if (!pbt && !Mode_buttons.loading_user)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
|
|
|
bt = ButtonCreate(name, 0, ic, ac, tc, label, ontop, flags,
|
|
|
|
minw, maxw, minh, maxh, xo, yo, xa, xr,
|
|
|
|
ya, yr, xsr, xsa, ysr, ysa, simg, desk,
|
|
|
|
sticky);
|
|
|
|
bt->default_show = show;
|
|
|
|
bt->internal = internal;
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
case CONFIG_TEXT:
|
|
|
|
tc = TextclassFind(s2, 1);
|
|
|
|
if (pbt)
|
|
|
|
pbt->tclass = tc;
|
|
|
|
break;
|
|
|
|
case BUTTON_LABEL:
|
2005-03-05 04:19:48 -08:00
|
|
|
_EFREE(label);
|
2004-12-28 15:46:49 -08:00
|
|
|
label = Estrdup(atword(s, 2));
|
|
|
|
if (pbt)
|
2005-03-05 04:19:48 -08:00
|
|
|
{
|
|
|
|
_EFREE(pbt->label);
|
|
|
|
pbt->label = label;
|
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
break;
|
|
|
|
case BORDERPART_ONTOP:
|
|
|
|
ontop = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
EoSetLayer(pbt, ontop);
|
|
|
|
break;
|
|
|
|
case CONFIG_CLASSNAME:
|
|
|
|
case BUTTON_NAME:
|
2005-03-05 04:19:48 -08:00
|
|
|
_EFREE(name);
|
2004-12-28 15:46:49 -08:00
|
|
|
name = Estrdup(s2);
|
|
|
|
pbt = FindItem(name, 0, LIST_FINDBY_NAME, LIST_TYPE_BUTTON);
|
|
|
|
break;
|
|
|
|
case CONFIG_ACTIONCLASS:
|
|
|
|
case BUTTON_ACLASS:
|
|
|
|
ac = FindItem(s2, 0, LIST_FINDBY_NAME, LIST_TYPE_ACLASS);
|
|
|
|
if (pbt)
|
|
|
|
pbt->aclass = ac;
|
|
|
|
break;
|
|
|
|
case CONFIG_IMAGECLASS:
|
|
|
|
case BUTTON_ICLASS:
|
|
|
|
ic = ImageclassFind(s2, 1);
|
|
|
|
if (pbt)
|
|
|
|
pbt->iclass = ic;
|
|
|
|
break;
|
|
|
|
case BORDERPART_WMIN:
|
|
|
|
minw = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.width.min = minw;
|
|
|
|
break;
|
|
|
|
case BORDERPART_WMAX:
|
|
|
|
maxw = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.width.max = maxw;
|
|
|
|
break;
|
|
|
|
case BORDERPART_HMIN:
|
|
|
|
minh = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.height.min = minh;
|
|
|
|
break;
|
|
|
|
case BORDERPART_FLAGS:
|
|
|
|
flags = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->flags = flags;
|
|
|
|
break;
|
|
|
|
case BORDERPART_HMAX:
|
|
|
|
maxh = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.height.max = maxh;
|
|
|
|
break;
|
|
|
|
case BUTTON_XO:
|
|
|
|
xo = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.xorigin = xo;
|
|
|
|
break;
|
|
|
|
case BUTTON_YO:
|
|
|
|
yo = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.yorigin = yo;
|
|
|
|
break;
|
|
|
|
case BUTTON_XA:
|
|
|
|
xa = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.xabs = xa;
|
|
|
|
break;
|
|
|
|
case BUTTON_XR:
|
|
|
|
xr = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.xrel = xr;
|
|
|
|
break;
|
|
|
|
case BUTTON_YA:
|
|
|
|
ya = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.yabs = ya;
|
|
|
|
break;
|
|
|
|
case BUTTON_YR:
|
|
|
|
yr = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.yrel = yr;
|
|
|
|
break;
|
|
|
|
case BUTTON_XSR:
|
|
|
|
xsr = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.xsizerel = xsr;
|
|
|
|
break;
|
|
|
|
case BUTTON_XSA:
|
|
|
|
xsa = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.xsizeabs = xsa;
|
|
|
|
break;
|
|
|
|
case BUTTON_YSR:
|
|
|
|
ysr = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.ysizerel = ysr;
|
|
|
|
break;
|
|
|
|
case BUTTON_YSA:
|
|
|
|
ysa = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.ysizeabs = ysa;
|
|
|
|
break;
|
|
|
|
case BUTTON_SIMG:
|
|
|
|
simg = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->geom.size_from_image = simg;
|
|
|
|
break;
|
|
|
|
case BUTTON_DESK:
|
|
|
|
desk = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
ButtonMoveToDesktop(pbt, desk);
|
|
|
|
break;
|
|
|
|
case BUTTON_STICKY:
|
|
|
|
sticky = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
EoSetSticky(pbt, sticky);
|
|
|
|
break;
|
|
|
|
case BUTTON_INTERNAL:
|
|
|
|
internal = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->internal = internal;
|
|
|
|
break;
|
|
|
|
case BUTTON_SHOW:
|
|
|
|
show = atoi(s2);
|
|
|
|
if (pbt)
|
|
|
|
pbt->default_show = show;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
err = -1;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
done:
|
2005-03-05 04:19:48 -08:00
|
|
|
_EFREE(name);
|
|
|
|
_EFREE(label);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
return err;
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
2005-03-05 04:19:48 -08:00
|
|
|
static void
|
|
|
|
ButtonsConfigLoadUser(void)
|
|
|
|
{
|
|
|
|
char s[4096];
|
|
|
|
|
|
|
|
Esnprintf(s, sizeof(s), "%s.buttons", EGetSavePrefix());
|
|
|
|
|
|
|
|
Mode_buttons.loading_user = 1;
|
|
|
|
ConfigFileLoad(s, NULL, ConfigFileRead, 0);
|
|
|
|
Mode_buttons.loading_user = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ButtonsConfigSave(void)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2005-03-05 04:19:48 -08:00
|
|
|
char s[FILEPATH_LEN_MAX], st[FILEPATH_LEN_MAX];
|
|
|
|
FILE *fs;
|
2003-12-07 01:18:55 -08:00
|
|
|
int i, num;
|
2004-12-28 15:46:49 -08:00
|
|
|
Button **blst;
|
|
|
|
int flags;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
blst = (Button **) ListItemTypeID(&num, LIST_TYPE_BUTTON, 0);
|
|
|
|
if (!blst)
|
2005-03-05 04:19:48 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
Etmp(st);
|
|
|
|
fs = fopen(st, "w");
|
|
|
|
if (!fs)
|
|
|
|
return;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
if (blst[i]->internal)
|
2003-12-07 01:18:55 -08:00
|
|
|
continue;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
fprintf(fs, "4 999\n");
|
2005-04-17 06:58:09 -07:00
|
|
|
fprintf(fs, "100 %s\n", EoGetName(blst[i]));
|
2004-12-28 15:46:49 -08:00
|
|
|
if (blst[i]->iclass)
|
|
|
|
fprintf(fs, "12 %s\n", blst[i]->iclass->name);
|
|
|
|
if (blst[i]->aclass)
|
|
|
|
fprintf(fs, "11 %s\n", ActionclassGetName(blst[i]->aclass));
|
|
|
|
if (EoGetLayer(blst[i]) >= 0)
|
|
|
|
fprintf(fs, "453 %i\n", EoGetLayer(blst[i]));
|
|
|
|
fprintf(fs, "456 %i\n", blst[i]->geom.width.min);
|
|
|
|
fprintf(fs, "457 %i\n", blst[i]->geom.width.max);
|
|
|
|
fprintf(fs, "468 %i\n", blst[i]->geom.height.min);
|
|
|
|
fprintf(fs, "469 %i\n", blst[i]->geom.height.max);
|
|
|
|
fprintf(fs, "528 %i\n", blst[i]->geom.xorigin);
|
|
|
|
fprintf(fs, "529 %i\n", blst[i]->geom.yorigin);
|
|
|
|
fprintf(fs, "530 %i\n", blst[i]->geom.xabs);
|
|
|
|
fprintf(fs, "531 %i\n", blst[i]->geom.xrel);
|
|
|
|
fprintf(fs, "532 %i\n", blst[i]->geom.yabs);
|
|
|
|
fprintf(fs, "533 %i\n", blst[i]->geom.yrel);
|
|
|
|
fprintf(fs, "534 %i\n", blst[i]->geom.xsizerel);
|
|
|
|
fprintf(fs, "535 %i\n", blst[i]->geom.xsizeabs);
|
|
|
|
fprintf(fs, "536 %i\n", blst[i]->geom.ysizerel);
|
|
|
|
fprintf(fs, "537 %i\n", blst[i]->geom.ysizeabs);
|
|
|
|
fprintf(fs, "538 %i\n", blst[i]->geom.size_from_image);
|
|
|
|
fprintf(fs, "539 %i\n", EoGetDesk(blst[i]));
|
|
|
|
fprintf(fs, "540 %i\n", EoIsSticky(blst[i]));
|
2005-04-12 09:43:39 -07:00
|
|
|
fprintf(fs, "542 %i\n", EoIsShown(blst[i]));
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
if (blst[i]->flags)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
flags = 0;
|
|
|
|
if (((blst[i]->flags & FLAG_FIXED_HORIZ)
|
|
|
|
&& (blst[i]->flags & FLAG_FIXED_VERT))
|
|
|
|
|| (blst[i]->flags & FLAG_FIXED))
|
|
|
|
flags = 2;
|
|
|
|
else if (blst[i]->flags & FLAG_FIXED_HORIZ)
|
|
|
|
flags = 3;
|
|
|
|
else if (blst[i]->flags & FLAG_FIXED_VERT)
|
|
|
|
flags = 4;
|
|
|
|
else if (blst[i]->flags & FLAG_TITLE)
|
|
|
|
flags = 0;
|
|
|
|
else if (blst[i]->flags & FLAG_MINIICON)
|
|
|
|
flags = 1;
|
|
|
|
fprintf(fs, "454 %i\n", flags);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
fprintf(fs, "1000\n");
|
|
|
|
}
|
|
|
|
|
2005-03-05 04:19:48 -08:00
|
|
|
fclose(fs);
|
|
|
|
|
|
|
|
Esnprintf(s, sizeof(s), "%s.buttons", EGetSavePrefix());
|
|
|
|
E_mv(st, s);
|
|
|
|
|
|
|
|
Efree(blst);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buttons Module
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ButtonsSighan(int sig, void *prm __UNUSED__)
|
|
|
|
{
|
|
|
|
switch (sig)
|
|
|
|
{
|
2005-03-05 04:19:48 -08:00
|
|
|
case ESIGNAL_INIT:
|
|
|
|
memset(&Mode_buttons, 0, sizeof(Mode_buttons));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESIGNAL_CONFIGURE:
|
|
|
|
ButtonsConfigLoadUser();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESIGNAL_EXIT:
|
2005-03-19 03:10:12 -08:00
|
|
|
if (Mode.wm.save_ok)
|
|
|
|
ButtonsConfigSave();
|
2003-12-07 01:18:55 -08:00
|
|
|
break;
|
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doHideShowButton(const char *params)
|
|
|
|
{
|
|
|
|
Button **lst, *b;
|
|
|
|
char s[1024];
|
|
|
|
const char *ss;
|
|
|
|
int num, i;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2005-02-26 17:53:22 -08:00
|
|
|
if (!params)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-02-26 17:53:22 -08:00
|
|
|
lst = (Button **) ListItemTypeID(&num, LIST_TYPE_BUTTON, 0);
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
ButtonToggle(lst[i]);
|
|
|
|
if (lst)
|
|
|
|
Efree(lst);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
sscanf(params, "%1000s", s);
|
|
|
|
if (!strcmp(s, "button"))
|
|
|
|
{
|
|
|
|
sscanf(params, "%*s %1000s", s);
|
|
|
|
b = FindItem(s, 0, LIST_FINDBY_NAME, LIST_TYPE_BUTTON);
|
|
|
|
if (b)
|
|
|
|
ButtonToggle(b);
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "buttons"))
|
|
|
|
{
|
|
|
|
ss = atword(params, 2);
|
|
|
|
if (!ss)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lst = (Button **) ListItemType(&num, LIST_TYPE_BUTTON);
|
|
|
|
for (i = 0; i < num; i++)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-02-26 17:53:22 -08:00
|
|
|
if (matchregexp(ss, ButtonGetName(lst[i])))
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-02-26 17:53:22 -08:00
|
|
|
if (strcmp(ButtonGetName(lst[i]),
|
|
|
|
"_DESKTOP_DESKRAY_DRAG_CONTROL"))
|
|
|
|
ButtonToggle(lst[i]);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
}
|
2005-02-26 17:53:22 -08:00
|
|
|
if (lst)
|
|
|
|
Efree(lst);
|
|
|
|
}
|
|
|
|
else if (!strcmp(s, "all_buttons_except"))
|
|
|
|
{
|
|
|
|
ss = atword(params, 2);
|
|
|
|
if (!ss)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lst = (Button **) ListItemTypeID(&num, LIST_TYPE_BUTTON, 0);
|
|
|
|
for (i = 0; i < num; i++)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-02-26 17:53:22 -08:00
|
|
|
if (!matchregexp(ss, ButtonGetName(lst[i])))
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-02-26 17:53:22 -08:00
|
|
|
if (strcmp(ButtonGetName(lst[i]),
|
|
|
|
"_DESKTOP_DESKRAY_DRAG_CONTROL"))
|
|
|
|
ButtonToggle(lst[i]);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
}
|
2005-02-26 17:53:22 -08:00
|
|
|
if (lst)
|
|
|
|
Efree(lst);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2005-02-26 17:53:22 -08:00
|
|
|
else if (!strcmp(s, "all"))
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-02-26 17:53:22 -08:00
|
|
|
lst = (Button **) ListItemType(&num, LIST_TYPE_BUTTON);
|
|
|
|
for (i = 0; i < num; i++)
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
2005-02-26 17:53:22 -08:00
|
|
|
if (strcmp(ButtonGetName(lst[i]), "_DESKTOP_DESKRAY_DRAG_CONTROL"))
|
|
|
|
ButtonToggle(lst[i]);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2005-02-26 17:53:22 -08:00
|
|
|
if (lst)
|
|
|
|
Efree(lst);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2005-02-26 17:53:22 -08:00
|
|
|
|
|
|
|
done:
|
2004-12-28 15:46:49 -08:00
|
|
|
autosave();
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
ButtonsIpc(const char *params, Client * c __UNUSED__)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
const char *p;
|
|
|
|
char cmd[128], prm[4096];
|
|
|
|
int i, len, num;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
cmd[0] = prm[0] = '\0';
|
|
|
|
p = params;
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
sscanf(p, "%100s %4000s %n", cmd, prm, &len);
|
|
|
|
p += len;
|
|
|
|
}
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if (!p || cmd[0] == '?')
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
else if (!strncmp(cmd, "list", 2))
|
|
|
|
{
|
|
|
|
Button **lst, *b;
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2005-01-09 02:06:29 -08:00
|
|
|
IpcPrintf("Win d s l x y w h name\n");
|
2004-12-28 15:46:49 -08:00
|
|
|
lst = (Button **) ListItemType(&num, LIST_TYPE_BUTTON);
|
|
|
|
for (i = 0; i < num; i++)
|
2003-12-07 01:18:55 -08:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
b = lst[i];
|
|
|
|
IpcPrintf("%#lx %2d %2d %2d %5d+%5d %5dx%5d %s\n",
|
|
|
|
EoGetWin(b), EoGetDesk(b), EoIsSticky(b), EoGetLayer(b),
|
|
|
|
EoGetX(b), EoGetY(b), EoGetW(b), EoGetH(b),
|
|
|
|
ButtonGetName(lst[i]));
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
if (lst)
|
|
|
|
Efree(lst);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (!strncmp(cmd, "move", 2))
|
|
|
|
{
|
2005-03-05 04:19:48 -08:00
|
|
|
if (Mode_buttons.button)
|
|
|
|
ButtonDragStart(Mode_buttons.button);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2003-12-07 01:18:55 -08:00
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
static void
|
|
|
|
IPC_ButtonShow(const char *params, Client * c __UNUSED__)
|
|
|
|
{
|
|
|
|
doHideShowButton(params);
|
2003-12-07 01:18:55 -08:00
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
IpcItem ButtonsIpcArray[] = {
|
|
|
|
{
|
|
|
|
ButtonsIpc,
|
|
|
|
"button", "btn",
|
|
|
|
"Button functions",
|
|
|
|
" button list List buttons\n"},
|
|
|
|
{
|
|
|
|
IPC_ButtonShow,
|
|
|
|
"button_show", NULL,
|
|
|
|
"Show or Hide buttons on desktop",
|
|
|
|
"use \"button_show <button/buttons/all_buttons_except/all> "
|
|
|
|
"<BUTTON_STRING>\"\nexamples: \"button_show buttons all\" "
|
|
|
|
"(removes all buttons and the dragbar)\n\"button_show\" "
|
|
|
|
"(removes all buttons)\n \"button_show buttons CONFIG*\" "
|
|
|
|
"(removes all buttons with CONFIG in the start)\n"},
|
|
|
|
};
|
|
|
|
#define N_IPC_FUNCS (sizeof(ButtonsIpcArray)/sizeof(IpcItem))
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static const CfgItem ButtonsCfgItems[] = {
|
|
|
|
CFG_ITEM_BOOL(Conf.buttons, enable, 1),
|
|
|
|
};
|
|
|
|
#define N_CFG_ITEMS (sizeof(ButtonsCfgItems)/sizeof(CfgItem))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module descriptor
|
|
|
|
*/
|
|
|
|
EModule ModButtons = {
|
|
|
|
"buttons", "btn",
|
|
|
|
ButtonsSighan,
|
|
|
|
{N_IPC_FUNCS, ButtonsIpcArray},
|
|
|
|
{0, NULL}
|
|
|
|
};
|