wmclockmon: update change-log
[dockapps.git] / wmget / dockapp / da_mouse.c
blob9c56b183e25fbb8445d4defb8fa905be03f78351
1 /*
2 wmget - A background download manager as a Window Maker dock app
3 Copyright (c) 2001-2003 Aaron Trickey <aaron@amtrickey.net>
5 Permission is hereby granted, free of charge, to any person
6 obtaining a copy of this software and associated documentation files
7 (the "Software"), to deal in the Software without restriction,
8 including without limitation the rights to use, copy, modify, merge,
9 publish, distribute, sublicense, and/or sell copies of the Software,
10 and to permit persons to whom the Software is furnished to do so,
11 subject to the following conditions:
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 ********************************************************************
25 dockapp/da_mouse.c - Mouse/clickregion handling
27 This code keeps track of app-registered ``clickregions'', which
28 represent clickable rectangles and button/modifier masks associated
29 with app callbacks.
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include "dockapp.h"
36 #define DOCKAPP_EXPOSE_INTERNALS
37 #include "da_mouse.h"
41 typedef struct {
42 int x, y, w, h;
43 int buttonmask;
45 dockapp_rv_t (*cb) (void *, int x, int y);
46 void *cbdata;
47 } da_clickregion;
50 /* for now we use a simple array of clickregions
52 #define DA_MAX_CLICKREGIONS 50
53 static da_clickregion da_clickregions[DA_MAX_CLICKREGIONS];
54 static size_t da_num_clickregions = 0;
57 /* a mouse-down simply stores the mouse state here for later processing
58 * by a mouse-up
60 static int da_mouse_down_x;
61 static int da_mouse_down_y;
62 static int da_mouse_down_buttons;
65 void da_mouse_button_down (int x, int y, int buttons)
67 /* fprintf (stderr, "hello from da_mouse_button_down\n"); */
68 da_mouse_down_x = x;
69 da_mouse_down_y = y;
70 da_mouse_down_buttons = buttons;
74 dockapp_rv_t da_mouse_button_up (int x, int y, int buttons)
76 da_clickregion *c, *end;
79 fprintf (stderr, "hello from da_mouse_button_up, btns=0x%02x\n",
80 buttons);
83 end = da_clickregions + da_num_clickregions;
85 for (c = da_clickregions; c < end; ++c) {
86 if (((buttons & c->buttonmask) == c->buttonmask)
87 && x >= c->x && x < c->x + c->w
88 && y >= c->y && y < c->y + c->h
89 && da_mouse_down_x >= c->x && da_mouse_down_x < c->x + c->w
90 && da_mouse_down_y >= c->y && da_mouse_down_y < c->y + c->h) {
91 if (c->cb (c->cbdata, x, y) == dockapp_exit)
92 return dockapp_exit;
96 return dockapp_ok;
100 dockapp_rv_t dockapp_add_clickregion (
101 int x, int y, int w, int h,
102 int buttonmask,
103 dockapp_rv_t (*cb) (void *, int x, int y),
104 void *cbdata)
106 da_clickregion *c;
108 if (da_num_clickregions >= DA_MAX_CLICKREGIONS)
109 return dockapp_rv_too_many_clickregions;
111 c = da_clickregions + da_num_clickregions++;
113 c->x = x;
114 c->y = y;
115 c->w = w;
116 c->h = h;
117 c->buttonmask = buttonmask;
118 c->cb = cb;
119 c->cbdata = cbdata;
121 return dockapp_ok;