~ctwm/ctwm/trunk

« back to all changes in this revision

Viewing changes to functions.c

  • Committer: Matthew Fuller
  • Date: 2016-09-27 10:33:11 UTC
  • mfrom: (525.1.16 cleanups)
  • Revision ID: fullermd@over-yonder.net-20160927103311-c3j8dmmr0oazxu3h
Some cleanups on function-handling code.  More in progress.

Harmonize the #define's with the function names they correspond to.
Bunch of comments, including some outstanding questions.  A few minor
non-functional code rearrangements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include "functions.h"
45
45
 
46
46
 
 
47
/*
 
48
 * Various functions can be executed "from the root" (which generally
 
49
 * means "from a menu"), but apply to a specific window (e.g., f.move,
 
50
 * f.identify, etc).  You obviously can't be selecting it from a menu and
 
51
 * pointing at the window to target at the same time, so we have to
 
52
 * 2-step those calls.  This happens via the DeferExecution() call in the
 
53
 * implementations of those functions, which stashes the "in progress"
 
54
 * function in RootFunction.  The HandleButtonPress() event handler will
 
55
 * later notice that and loop events back around into ExecuteFunction()
 
56
 * again to pick up where it left off.
 
57
 *
 
58
 * (a more descriptive name might be in order)
 
59
 */
47
60
int RootFunction = 0;
48
 
int MoveFunction;  /* either F_MOVE or F_FORCEMOVE */
 
61
 
 
62
/*
 
63
 * Which move-ish function is in progress.  This is _almost_ really a
 
64
 * local var in the movewindow() function, but we also reference it in
 
65
 * the HandleButtonRelease() event handler because that has to know
 
66
 * which move variant we're doing to figure out whether it has to
 
67
 * constrain the final coordinates in various ways.
 
68
 */
 
69
int MoveFunction;
49
70
 
50
71
/* Building the f.identify window.  The events code grubs in these. */
51
72
#define INFO_LINES 30
146
167
                return true;        /* XXX should this be false? */
147
168
        }
148
169
 
 
170
        /*
 
171
         * For most functions with a few exceptions, grab the pointer.
 
172
         *
 
173
         * XXX big XXX.  I have no idea why.  Apart from adding 1 or 2
 
174
         * functions to the exclusion list, this code comes verbatim from
 
175
         * twm, which has no history or documentation as to why it's
 
176
         * happening.
 
177
         *
 
178
         * My best guess is that this is being done solely to set the cursor?
 
179
         * X-ref the comment on the Ungrab() at the end of the function.
 
180
         */
149
181
        switch(func) {
150
182
                case F_UPICONMGR:
151
183
                case F_LEFTICONMGR:
218
250
                        JumpIconManager(func);
219
251
                        break;
220
252
 
221
 
                case F_SHOWLIST:
 
253
                case F_SHOWICONMGR:
222
254
                        if(Scr->NoIconManagers) {
223
255
                                break;
224
256
                        }
241
273
                        ModifyAnimationSpeed(-1);
242
274
                        break;
243
275
 
244
 
                case F_HIDELIST:
 
276
                case F_HIDEICONMGR:
245
277
                        if(Scr->NoIconManagers) {
246
278
                                break;
247
279
                        }
248
280
                        HideIconManager();
249
281
                        break;
250
282
 
251
 
                case F_SHOWWORKMGR:
 
283
                case F_SHOWWORKSPACEMGR:
252
284
                        if(! Scr->workSpaceManagerActive) {
253
285
                                break;
254
286
                        }
256
288
                        OtpRaise(Scr->currentvs->wsw->twm_win, WinWin);
257
289
                        break;
258
290
 
259
 
                case F_HIDEWORKMGR:
 
291
                case F_HIDEWORKSPACEMGR:
260
292
                        if(! Scr->workSpaceManagerActive) {
261
293
                                break;
262
294
                        }
264
296
                                eventp->xbutton.y_root - 5);
265
297
                        break;
266
298
 
267
 
                case F_TOGGLEWORKMGR:
 
299
                case F_TOGGLEWORKSPACEMGR:
268
300
                        if(! Scr->workSpaceManagerActive) {
269
301
                                break;
270
302
                        }
612
644
                        break;
613
645
 
614
646
                case F_POPUP:
 
647
                        /*
 
648
                         * This is a synthetic function; it exists only to be called
 
649
                         * internally from the various magic menus like TwmWindows
 
650
                         * etc.
 
651
                         */
615
652
                        tmp_win = (TwmWindow *)action;
616
653
                        if(! tmp_win) {
617
654
                                break;
628
665
                        break;
629
666
 
630
667
                case F_WINWARP:
 
668
                        /* Synthetic function; x-ref comment on F_POPUP */
631
669
                        tmp_win = (TwmWindow *)action;
632
670
 
633
671
                        if(! tmp_win) {
716
754
                        break;
717
755
 
718
756
 
719
 
                case F_VERTZOOM:
 
757
                case F_ZOOM:
720
758
                case F_HORIZOOM:
721
759
                case F_FULLZOOM:
722
760
                case F_FULLSCREENZOOM:
1212
1250
                        }
1213
1251
                        break;
1214
1252
 
1215
 
                case F_SHOWBGRD:
 
1253
                case F_SHOWBACKGROUND:
1216
1254
                        ShowBackground(Scr->currentvs, -1);
1217
1255
                        break;
1218
1256
 
1763
1801
                        Done(0);
1764
1802
                        break;
1765
1803
 
1766
 
                case F_RESCUE_WINDOWS:
 
1804
                case F_RESCUEWINDOWS:
1767
1805
                        RescueWindows();
1768
1806
                        break;
1769
1807
 
1770
1808
        }
1771
1809
 
 
1810
 
 
1811
        /*
 
1812
         * Ungrab the pointer.  Sometimes.  This condition apparently means
 
1813
         * we got to the end of the execution (didn't return early due to
 
1814
         * e.g. a Defer), and didn't come in as a result of pressing a mouse
 
1815
         * button.  Note that this is _not_ strictly dual to the
 
1816
         * XGrabPointer() conditionally called in the switch() early on;
 
1817
         * there will be plenty of cases where one executes without the
 
1818
         * other.
 
1819
         *
 
1820
         * XXX It isn't clear that this really belong here...
 
1821
         */
1772
1822
        if(ButtonPressed == -1) {
1773
1823
                XUngrabPointer(dpy, CurrentTime);
1774
1824
        }
 
1825
 
1775
1826
        return do_next_action;
1776
1827
}
1777
1828
 
1860
1911
}
1861
1912
 
1862
1913
 
 
1914
/*
 
1915
 * f.showiconmanager
 
1916
 */
1863
1917
static void
1864
1918
ShowIconManager(void)
1865
1919
{
1866
1920
        IconMgr   *i;
1867
1921
        WorkSpace *wl;
1868
1922
 
 
1923
        /*
 
1924
         * XXX I don't think this is right; there can still be icon managers
 
1925
         * to show even if we've never set any Workspaces {}.  And
 
1926
         * HideIconManager() doesn't have this extra condition either...
 
1927
         */
1869
1928
        if(! Scr->workSpaceManagerActive) {
1870
1929
                return;
1871
1930
        }
1873
1932
        if(Scr->NoIconManagers) {
1874
1933
                return;
1875
1934
        }
 
1935
 
1876
1936
        for(wl = Scr->workSpaceMgr.workSpaceList; wl != NULL; wl = wl->next) {
1877
1937
                for(i = wl->iconmgr; i != NULL; i = i->next) {
 
1938
                        /* Don't show iconmgr's with nothing in 'em */
1878
1939
                        if(i->count == 0) {
1879
1940
                                continue;
1880
1941
                        }
 
1942
 
 
1943
                        /* If it oughta be in a vscreen, show it */
1881
1944
                        if(visible(i->twm_win)) {
 
1945
                                /* IM window */
1882
1946
                                SetMapStateProp(i->twm_win, NormalState);
1883
1947
                                XMapWindow(dpy, i->twm_win->w);
1884
1948
                                OtpRaise(i->twm_win, WinWin);
1885
1949
                                XMapWindow(dpy, i->twm_win->frame);
 
1950
 
 
1951
                                /* Hide icon */
1886
1952
                                if(i->twm_win->icon && i->twm_win->icon->w) {
1887
1953
                                        XUnmapWindow(dpy, i->twm_win->icon->w);
1888
1954
                                }
1889
1955
                        }
 
1956
 
 
1957
                        /* Mark as shown */
1890
1958
                        i->twm_win->mapped = true;
1891
1959
                        i->twm_win->isicon = false;
1892
1960
                }
1894
1962
}
1895
1963
 
1896
1964
 
 
1965
/*
 
1966
 * f.hideiconmanager.  Also called when you f.delete an icon manager.
 
1967
 *
 
1968
 * This hides all the icon managers in all the workspaces, and it doesn't
 
1969
 * leave icons behind, so it's _not_ the same as just iconifying, and
 
1970
 * thus not implemented by just calling Iconify(), but by doing the
 
1971
 * hiding manually.
 
1972
 */
1897
1973
static void
1898
1974
HideIconManager(void)
1899
1975
{
1903
1979
        if(Scr->NoIconManagers) {
1904
1980
                return;
1905
1981
        }
 
1982
 
1906
1983
        for(wl = Scr->workSpaceMgr.workSpaceList; wl != NULL; wl = wl->next) {
1907
1984
                for(i = wl->iconmgr; i != NULL; i = i->next) {
 
1985
                        /* Hide the IM window */
1908
1986
                        SetMapStateProp(i->twm_win, WithdrawnState);
1909
1987
                        XUnmapWindow(dpy, i->twm_win->frame);
 
1988
 
 
1989
                        /* Hide its icon */
1910
1990
                        if(i->twm_win->icon && i->twm_win->icon->w) {
1911
1991
                                XUnmapWindow(dpy, i->twm_win->icon->w);
1912
1992
                        }
 
1993
 
 
1994
                        /* Mark as pretend-iconified, even though the icon is hidden */
1913
1995
                        i->twm_win->mapped = false;
1914
1996
                        i->twm_win->isicon = true;
1915
1997
                }
1917
1999
}
1918
2000
 
1919
2001
 
1920
 
/***********************************************************************
1921
 
 *
1922
 
 *  Procedure:
1923
 
 *      DeferExecution - defer the execution of a function to the
1924
 
 *          next button press if the context is C_ROOT
 
2002
/*
 
2003
 * Check to see if a function (implicitly, a window-targetting function)
 
2004
 * is happening in a context away from an actual window, and if so stash
 
2005
 * up info about what's in progress and return true to tell the caller to
 
2006
 * end processing the function (for now).  X-ref comment on RootFunction
 
2007
 * variable definition for details.
1925
2008
 *
1926
2009
 *  Inputs:
1927
2010
 *      context - the context in which the mouse button was pressed
1928
2011
 *      func    - the function to defer
1929
2012
 *      cursor  - the cursor to display while waiting
1930
 
 *
1931
 
 ***********************************************************************
1932
2013
 */
1933
 
 
1934
2014
static bool
1935
2015
DeferExecution(int context, int func, Cursor cursor)
1936
2016
{
2165
2245
draw_info_window(void)
2166
2246
{
2167
2247
        int i;
2168
 
        int height;
 
2248
        const int height = Scr->DefaultFont.height + 2;
2169
2249
 
2170
2250
        Draw3DBorder(Scr->InfoWindow.win, 0, 0,
2171
2251
                     Scr->InfoWindow.width, Scr->InfoWindow.height,
2173
2253
 
2174
2254
        FB(Scr->DefaultC.fore, Scr->DefaultC.back);
2175
2255
 
2176
 
        height = Scr->DefaultFont.height + 2;
2177
2256
        for(i = 0; i < Scr->InfoWindow.lines ; i++) {
2178
2257
                XmbDrawString(dpy, Scr->InfoWindow.win, Scr->DefaultFont.font_set,
2179
2258
                              Scr->NormalGC, 5,
2183
2262
}
2184
2263
 
2185
2264
 
 
2265
/*
 
2266
 * Is Window w part of the conglomerate of metawindows we put around the
 
2267
 * real window for TwmWindow t?  Note that this does _not_ check if w is
 
2268
 * the actual window we built the TwmWindow t around.
 
2269
 */
2186
2270
static bool
2187
2271
belongs_to_twm_window(TwmWindow *t, Window w)
2188
2272
{
 
2273
        /* Safety */
2189
2274
        if(!t) {
2190
2275
                return false;
2191
2276
        }
2192
2277
 
2193
 
        if(w == t->frame || w == t->title_w || w == t->hilite_wl || w == t->hilite_wr ||
2194
 
                        (t->icon && (w == t->icon->w || w == t->icon->bm_w))) {
2195
 
                return true;
2196
 
        }
2197
 
 
2198
 
        if(t && t->titlebuttons) {
 
2278
        /* Part of the framing we put around the window? */
 
2279
        if(w == t->frame || w == t->title_w
 
2280
                        || w == t->hilite_wl || w == t->hilite_wr) {
 
2281
                return true;
 
2282
        }
 
2283
 
 
2284
        /* Part of the icon bits? */
 
2285
        if(t->icon && (w == t->icon->w || w == t->icon->bm_w)) {
 
2286
                return true;
 
2287
        }
 
2288
 
 
2289
        /* One of the title button windows? */
 
2290
        if(t->titlebuttons) {
2199
2291
                TBWindow *tbw;
2200
2292
                int nb = Scr->TBInfo.nleft + Scr->TBInfo.nright;
2201
 
                for(tbw = t->titlebuttons; nb > 0; tbw++, nb--) {
 
2293
                for(tbw = t->titlebuttons ; nb > 0 ; tbw++, nb--) {
2202
2294
                        if(tbw->window == w) {
2203
2295
                                return true;
2204
2296
                        }
2205
2297
                }
2206
2298
        }
 
2299
 
 
2300
        /* Then no */
2207
2301
        return false;
2208
2302
}
2209
2303
 
2273
2367
        int cons, newx, newy, save;
2274
2368
        unsigned int neww, newh;
2275
2369
        int i;
2276
 
        int winx = tmp_win->frame_x;
2277
 
        int winy = tmp_win->frame_y;
2278
 
        int winw = tmp_win->frame_width  + 2 * tmp_win->frame_bw;
2279
 
        int winh = tmp_win->frame_height + 2 * tmp_win->frame_bw;
 
2370
        const int winx = tmp_win->frame_x;
 
2371
        const int winy = tmp_win->frame_y;
 
2372
        const int winw = tmp_win->frame_width  + 2 * tmp_win->frame_bw;
 
2373
        const int winh = tmp_win->frame_height + 2 * tmp_win->frame_bw;
2280
2374
 
2281
2375
        if(!strcmp(direction, "left")) {
2282
2376
                cons = FindConstraint(tmp_win, MFD_LEFT);
2373
2467
                                newy = tmp_win->save_frame_y +
2374
2468
                                       tmp_win->save_frame_height - newh;
2375
2469
                        }
2376
 
                        tmp_win->zoomed = F_VERTZOOM;
 
2470
                        tmp_win->zoomed = F_ZOOM;
2377
2471
                        SetupWindow(tmp_win, newx, newy, neww, newh, -1);
2378
2472
                }
2379
2473
                else {
2874
2968
}
2875
2969
 
2876
2970
 
2877
 
/***********************************************************************
2878
 
 *
2879
 
 *  Procedure:
2880
 
 *      NeedToDefer - checks each function in the list to see if it
2881
 
 *              is one that needs to be defered.
2882
 
 *
2883
 
 *  Inputs:
2884
 
 *      root    - the menu root to check
2885
 
 *
2886
 
 ***********************************************************************
 
2971
/*
 
2972
 * Checks each function in the list to see if it is one that needs to be
 
2973
 * defered.  Only currently called during handling of "f.function"
 
2974
 * handling; direct calls to funcs that need to be deferred already have
 
2975
 * DeferExecution() calls hardcoded in their handling.
 
2976
 *
 
2977
 * XXX Should that be?  Maybe we should better harmonize the cases.
 
2978
 *
 
2979
 * XXX I'm not sure this list is actually up to date.  Check.
2887
2980
 */
2888
2981
static bool
2889
2982
NeedToDefer(MenuRoot *root)
2904
2997
                        case F_FOCUS:
2905
2998
                        case F_DESTROY:
2906
2999
                        case F_WINREFRESH:
2907
 
                        case F_VERTZOOM:
 
3000
                        case F_ZOOM:
2908
3001
                        case F_FULLZOOM:
2909
3002
                        case F_FULLSCREENZOOM:
2910
3003
                        case F_HORIZOOM:
3103
3196
FindConstraint(TwmWindow *tmp_win, MoveFillDir direction)
3104
3197
{
3105
3198
        TwmWindow  *t;
3106
 
        int winx = tmp_win->frame_x;
3107
 
        int winy = tmp_win->frame_y;
3108
 
        int winw = tmp_win->frame_width  + 2 * tmp_win->frame_bw;
3109
 
        int winh = tmp_win->frame_height + 2 * tmp_win->frame_bw;
3110
3199
        int ret;
 
3200
        const int winx = tmp_win->frame_x;
 
3201
        const int winy = tmp_win->frame_y;
 
3202
        const int winw = tmp_win->frame_width  + 2 * tmp_win->frame_bw;
 
3203
        const int winh = tmp_win->frame_height + 2 * tmp_win->frame_bw;
3111
3204
 
3112
3205
        switch(direction) {
3113
3206
                case MFD_LEFT:
3138
3231
                        return -1;
3139
3232
        }
3140
3233
        for(t = Scr->FirstWindow; t != NULL; t = t->next) {
3141
 
                int w, h;
 
3234
                const int w = t->frame_width  + 2 * t->frame_bw;
 
3235
                const int h = t->frame_height + 2 * t->frame_bw;
3142
3236
 
3143
3237
                if(t == tmp_win) {
3144
3238
                        continue;
3149
3243
                if(!t->mapped) {
3150
3244
                        continue;
3151
3245
                }
3152
 
                w = t->frame_width  + 2 * t->frame_bw;
3153
 
                h = t->frame_height + 2 * t->frame_bw;
3154
3246
 
3155
3247
                switch(direction) {
3156
3248
                        case MFD_LEFT: