chiark / gitweb /
Imported Debian patch 1.0.0-5
[e16] / src / startup.c
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3  * Copyright (C) 2004-2009 Kim Woelders
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies of the Software, its documentation and marketing & publicity
14  * materials, and acknowledgment shall be given in the documentation, materials
15  * and software packages that this Software was used.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #include "E.h"
25 #include "backgrounds.h"
26 #include "eobj.h"
27 #include "iclass.h"
28 #include "timers.h"
29 #include "xwin.h"
30
31 static EObj        *init_win1 = NULL;
32 static EObj        *init_win2 = NULL;
33 static char         bg_sideways = 0;
34
35 void
36 StartupWindowsCreate(void)
37 {
38    Win                 w1, w2, win1, win2, b1, b2;
39    Background         *bg;
40    ImageClass         *ic;
41    int                 x, y, bx, by, bw, bh;
42    EObj               *eo;
43
44    /* Acting only as boolean? */
45    if (BackgroundFind("STARTUP_BACKGROUND_SIDEWAYS"))
46       bg_sideways = 1;
47
48    ic = ImageclassFind("STARTUP_BAR", 0);
49    if (!ic)
50       ic = ImageclassFind("DESKTOP_DRAGBUTTON_HORIZ", 0);
51    bg = BackgroundFind("STARTUP_BACKGROUND");
52    if (!ic || !bg)
53       return;
54
55    if (bg_sideways)
56      {
57         x = WinGetW(VROOT) / 2;
58         y = 0;
59         bx = WinGetW(VROOT) - Conf.desks.dragbar_width;
60         by = 0;
61         bw = Conf.desks.dragbar_width;
62         bh = WinGetH(VROOT);
63      }
64    else
65      {
66         x = 0;
67         y = WinGetH(VROOT) / 2;
68         bx = 0;
69         by = WinGetH(VROOT) - Conf.desks.dragbar_width;
70         bw = WinGetW(VROOT);
71         bh = Conf.desks.dragbar_width;
72      }
73
74    eo = EobjWindowCreate(EOBJ_TYPE_MISC,
75                          -x, -y, WinGetW(VROOT), WinGetH(VROOT), 1, "Init-1");
76    if (!eo)
77       return;
78    init_win1 = eo;
79    w1 = EobjGetWin(eo);
80    win1 = ECreateWindow(w1, x, y, WinGetW(VROOT), WinGetH(VROOT), 0);
81
82    eo = EobjWindowCreate(EOBJ_TYPE_MISC,
83                          x, y, WinGetW(VROOT), WinGetH(VROOT), 1, "Init-2");
84    if (!eo)
85       return;
86    init_win2 = eo;
87    w2 = EobjGetWin(eo);
88    win2 = ECreateWindow(w2, -x, -y, WinGetW(VROOT), WinGetH(VROOT), 0);
89
90    EMapWindow(win1);
91    EMapWindow(win2);
92
93    if (bw > 0 && bh > 0)
94      {
95         b1 = ECreateWindow(w1, bx, by, bw, bh, 0);
96         b2 = ECreateWindow(w2, 0, 0, bw, bh, 0);
97         EMapRaised(b1);
98         EMapRaised(b2);
99
100         ImageclassApply(ic, b1, 0, 0, 0, ST_SOLID);
101         ImageclassApply(ic, b2, 0, 0, 0, ST_SOLID);
102      }
103
104    BackgroundSet(bg, win1, WinGetW(VROOT), WinGetH(VROOT));
105    BackgroundSet(bg, win2, WinGetW(VROOT), WinGetH(VROOT));
106    StartupBackgroundsDestroy();
107
108    EobjMap(init_win1, 0);
109    EobjMap(init_win2, 0);
110
111    EobjsRepaint();
112 }
113
114 void
115 StartupBackgroundsDestroy(void)
116 {
117    BackgroundDestroyByName("STARTUP_BACKGROUND");
118    BackgroundDestroyByName("STARTUP_BACKGROUND_SIDEWAYS");
119 }
120
121 static int
122 doStartupWindowsOpen(void *data __UNUSED__)
123 {
124    static int          kk = 0;
125    int                 k, x, y, xOffset, yOffset, ty;
126
127    k = kk;
128
129    if (bg_sideways)
130      {                          /* so we can have two different slide methods */
131         ty = (WinGetW(VROOT) / 2);
132         xOffset = (ty * k) >> 10;
133         x = ty;
134         yOffset = 0;
135         y = 0;
136      }
137    else
138      {
139         ty = (WinGetH(VROOT) / 2);
140         xOffset = 0;
141         x = 0;
142         yOffset = (ty * k) >> 10;
143         y = ty;
144      }
145
146    EobjMove(init_win1, -x - xOffset, -y - yOffset);
147    EobjMove(init_win2, x + xOffset, y + yOffset);
148
149    k = (int)(1e-3 * Conf.animation.step * Conf.desks.slidespeed / 2);
150    if (k <= 0)
151       k = 1;
152    kk += k;
153    if (kk < 1024)
154       return 1;
155
156    Mode.place.enable_features++;
157    EobjWindowDestroy(init_win1);
158    EobjWindowDestroy(init_win2);
159    init_win1 = NULL;
160    init_win2 = NULL;
161
162    return 0;
163 }
164
165 void
166 StartupWindowsOpen(void)
167 {
168    if (init_win1 == NULL || init_win2 == NULL)
169       return;
170
171    Mode.place.enable_features--;
172    ESync(ESYNC_STARTUP);
173    AnimatorAdd(doStartupWindowsOpen, NULL);
174 }