summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2009-01-12 08:10:59 +0100
committerDanny Baumann <dannybaumann@web.de>2009-01-12 08:10:59 +0100
commit000a904456c0d834320162113ca5a1fd37e49978 (patch)
tree95108bc56b600e381e7252a0e00e0a7778cd2c52
parent2d20fabdbddf09e111ba844ac54ab12022cdd06b (diff)
downloadprompt-master.tar.gz
prompt-master.tar.bz2
Cleanup, optimizations.HEADmaster
-rw-r--r--prompt.c201
1 files changed, 95 insertions, 106 deletions
diff --git a/prompt.c b/prompt.c
index d343178..84fc5e8 100644
--- a/prompt.c
+++ b/prompt.c
@@ -38,10 +38,6 @@
#include "prompt_options.h"
-#define PI 3.1415926
-#define PI2 3.14159265358979323846
-#define DEG2RAD2(DEG) ((DEG)*((PI2)/(180.0)))
-
static int displayPrivateIndex;
typedef struct _PromptDisplay
@@ -55,30 +51,20 @@ typedef struct _PromptDisplay
typedef struct _PromptScreen
{
- PaintOutputProc paintOutput;
- int windowPrivateIndex;
+ PaintOutputProc paintOutput;
/* text display support */
CompTextData *textData;
-
- Bool title;
-
} PromptScreen;
#define GET_PROMPT_DISPLAY(d) \
((PromptDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
#define PROMPT_DISPLAY(d) \
- PromptDisplay *ad = GET_PROMPT_DISPLAY (d)
-#define GET_PROMPT_SCREEN(s, ad) \
- ((PromptScreen *) (s)->base.privates[(ad)->screenPrivateIndex].ptr)
+ PromptDisplay *pd = GET_PROMPT_DISPLAY (d)
+#define GET_PROMPT_SCREEN(s, pd) \
+ ((PromptScreen *) (s)->base.privates[(pd)->screenPrivateIndex].ptr)
#define PROMPT_SCREEN(s) \
- PromptScreen *as = GET_PROMPT_SCREEN (s, GET_PROMPT_DISPLAY (s->display))
-#define GET_PROMPT_WINDOW(w, as) \
- ((PromptWindow *) (w)->base.privates[ (as)->windowPrivateIndex].ptr)
-#define PROMPT_WINDOW(w) \
- PromptWindow *aw = GET_PROMPT_WINDOW (w, \
- GET_PROMPT_SCREEN (w->screen, \
- GET_PROMPT_DISPLAY (w->screen->display)))
+ PromptScreen *ps = GET_PROMPT_SCREEN (s, GET_PROMPT_DISPLAY (s->display))
/* Prototyping */
@@ -88,26 +74,27 @@ promptFreeTitle (CompScreen *s)
PROMPT_SCREEN(s);
PROMPT_DISPLAY (s->display);
- if (!as->textData)
+ if (!ps->textData)
return;
- (ad->textFunc->finiTextData) (s, as->textData);
- as->textData = NULL;
+ (pd->textFunc->finiTextData) (s, ps->textData);
+ ps->textData = NULL;
damageScreen (s);
}
static void
-promptRenderTitle (CompScreen *s, char *stringData)
+promptRenderTitle (CompScreen *s,
+ char *stringData)
{
CompTextAttrib tA;
+ int ox1, ox2, oy1, oy2;
PROMPT_SCREEN (s);
PROMPT_DISPLAY (s->display);
- //ringFreeWindowTitle (s);
+ promptFreeTitle (s);
- int ox1, ox2, oy1, oy2;
getCurrentOutputExtents (s, &ox1, &oy1, &ox2, &oy2);
/* 75% of the output device as maximum width */
@@ -130,7 +117,7 @@ promptRenderTitle (CompScreen *s, char *stringData)
tA.bgColor[2] = promptGetTitleBackColorBlue (s);
tA.bgColor[3] = promptGetTitleBackColorAlpha (s);
- as->textData = (ad->textFunc->renderText) (s, stringData, &tA);
+ ps->textData = (pd->textFunc->renderText) (s, stringData, &tA);
}
/* Stolen from ring.c */
@@ -138,22 +125,21 @@ promptRenderTitle (CompScreen *s, char *stringData)
static void
promptDrawTitle (CompScreen *s)
{
- PROMPT_SCREEN(s);
+ int ox1, ox2, oy1, oy2;
+ float x, y, width, height;
+
+ PROMPT_SCREEN (s);
PROMPT_DISPLAY (s->display);
- float width = as->textData->width;
- float height = as->textData->height;
+ width = ps->textData->width;
+ height = ps->textData->height;
- int ox1, ox2, oy1, oy2;
getCurrentOutputExtents (s, &ox1, &oy1, &ox2, &oy2);
- float x = ox1 + ((ox2 - ox1) / 2) - (width / 2);
- float y = oy1 + ((oy2 - oy1) / 2) + (height / 2);
-
- x = floor (x);
- y = floor (y);
+ x = floor (ox1 + ((ox2 - ox1) / 2) - (width / 2));
+ y = floor (oy1 + ((oy2 - oy1) / 2) + (height / 2));
- (ad->textFunc->drawText) (s, as->textData, x, y, 0.7f);
+ (pd->textFunc->drawText) (s, ps->textData, x, y, 0.7f);
}
static Bool
@@ -161,34 +147,34 @@ promptRemoveTitle (void *vs)
{
CompScreen *s = (CompScreen *) vs;
- PROMPT_SCREEN (s);
-
- as->title = FALSE;
+ PROMPT_DISPLAY (s->display);
promptFreeTitle (s);
+ pd->removeTextHandle = 0;
+
return FALSE;
}
/* Paint title on screen if neccessary */
static Bool
-promptPaintOutput (CompScreen *s,
- const ScreenPaintAttrib *sAttrib,
- const CompTransform *transform,
- Region region,
- CompOutput *output,
- unsigned int mask)
+promptPaintOutput (CompScreen *s,
+ const ScreenPaintAttrib *sAttrib,
+ const CompTransform *transform,
+ Region region,
+ CompOutput *output,
+ unsigned int mask)
{
Bool status;
PROMPT_SCREEN (s);
- UNWRAP (as, s, paintOutput);
+ UNWRAP (ps, s, paintOutput);
status = (*s->paintOutput) (s, sAttrib, transform, region, output, mask);
- WRAP (as, s, paintOutput, promptPaintOutput);
+ WRAP (ps, s, paintOutput, promptPaintOutput);
- if (as->title)
+ if (ps->textData)
{
CompTransform sTransform = *transform;
@@ -207,40 +193,42 @@ promptPaintOutput (CompScreen *s,
static Bool
promptDisplayText (CompDisplay *d,
- CompAction *action,
- CompActionState cstate,
- CompOption *option,
- int nOption)
+ CompAction *action,
+ CompActionState state,
+ CompOption *option,
+ int nOption)
{
+ Window xid;
+ CompScreen *s;
+
+ xid = getIntOptionNamed (option, nOption, "root", 0);
+ s = findScreenAtDisplay (d, xid);
+ if (s)
+ {
char *stringData;
- int timeout;
- Bool infinite = FALSE;
-
- CompWindow *w;
- w = findWindowAtDisplay (d, getIntOptionNamed (option, nOption,
- "window", 0));
- if (!w)
- return TRUE;
-
- CompScreen *s;
- s = findScreenAtDisplay (d, getIntOptionNamed (option, nOption,
- "root", 0));
- if (!s)
- return TRUE;
-
- PROMPT_SCREEN (w->screen);
-
- stringData = getStringOptionNamed (option, nOption, "string", "This message was not sent correctly");
- timeout = getIntOptionNamed(option, nOption, "timeout", 5000);
- if (timeout < 0)
- infinite = TRUE;
-
- /* Create Message */
- as->title = TRUE;
- promptRenderTitle (w->screen, stringData);
- if (!infinite)
- compAddTimeout (timeout, timeout * 1.2, promptRemoveTitle, s);
- damageScreen (s);
+ int timeout;
+
+ stringData = getStringOptionNamed (option, nOption, "string",
+ "This message was not"
+ "sent correctly");
+
+ timeout = getIntOptionNamed (option, nOption, "timeout", 5000);
+
+ /* Create Message */
+ promptRenderTitle (s, stringData);
+
+ if (timeout > 0)
+ {
+ PROMPT_DISPLAY (s->display);
+
+ if (pd->removeTextHandle)
+ compRemoveTimeout (pd->removeTextHandle);
+ pd->removeTextHandle = compAddTimeout (timeout, timeout * 1.2,
+ promptRemoveTitle, s);
+ }
+
+ damageScreen (s);
+ }
return TRUE;
}
@@ -249,43 +237,41 @@ promptDisplayText (CompDisplay *d,
static Bool
promptInitScreen (CompPlugin *p,
- CompScreen *s)
+ CompScreen *s)
{
- PromptScreen *as;
+ PromptScreen *ps;
PROMPT_DISPLAY (s->display);
- as = malloc (sizeof (PromptScreen));
- if (!as)
+ ps = malloc (sizeof (PromptScreen));
+ if (!ps)
return FALSE;
- s->base.privates[ad->screenPrivateIndex].ptr = as;
+ s->base.privates[pd->screenPrivateIndex].ptr = ps;
- as->textData = NULL;
+ ps->textData = NULL;
- as->title = FALSE;
-
- WRAP (as, s, paintOutput, promptPaintOutput);
+ WRAP (ps, s, paintOutput, promptPaintOutput);
return TRUE;
}
static void
promptFiniScreen (CompPlugin *p,
- CompScreen *s)
+ CompScreen *s)
{
PROMPT_SCREEN (s);
- UNWRAP (as, s, paintOutput);
+ UNWRAP (ps, s, paintOutput);
- free (as);
+ free (ps);
}
static Bool
promptInitDisplay (CompPlugin *p,
- CompDisplay *d)
+ CompDisplay *d)
{
- PromptDisplay *ad;
+ PromptDisplay *pd;
int index;
if (!checkPluginABI ("core", CORE_ABIVERSION))
@@ -300,19 +286,19 @@ promptInitDisplay (CompPlugin *p,
return FALSE;
}
- ad = malloc (sizeof (PromptDisplay));
- if (!ad)
+ pd = malloc (sizeof (PromptDisplay));
+ if (!pd)
return FALSE;
- ad->screenPrivateIndex = allocateScreenPrivateIndex (d);
- if (ad->screenPrivateIndex < 0)
+ pd->screenPrivateIndex = allocateScreenPrivateIndex (d);
+ if (pd->screenPrivateIndex < 0)
{
- free (ad);
+ free (pd);
return FALSE;
}
- d->base.privates[displayPrivateIndex].ptr = ad;
- ad->textFunc = d->base.privates[index].ptr;
+ d->base.privates[displayPrivateIndex].ptr = pd;
+ pd->textFunc = d->base.privates[index].ptr;
promptSetDisplayTextInitiate (d, promptDisplayText);
@@ -321,17 +307,20 @@ promptInitDisplay (CompPlugin *p,
static void
promptFiniDisplay (CompPlugin *p,
- CompDisplay *d)
+ CompDisplay *d)
{
PROMPT_DISPLAY (d);
- freeScreenPrivateIndex (d, ad->screenPrivateIndex);
- free (ad);
+ if (pd->removeTextHandle)
+ compRemoveTimeout (pd->removeTextHandle);
+
+ freeScreenPrivateIndex (d, pd->screenPrivateIndex);
+ free (pd);
}
static CompBool
promptInitObject (CompPlugin *p,
- CompObject *o)
+ CompObject *o)
{
static InitPluginObjectProc dispTab[] = {
(InitPluginObjectProc) 0,
@@ -344,7 +333,7 @@ promptInitObject (CompPlugin *p,
static void
promptFiniObject (CompPlugin *p,
- CompObject *o)
+ CompObject *o)
{
static FiniPluginObjectProc dispTab[] = {
(FiniPluginObjectProc) 0,