Add option to merge the workspace-switching functionality into the dock
[wmaker-crm.git] / src / geomview.c
blobf067ce4995dc0d44ceb1dbbd50e72784215b46a4
2 #include <WINGs/WINGsP.h>
4 typedef struct W_GeometryView {
5 W_Class widgetClass;
6 WMView *view;
8 WMColor *color;
9 WMColor *bgColor;
11 WMFont *font;
13 WMSize textSize;
15 union {
16 struct {
17 int x, y;
18 } pos;
19 struct {
20 unsigned width, height;
21 } size;
22 } data;
24 unsigned showPosition:1;
25 } WGeometryView;
27 static void handleEvents(XEvent * event, void *clientData);
28 static void paint(WGeometryView * gview);
30 WGeometryView *WCreateGeometryView(WMScreen * scr)
32 WGeometryView *gview;
33 char buffer[64];
34 static W_Class widgetClass = 0;
36 if (!widgetClass) {
37 widgetClass = W_RegisterUserWidget();
40 gview = malloc(sizeof(WGeometryView));
41 if (!gview) {
42 return NULL;
44 memset(gview, 0, sizeof(WGeometryView));
46 gview->widgetClass = widgetClass;
48 gview->view = W_CreateTopView(scr);
49 if (!gview->view) {
50 wfree(gview);
52 return NULL;
54 gview->view->self = gview;
56 gview->font = WMSystemFontOfSize(scr, 12);
57 if (!gview->font) {
58 W_DestroyView(gview->view);
59 wfree(gview);
61 return NULL;
64 gview->bgColor = WMCreateRGBColor(scr, 0x3333, 0x6666, 0x9999, True);
65 gview->color = WMWhiteColor(scr);
67 WMCreateEventHandler(gview->view, ExposureMask, handleEvents, gview);
69 snprintf(buffer, sizeof(buffer), "%+05i, %+05i", 0, 0);
71 gview->textSize.width = WMWidthOfString(gview->font, buffer, strlen(buffer));
72 gview->textSize.height = WMFontHeight(gview->font);
74 WMSetWidgetBackgroundColor(gview, gview->bgColor);
76 W_ResizeView(gview->view, gview->textSize.width + 8, gview->textSize.height + 6);
78 return gview;
81 void WSetGeometryViewShownPosition(WGeometryView * gview, int x, int y)
83 gview->showPosition = 1;
84 gview->data.pos.x = x;
85 gview->data.pos.y = y;
87 paint(gview);
90 void WSetGeometryViewShownSize(WGeometryView * gview, unsigned width, unsigned height)
92 gview->showPosition = 0;
93 gview->data.size.width = width;
94 gview->data.size.height = height;
96 paint(gview);
99 static void paint(WGeometryView * gview)
101 char buffer[64];
103 if (gview->showPosition) {
104 snprintf(buffer, sizeof(buffer), "%+5i , %+5i ", gview->data.pos.x, gview->data.pos.y);
105 } else {
106 snprintf(buffer, sizeof(buffer), "%+5i x %+5i ",
107 gview->data.size.width, gview->data.size.height);
110 WMDrawImageString(W_VIEW_SCREEN(gview->view),
111 W_VIEW_DRAWABLE(gview->view),
112 gview->color, gview->bgColor, gview->font,
113 (W_VIEW_WIDTH(gview->view) - gview->textSize.width) / 2,
114 (W_VIEW_HEIGHT(gview->view) - gview->textSize.height) / 2, buffer, strlen(buffer));
116 W_DrawRelief(W_VIEW_SCREEN(gview->view), W_VIEW_DRAWABLE(gview->view),
117 0, 0, W_VIEW_WIDTH(gview->view), W_VIEW_HEIGHT(gview->view), WRSimple);
120 static void handleEvents(XEvent * event, void *clientData)
122 WGeometryView *gview = (WGeometryView *) clientData;
124 switch (event->type) {
125 case Expose:
126 paint(gview);
127 break;