~ctwm/ctwm/trunk

« back to all changes in this revision

Viewing changes to menus.c

  • Committer: Matthew Fuller
  • Date: 2016-08-16 10:37:18 UTC
  • mfrom: (514.2.49 build)
  • Revision ID: fullermd@over-yonder.net-20160816103718-7ay3cpxxzlkaw1er
Implement a parallel minimal build system, which can at least yield a
runnable ctwm in situations where the cmake chain is unavailable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
#include <string.h>
75
75
#include <strings.h>
76
76
 
 
77
#include <X11/extensions/shape.h>
 
78
 
77
79
#include "ctwm_atoms.h"
 
80
#include "menus.h"
78
81
#include "resize.h"
79
82
#include "events.h"
80
83
#include "util.h"
81
84
#include "drawing.h"
82
 
#include "functions_defs.h"
83
 
#include "iconmgr.h"
84
85
#include "icons_builtin.h"
 
86
#include "parse.h"
85
87
#include "icons.h"
86
88
#include "add_window.h"
87
 
#include "colormaps.h"
 
89
#include "decorations.h"
88
90
#include "otp.h"
89
91
#include "image.h"
90
 
#include "list.h"
91
92
#include "functions.h"
92
93
#include "screen.h"
93
 
#include "occupation.h"
94
 
#include "vscreen.h"
95
 
#include "win_iconify.h"
96
 
#include "win_ops.h"
97
 
#include "win_utils.h"
98
94
#include "workspace_manager.h"
99
95
#include "workspace_utils.h"
100
96
#ifdef SOUNDS
120
116
static Cursor LastCursor;
121
117
static bool addingdefaults = false;
122
118
 
 
119
/*
 
120
 * Directionals for TryToPush_be().  These differ from the specs for
 
121
 * jump/pack/fill in functions. because there's an indeterminate option.
 
122
 */
 
123
typedef enum {
 
124
        PD_ANY,
 
125
        PD_BOTTOM,
 
126
        PD_LEFT,
 
127
        PD_RIGHT,
 
128
        PD_TOP,
 
129
} PushDirection;
123
130
 
124
131
 
125
132
static void Paint3DEntry(MenuRoot *mr, MenuItem *mi, bool exposure);
126
133
static void PaintNormalEntry(MenuRoot *mr, MenuItem *mi, bool exposure);
 
134
static void MosaicFade(TwmWindow *tmp_win, Window blanket);
127
135
static void DestroyMenu(MenuRoot *menu);
 
136
static void ZoomInWindow(TwmWindow *tmp_win, Window blanket);
 
137
static void ZoomOutWindow(TwmWindow *tmp_win, Window blanket);
 
138
static void FadeWindow(TwmWindow *tmp_win, Window blanket);
 
139
static void SweepWindow(TwmWindow *tmp_win, Window blanket);
 
140
static void waitamoment(float timeout);
 
141
static void TryToPush_be(TwmWindow *tmp_win, int x, int y, PushDirection dir);
128
142
 
129
143
 
130
144
#define SHADOWWIDTH 5                   /* in pixels */
1633
1647
/***********************************************************************
1634
1648
 *
1635
1649
 *  Procedure:
 
1650
 *      resizeFromCenter -
 
1651
 *
 
1652
 ***********************************************************************
 
1653
 */
 
1654
 
 
1655
void resizeFromCenter(Window w, TwmWindow *tmp_win)
 
1656
{
 
1657
        int lastx, lasty, bw2;
 
1658
 
 
1659
        bw2 = tmp_win->frame_bw * 2;
 
1660
        AddingW = tmp_win->attr.width + bw2 + 2 * tmp_win->frame_bw3D;
 
1661
        AddingH = tmp_win->attr.height + tmp_win->title_height + bw2 + 2 *
 
1662
                  tmp_win->frame_bw3D;
 
1663
 
 
1664
        XGetGeometry(dpy, w, &JunkRoot, &origDragX, &origDragY,
 
1665
                     &DragWidth, &DragHeight,
 
1666
                     &JunkBW, &JunkDepth);
 
1667
 
 
1668
        XWarpPointer(dpy, None, w,
 
1669
                     0, 0, 0, 0, DragWidth / 2, DragHeight / 2);
 
1670
        XQueryPointer(dpy, Scr->Root, &JunkRoot,
 
1671
                      &JunkChild, &JunkX, &JunkY,
 
1672
                      &AddingX, &AddingY, &JunkMask);
 
1673
 
 
1674
        lastx = -10000;
 
1675
        lasty = -10000;
 
1676
 
 
1677
        MenuStartResize(tmp_win, origDragX, origDragY, DragWidth, DragHeight);
 
1678
        while(1) {
 
1679
                XMaskEvent(dpy,
 
1680
                           ButtonPressMask | PointerMotionMask | ExposureMask, &Event);
 
1681
 
 
1682
                if(Event.type == MotionNotify) {
 
1683
                        /* discard any extra motion events before a release */
 
1684
                        while(XCheckMaskEvent(dpy,
 
1685
                                              ButtonMotionMask | ButtonPressMask, &Event))
 
1686
                                if(Event.type == ButtonPress) {
 
1687
                                        break;
 
1688
                                }
 
1689
                }
 
1690
 
 
1691
                if(Event.type == ButtonPress) {
 
1692
                        MenuEndResize(tmp_win);
 
1693
                        // Next line should be unneeded, done by MenuEndResize() ?
 
1694
                        XMoveResizeWindow(dpy, w, AddingX, AddingY, AddingW, AddingH);
 
1695
                        break;
 
1696
                }
 
1697
 
 
1698
                if(Event.type != MotionNotify) {
 
1699
                        DispatchEvent2();
 
1700
                        if(Cancel) {
 
1701
                                // ...
 
1702
                                MenuEndResize(tmp_win);
 
1703
                                return;
 
1704
                        }
 
1705
                        continue;
 
1706
                }
 
1707
 
 
1708
                /*
 
1709
                 * XXX - if we are going to do a loop, we ought to consider
 
1710
                 * using multiple GXxor lines so that we don't need to
 
1711
                 * grab the server.
 
1712
                 */
 
1713
                XQueryPointer(dpy, Scr->Root, &JunkRoot, &JunkChild,
 
1714
                              &JunkX, &JunkY, &AddingX, &AddingY, &JunkMask);
 
1715
 
 
1716
                if(lastx != AddingX || lasty != AddingY) {
 
1717
                        MenuDoResize(AddingX, AddingY, tmp_win);
 
1718
 
 
1719
                        lastx = AddingX;
 
1720
                        lasty = AddingY;
 
1721
                }
 
1722
 
 
1723
        }
 
1724
}
 
1725
 
 
1726
 
 
1727
 
 
1728
/***********************************************************************
 
1729
 *
 
1730
 *  Procedure:
1636
1731
 *      ReGrab - regrab the pointer with the LastCursor;
1637
1732
 *
1638
1733
 ***********************************************************************
1652
1747
}
1653
1748
 
1654
1749
 
 
1750
/***********************************************************************
 
1751
 *
 
1752
 *  Procedure:
 
1753
 *      FocusOnRoot - put input focus on the root window
 
1754
 *
 
1755
 ***********************************************************************
 
1756
 */
 
1757
 
 
1758
void FocusOnRoot(void)
 
1759
{
 
1760
        SetFocus(NULL, LastTimestamp());
 
1761
        InstallColormaps(0, &Scr->RootColormaps);
 
1762
        if(! Scr->ClickToFocus) {
 
1763
                Scr->FocusRoot = true;
 
1764
        }
 
1765
}
 
1766
 
 
1767
static void ReMapOne(TwmWindow *t, TwmWindow *leader)
 
1768
{
 
1769
        if(t->icon_on) {
 
1770
                Zoom(t->icon->w, t->frame);
 
1771
        }
 
1772
        else if(leader->icon) {
 
1773
                Zoom(leader->icon->w, t->frame);
 
1774
        }
 
1775
 
 
1776
        if(!t->squeezed) {
 
1777
                XMapWindow(dpy, t->w);
 
1778
        }
 
1779
        t->mapped = true;
 
1780
        if(False && Scr->Root != Scr->CaptiveRoot) {        /* XXX dubious test */
 
1781
                ReparentWindow(dpy, t, WinWin, Scr->Root, t->frame_x, t->frame_y);
 
1782
        }
 
1783
        if(!Scr->NoRaiseDeicon) {
 
1784
                OtpRaise(t, WinWin);
 
1785
        }
 
1786
        XMapWindow(dpy, t->frame);
 
1787
        SetMapStateProp(t, NormalState);
 
1788
 
 
1789
        if(t->icon && t->icon->w) {
 
1790
                XUnmapWindow(dpy, t->icon->w);
 
1791
                IconDown(t);
 
1792
                if(Scr->ShrinkIconTitles) {
 
1793
                        t->icon->title_shrunk = true;
 
1794
                }
 
1795
        }
 
1796
        if(t->iconmanagerlist) {
 
1797
                WList *wl;
 
1798
 
 
1799
                for(wl = t->iconmanagerlist; wl != NULL; wl = wl->nextv) {
 
1800
                        XUnmapWindow(dpy, wl->icon);
 
1801
                }
 
1802
        }
 
1803
        t->isicon = false;
 
1804
        t->icon_on = false;
 
1805
        WMapDeIconify(t);
 
1806
}
 
1807
 
 
1808
static void ReMapTransients(TwmWindow *tmp_win)
 
1809
{
 
1810
        TwmWindow *t;
 
1811
 
 
1812
        /* find t such that it is a transient or group member window */
 
1813
        for(t = Scr->FirstWindow; t != NULL; t = t->next) {
 
1814
                if(t != tmp_win &&
 
1815
                                ((t->istransient && t->transientfor == tmp_win->w) ||
 
1816
                                 (t->group == tmp_win->w && t->isicon))) {
 
1817
                        ReMapOne(t, tmp_win);
 
1818
                }
 
1819
        }
 
1820
}
 
1821
 
 
1822
void DeIconify(TwmWindow *tmp_win)
 
1823
{
 
1824
        TwmWindow *t = tmp_win;
 
1825
        bool isicon = false;
 
1826
 
 
1827
        /* de-iconify the main window */
 
1828
        if(Scr->WindowMask) {
 
1829
                XRaiseWindow(dpy, Scr->WindowMask);
 
1830
        }
 
1831
        if(tmp_win->isicon) {
 
1832
                isicon = true;
 
1833
                if(tmp_win->icon_on && tmp_win->icon && tmp_win->icon->w) {
 
1834
                        Zoom(tmp_win->icon->w, tmp_win->frame);
 
1835
                }
 
1836
                else if(tmp_win->group != (Window) 0) {
 
1837
                        t = GetTwmWindow(tmp_win->group);
 
1838
                        if(t && t->icon_on && t->icon && t->icon->w) {
 
1839
                                Zoom(t->icon->w, tmp_win->frame);
 
1840
                        }
 
1841
                }
 
1842
        }
 
1843
 
 
1844
        ReMapOne(tmp_win, t);
 
1845
 
 
1846
        if(isicon &&
 
1847
                        (Scr->WarpCursor ||
 
1848
                         LookInList(Scr->WarpCursorL, tmp_win->full_name, &tmp_win->class))) {
 
1849
                WarpToWindow(tmp_win, false);
 
1850
        }
 
1851
 
 
1852
        /* now de-iconify any window group transients */
 
1853
        ReMapTransients(tmp_win);
 
1854
 
 
1855
        if(! Scr->WindowMask && Scr->DeIconifyFunction.func != 0) {
 
1856
                char *action;
 
1857
                XEvent event;
 
1858
 
 
1859
                action = Scr->DeIconifyFunction.item ?
 
1860
                         Scr->DeIconifyFunction.item->action : NULL;
 
1861
                ExecuteFunction(Scr->DeIconifyFunction.func, action,
 
1862
                                (Window) 0, tmp_win, &event, C_ROOT, false);
 
1863
        }
 
1864
        XSync(dpy, 0);
 
1865
}
 
1866
 
 
1867
static void
 
1868
UnmapTransients(TwmWindow *tmp_win, bool iconify, long eventMask)
 
1869
{
 
1870
        TwmWindow *t;
 
1871
 
 
1872
        for(t = Scr->FirstWindow; t != NULL; t = t->next) {
 
1873
                if(t != tmp_win &&
 
1874
                                ((t->istransient && t->transientfor == tmp_win->w) ||
 
1875
                                 t->group == tmp_win->w)) {
 
1876
                        if(iconify) {
 
1877
                                if(t->icon_on) {
 
1878
                                        Zoom(t->icon->w, tmp_win->icon->w);
 
1879
                                }
 
1880
                                else if(tmp_win->icon) {
 
1881
                                        Zoom(t->frame, tmp_win->icon->w);
 
1882
                                }
 
1883
                        }
 
1884
 
 
1885
                        /*
 
1886
                         * Prevent the receipt of an UnmapNotify, since that would
 
1887
                         * cause a transition to the Withdrawn state.
 
1888
                         */
 
1889
                        t->mapped = false;
 
1890
 
 
1891
                        /*
 
1892
                         * Note that here, we're setting masks relative to what we
 
1893
                         * were passed, which is that of the window these are
 
1894
                         * transient for, rather than relative to these windows'
 
1895
                         * current masks.  I believe in practice it's the same thing,
 
1896
                         * and it saves getting attributes on each for masking.
 
1897
                         * Still, a little odd...
 
1898
                         */
 
1899
                        mask_out_event_mask(t->w, StructureNotifyMask, eventMask);
 
1900
                        XUnmapWindow(dpy, t->w);
 
1901
                        XUnmapWindow(dpy, t->frame);
 
1902
                        restore_mask(t->w, eventMask);
 
1903
 
 
1904
                        if(t->icon && t->icon->w) {
 
1905
                                XUnmapWindow(dpy, t->icon->w);
 
1906
                        }
 
1907
                        SetMapStateProp(t, IconicState);
 
1908
                        if(t == Scr->Focus) {
 
1909
                                SetFocus(NULL, LastTimestamp());
 
1910
                                if(! Scr->ClickToFocus) {
 
1911
                                        Scr->FocusRoot = true;
 
1912
                                }
 
1913
                        }
 
1914
                        if(t->iconmanagerlist) {
 
1915
                                XMapWindow(dpy, t->iconmanagerlist->icon);
 
1916
                        }
 
1917
                        t->isicon = true;
 
1918
                        t->icon_on = false;
 
1919
                        WMapIconify(t);
 
1920
                }
 
1921
        }
 
1922
}
 
1923
 
 
1924
void Iconify(TwmWindow *tmp_win, int def_x, int def_y)
 
1925
{
 
1926
        TwmWindow *t;
 
1927
        bool iconify;
 
1928
        long eventMask;
 
1929
        WList *wl;
 
1930
        Window leader = (Window) - 1;
 
1931
        Window blanket = (Window) - 1;
 
1932
 
 
1933
        iconify = (!tmp_win->iconify_by_unmapping);
 
1934
        t = NULL;
 
1935
        if(tmp_win->istransient) {
 
1936
                leader = tmp_win->transientfor;
 
1937
                t = GetTwmWindow(leader);
 
1938
        }
 
1939
        else if((leader = tmp_win->group) != 0 && leader != tmp_win->w) {
 
1940
                t = GetTwmWindow(leader);
 
1941
        }
 
1942
        if(t && t->icon_on) {
 
1943
                iconify = false;
 
1944
        }
 
1945
        if(iconify) {
 
1946
                if(!tmp_win->icon || !tmp_win->icon->w) {
 
1947
                        CreateIconWindow(tmp_win, def_x, def_y);
 
1948
                }
 
1949
                else {
 
1950
                        IconUp(tmp_win);
 
1951
                }
 
1952
                if(visible(tmp_win)) {
 
1953
                        if(Scr->WindowMask) {
 
1954
                                OtpRaise(tmp_win, IconWin);
 
1955
                                XMapWindow(dpy, tmp_win->icon->w);
 
1956
                        }
 
1957
                        else {
 
1958
                                OtpRaise(tmp_win, IconWin);
 
1959
                                XMapWindow(dpy, tmp_win->icon->w);
 
1960
                        }
 
1961
                }
 
1962
        }
 
1963
        if(tmp_win->iconmanagerlist) {
 
1964
                for(wl = tmp_win->iconmanagerlist; wl != NULL; wl = wl->nextv) {
 
1965
                        XMapWindow(dpy, wl->icon);
 
1966
                }
 
1967
        }
 
1968
 
 
1969
        /* Don't mask anything yet, just get the current for various uses */
 
1970
        eventMask = mask_out_event(tmp_win->w, 0);
 
1971
 
 
1972
        /* iconify transients and window group first */
 
1973
        UnmapTransients(tmp_win, iconify, eventMask);
 
1974
 
 
1975
        if(iconify) {
 
1976
                Zoom(tmp_win->frame, tmp_win->icon->w);
 
1977
        }
 
1978
 
 
1979
        /*
 
1980
         * Prevent the receipt of an UnmapNotify, since that would
 
1981
         * cause a transition to the Withdrawn state.
 
1982
         */
 
1983
        tmp_win->mapped = false;
 
1984
 
 
1985
        if((Scr->IconifyStyle != ICONIFY_NORMAL) && !Scr->WindowMask) {
 
1986
                XWindowAttributes winattrs;
 
1987
                XSetWindowAttributes attr;
 
1988
 
 
1989
                XGetWindowAttributes(dpy, tmp_win->frame, &winattrs);
 
1990
                attr.backing_store = NotUseful;
 
1991
                attr.save_under    = False;
 
1992
                blanket = XCreateWindow(dpy, Scr->Root, winattrs.x, winattrs.y,
 
1993
                                        winattrs.width, winattrs.height, 0,
 
1994
                                        CopyFromParent, CopyFromParent,
 
1995
                                        CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
 
1996
                XMapWindow(dpy, blanket);
 
1997
        }
 
1998
 
 
1999
        mask_out_event_mask(tmp_win->w, StructureNotifyMask, eventMask);
 
2000
        XUnmapWindow(dpy, tmp_win->w);
 
2001
        XUnmapWindow(dpy, tmp_win->frame);
 
2002
        restore_mask(tmp_win->w, eventMask);
 
2003
 
 
2004
        SetMapStateProp(tmp_win, IconicState);
 
2005
 
 
2006
        if((Scr->IconifyStyle != ICONIFY_NORMAL) && !Scr->WindowMask) {
 
2007
                switch(Scr->IconifyStyle) {
 
2008
                        case ICONIFY_MOSAIC:
 
2009
                                MosaicFade(tmp_win, blanket);
 
2010
                                break;
 
2011
                        case ICONIFY_ZOOMIN:
 
2012
                                ZoomInWindow(tmp_win, blanket);
 
2013
                                break;
 
2014
                        case ICONIFY_ZOOMOUT:
 
2015
                                ZoomOutWindow(tmp_win, blanket);
 
2016
                                break;
 
2017
                        case ICONIFY_FADE:
 
2018
                                FadeWindow(tmp_win, blanket);
 
2019
                                break;
 
2020
                        case ICONIFY_SWEEP:
 
2021
                                SweepWindow(tmp_win, blanket);
 
2022
                                break;
 
2023
                        case ICONIFY_NORMAL:
 
2024
                                /* Placate insufficiently smart clang warning */
 
2025
                                break;
 
2026
                }
 
2027
                XDestroyWindow(dpy, blanket);
 
2028
        }
 
2029
        if(tmp_win == Scr->Focus) {
 
2030
                SetFocus(NULL, LastTimestamp());
 
2031
                if(! Scr->ClickToFocus) {
 
2032
                        Scr->FocusRoot = true;
 
2033
                }
 
2034
        }
 
2035
        tmp_win->isicon = true;
 
2036
        tmp_win->icon_on = iconify;
 
2037
        WMapIconify(tmp_win);
 
2038
        if(! Scr->WindowMask && Scr->IconifyFunction.func != 0) {
 
2039
                char *action;
 
2040
                XEvent event;
 
2041
 
 
2042
                action = Scr->IconifyFunction.item ? Scr->IconifyFunction.item->action : NULL;
 
2043
                ExecuteFunction(Scr->IconifyFunction.func, action,
 
2044
                                (Window) 0, tmp_win, &event, C_ROOT, false);
 
2045
        }
 
2046
        XSync(dpy, 0);
 
2047
}
 
2048
 
 
2049
void AutoSqueeze(TwmWindow *tmp_win)
 
2050
{
 
2051
        if(tmp_win->isiconmgr) {
 
2052
                return;
 
2053
        }
 
2054
        if(Scr->RaiseWhenAutoUnSqueeze && tmp_win->squeezed) {
 
2055
                OtpRaise(tmp_win, WinWin);
 
2056
        }
 
2057
        Squeeze(tmp_win);
 
2058
}
 
2059
 
 
2060
void Squeeze(TwmWindow *tmp_win)
 
2061
{
 
2062
        long fx, fy, savex, savey;
 
2063
        int  neww, newh;
 
2064
        bool south;
 
2065
        int  grav = ((tmp_win->hints.flags & PWinGravity)
 
2066
                     ? tmp_win->hints.win_gravity : NorthWestGravity);
 
2067
        long eventMask;
 
2068
        if(tmp_win->squeezed) {
 
2069
                tmp_win->squeezed = False;
 
2070
#ifdef EWMH
 
2071
                EwmhSet_NET_WM_STATE(tmp_win, EWMH_STATE_SHADED);
 
2072
#endif /* EWMH */
 
2073
                if(!tmp_win->isicon) {
 
2074
                        XMapWindow(dpy, tmp_win->w);
 
2075
                }
 
2076
                SetupWindow(tmp_win, tmp_win->actual_frame_x, tmp_win->actual_frame_y,
 
2077
                            tmp_win->actual_frame_width, tmp_win->actual_frame_height, -1);
 
2078
                ReMapTransients(tmp_win);
 
2079
                return;
 
2080
        }
 
2081
 
 
2082
        newh = tmp_win->title_height + 2 * tmp_win->frame_bw3D;
 
2083
        if(newh < 3) {
 
2084
                XBell(dpy, 0);
 
2085
                return;
 
2086
        }
 
2087
        switch(grav) {
 
2088
                case SouthWestGravity :
 
2089
                case SouthGravity :
 
2090
                case SouthEastGravity :
 
2091
                        south = true;
 
2092
                        break;
 
2093
                default :
 
2094
                        south = false;
 
2095
                        break;
 
2096
        }
 
2097
        if(tmp_win->title_height && !tmp_win->AlwaysSqueezeToGravity) {
 
2098
                south = false;
 
2099
        }
 
2100
 
 
2101
        tmp_win->squeezed = true;
 
2102
        tmp_win->actual_frame_width  = tmp_win->frame_width;
 
2103
        tmp_win->actual_frame_height = tmp_win->frame_height;
 
2104
        savex = fx = tmp_win->frame_x;
 
2105
        savey = fy = tmp_win->frame_y;
 
2106
        neww  = tmp_win->actual_frame_width;
 
2107
        if(south) {
 
2108
                fy += tmp_win->frame_height - newh;
 
2109
        }
 
2110
        if(tmp_win->squeeze_info) {
 
2111
                fx  += tmp_win->title_x - tmp_win->frame_bw3D;
 
2112
                neww = tmp_win->title_width + 2 * (tmp_win->frame_bw + tmp_win->frame_bw3D);
 
2113
        }
 
2114
 
 
2115
        eventMask = mask_out_event(tmp_win->w, StructureNotifyMask);
 
2116
#ifdef EWMH
 
2117
        EwmhSet_NET_WM_STATE(tmp_win, EWMH_STATE_SHADED);
 
2118
#endif /* EWMH */
 
2119
        XUnmapWindow(dpy, tmp_win->w);
 
2120
        restore_mask(tmp_win->w, eventMask);
 
2121
 
 
2122
        if(fx + neww >= Scr->rootw - Scr->BorderRight) {
 
2123
                fx = Scr->rootw - Scr->BorderRight - neww;
 
2124
        }
 
2125
        if(fy + newh >= Scr->rooth - Scr->BorderBottom) {
 
2126
                fy = Scr->rooth - Scr->BorderBottom - newh;
 
2127
        }
 
2128
        SetupWindow(tmp_win, fx, fy, neww, newh, -1);
 
2129
        tmp_win->actual_frame_x = savex;
 
2130
        tmp_win->actual_frame_y = savey;
 
2131
 
 
2132
        /* Now make the group members disappear */
 
2133
        UnmapTransients(tmp_win, false, eventMask);
 
2134
}
 
2135
 
 
2136
/*
 
2137
 * Set WM_STATE; x-ref ICCCM section 4.1.3.1
 
2138
 * https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.3.1
 
2139
 */
 
2140
void SetMapStateProp(TwmWindow *tmp_win, int state)
 
2141
{
 
2142
        unsigned long data[2];              /* "suggested" by ICCCM version 1 */
 
2143
 
 
2144
        data[0] = (unsigned long) state;
 
2145
        data[1] = (unsigned long)(tmp_win->iconify_by_unmapping ? None :
 
2146
                                  (tmp_win->icon ? tmp_win->icon->w : None));
 
2147
 
 
2148
        XChangeProperty(dpy, tmp_win->w, XA_WM_STATE, XA_WM_STATE, 32,
 
2149
                        PropModeReplace, (unsigned char *) data, 2);
 
2150
}
 
2151
 
 
2152
 
 
2153
bool
 
2154
GetWMState(Window w, int *statep, Window *iwp)
 
2155
{
 
2156
        Atom actual_type;
 
2157
        int actual_format;
 
2158
        unsigned long nitems, bytesafter;
 
2159
        unsigned long *datap = NULL;
 
2160
        bool retval = false;
 
2161
 
 
2162
        if(XGetWindowProperty(dpy, w, XA_WM_STATE, 0L, 2L, False, XA_WM_STATE,
 
2163
                              &actual_type, &actual_format, &nitems, &bytesafter,
 
2164
                              (unsigned char **) &datap) != Success || !datap) {
 
2165
                return false;
 
2166
        }
 
2167
 
 
2168
        if(nitems <= 2) {                   /* "suggested" by ICCCM version 1 */
 
2169
                *statep = (int) datap[0];
 
2170
                *iwp = (Window) datap[1];
 
2171
                retval = true;
 
2172
        }
 
2173
 
 
2174
        XFree(datap);
 
2175
        return retval;
 
2176
}
 
2177
 
 
2178
 
1655
2179
int WarpToScreen(int n, int inc)
1656
2180
{
1657
2181
        Window dumwin;
1769
2293
                        p->ring.curs_x = ev->x_root - t->frame_x;
1770
2294
                        p->ring.curs_y = ev->y_root - t->frame_y;
1771
2295
#ifdef DEBUG
1772
 
                        /* XXX This is the Tmp_win [now] internal to the event code? */
1773
2296
                        fprintf(stderr,
1774
2297
                                "WarpAlongRing: cursor_valid := true; x := %d (%d-%d), y := %d (%d-%d)\n",
1775
2298
                                Tmp_win->ring.curs_x, ev->x_root, t->frame_x, Tmp_win->ring.curs_y, ev->y_root,
1862
2385
        }
1863
2386
 
1864
2387
        XWarpPointer(dpy, None, Scr->Root, 0, 0, 0, 0, x + t->frame_x, y + t->frame_y);
1865
 
        SetFocus(t, EventTime);
 
2388
        SetFocus(t, LastTimestamp());
1866
2389
 
1867
2390
#ifdef DEBUG
1868
2391
        {
2009
2532
        return;
2010
2533
}
2011
2534
 
 
2535
/***********************************************************************
 
2536
 *
 
2537
 *  Procedure:
 
2538
 *      DisplayPosition - display the position in the dimensions window
 
2539
 *
 
2540
 *  Inputs:
 
2541
 *      tmp_win - the current twm window
 
2542
 *      x, y    - position of the window
 
2543
 *
 
2544
 ***********************************************************************
 
2545
 */
 
2546
 
 
2547
void DisplayPosition(TwmWindow *tmp_win, int x, int y)
 
2548
{
 
2549
        char str [100];
 
2550
        char signx = '+';
 
2551
        char signy = '+';
 
2552
 
 
2553
        if(x < 0) {
 
2554
                x = -x;
 
2555
                signx = '-';
 
2556
        }
 
2557
        if(y < 0) {
 
2558
                y = -y;
 
2559
                signy = '-';
 
2560
        }
 
2561
        (void) sprintf(str, " %c%-4d %c%-4d ", signx, x, signy, y);
 
2562
        XRaiseWindow(dpy, Scr->SizeWindow);
 
2563
 
 
2564
        Draw3DBorder(Scr->SizeWindow, 0, 0,
 
2565
                     Scr->SizeStringOffset + Scr->SizeStringWidth + SIZE_HINDENT,
 
2566
                     Scr->SizeFont.height + SIZE_VINDENT * 2,
 
2567
                     2, Scr->DefaultC, off, false, false);
 
2568
 
 
2569
        FB(Scr->DefaultC.fore, Scr->DefaultC.back);
 
2570
        XmbDrawImageString(dpy, Scr->SizeWindow, Scr->SizeFont.font_set,
 
2571
                           Scr->NormalGC, Scr->SizeStringOffset,
 
2572
                           Scr->SizeFont.ascent + SIZE_VINDENT , str, 13);
 
2573
}
 
2574
 
 
2575
static void MosaicFade(TwmWindow *tmp_win, Window blanket)
 
2576
{
 
2577
        int         srect;
 
2578
        int         i, j, nrects;
 
2579
        Pixmap      mask;
 
2580
        GC          gc;
 
2581
        XGCValues   gcv;
 
2582
        XRectangle *rectangles;
 
2583
        int  width = tmp_win->frame_width;
 
2584
        int height = tmp_win->frame_height;
 
2585
 
 
2586
        srect = (width < height) ? (width / 20) : (height / 20);
 
2587
        mask  = XCreatePixmap(dpy, blanket, width, height, 1);
 
2588
 
 
2589
        gcv.foreground = 1;
 
2590
        gc = XCreateGC(dpy, mask, GCForeground, &gcv);
 
2591
        XFillRectangle(dpy, mask, gc, 0, 0, width, height);
 
2592
        gcv.function = GXclear;
 
2593
        XChangeGC(dpy, gc, GCFunction, &gcv);
 
2594
 
 
2595
        nrects = ((width * height) / (srect * srect)) / 10;
 
2596
        rectangles = calloc(nrects, sizeof(XRectangle));
 
2597
        for(j = 0; j < nrects; j++) {
 
2598
                rectangles [j].width  = srect;
 
2599
                rectangles [j].height = srect;
 
2600
        }
 
2601
        for(i = 0; i < 10; i++) {
 
2602
                for(j = 0; j < nrects; j++) {
 
2603
                        rectangles [j].x = ((lrand48() %  width) / srect) * srect;
 
2604
                        rectangles [j].y = ((lrand48() % height) / srect) * srect;
 
2605
                }
 
2606
                XFillRectangles(dpy, mask, gc, rectangles, nrects);
 
2607
                XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
 
2608
                XFlush(dpy);
 
2609
                waitamoment(0.020);
 
2610
        }
 
2611
        XFreePixmap(dpy, mask);
 
2612
        XFreeGC(dpy, gc);
 
2613
        free(rectangles);
 
2614
}
 
2615
 
 
2616
static void ZoomInWindow(TwmWindow *tmp_win, Window blanket)
 
2617
{
 
2618
        Pixmap        mask;
 
2619
        GC            gc, gcn;
 
2620
        XGCValues     gcv;
 
2621
 
 
2622
        int i, nsteps = 20;
 
2623
        int w = tmp_win->frame_width;
 
2624
        int h = tmp_win->frame_height;
 
2625
        int step = (MAX(w, h)) / (2.0 * nsteps);
 
2626
 
 
2627
        mask = XCreatePixmap(dpy, blanket, w, h, 1);
 
2628
        gcv.foreground = 1;
 
2629
        gc  = XCreateGC(dpy, mask, GCForeground, &gcv);
 
2630
        gcv.function = GXclear;
 
2631
        gcn = XCreateGC(dpy, mask, GCForeground | GCFunction, &gcv);
 
2632
 
 
2633
        for(i = 0; i < nsteps; i++) {
 
2634
                XFillRectangle(dpy, mask, gcn, 0, 0, w, h);
 
2635
                XFillArc(dpy, mask, gc, (w / 2) - ((nsteps - i) * step),
 
2636
                         (h / 2) - ((nsteps - i) * step),
 
2637
                         2 * (nsteps - i) * step,
 
2638
                         2 * (nsteps - i) * step,
 
2639
                         0, 360 * 64);
 
2640
                XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
 
2641
                XFlush(dpy);
 
2642
                waitamoment(0.020);
 
2643
        }
 
2644
}
 
2645
 
 
2646
static void ZoomOutWindow(TwmWindow *tmp_win, Window blanket)
 
2647
{
 
2648
        Pixmap        mask;
 
2649
        GC            gc;
 
2650
        XGCValues     gcv;
 
2651
 
 
2652
        int i, nsteps = 20;
 
2653
        int w = tmp_win->frame_width;
 
2654
        int h = tmp_win->frame_height;
 
2655
        int step = (MAX(w, h)) / (2.0 * nsteps);
 
2656
 
 
2657
        mask  = XCreatePixmap(dpy, blanket, w, h, 1);
 
2658
        gcv.foreground = 1;
 
2659
        gc = XCreateGC(dpy, mask, GCForeground, &gcv);
 
2660
        XFillRectangle(dpy, mask, gc, 0, 0, w, h);
 
2661
        gcv.function = GXclear;
 
2662
        XChangeGC(dpy, gc, GCFunction, &gcv);
 
2663
 
 
2664
        for(i = 0; i < nsteps; i++) {
 
2665
                XFillArc(dpy, mask, gc, (w / 2) - (i * step),
 
2666
                         (h / 2) - (i * step),
 
2667
                         2 * i * step,
 
2668
                         2 * i * step,
 
2669
                         0, 360 * 64);
 
2670
                XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
 
2671
                XFlush(dpy);
 
2672
                waitamoment(0.020);
 
2673
        }
 
2674
}
 
2675
 
 
2676
void FadeWindow(TwmWindow *tmp_win, Window blanket)
 
2677
{
 
2678
        Pixmap        mask, stipple;
 
2679
        GC            gc;
 
2680
        XGCValues     gcv;
 
2681
        static unsigned char stipple_bits[] = { 0x0F, 0x0F,
 
2682
                                                0xF0, 0xF0,
 
2683
                                                0x0F, 0x0F,
 
2684
                                                0xF0, 0xF0,
 
2685
                                                0x0F, 0x0F,
 
2686
                                                0xF0, 0xF0,
 
2687
                                                0x0F, 0x0F,
 
2688
                                                0xF0, 0xF0,
 
2689
                                              };
 
2690
        int w = tmp_win->frame_width;
 
2691
        int h = tmp_win->frame_height;
 
2692
 
 
2693
        stipple = XCreateBitmapFromData(dpy, blanket, (char *)stipple_bits, 8, 8);
 
2694
        mask    = XCreatePixmap(dpy, blanket, w, h, 1);
 
2695
        gcv.background = 0;
 
2696
        gcv.foreground = 1;
 
2697
        gcv.stipple    = stipple;
 
2698
        gcv.fill_style = FillOpaqueStippled;
 
2699
        gc = XCreateGC(dpy, mask, GCBackground | GCForeground | GCFillStyle | GCStipple,
 
2700
                       &gcv);
 
2701
        XFillRectangle(dpy, mask, gc, 0, 0, w, h);
 
2702
 
 
2703
        XShapeCombineMask(dpy, blanket, ShapeBounding, 0, 0, mask, ShapeSet);
 
2704
        XFlush(dpy);
 
2705
        waitamoment(0.10);
 
2706
        XFreePixmap(dpy, stipple);
 
2707
        XFlush(dpy);
 
2708
}
 
2709
 
 
2710
static void SweepWindow(TwmWindow *tmp_win, Window blanket)
 
2711
{
 
2712
        float step = 0.0;
 
2713
        int i, nsteps = 20;
 
2714
        int dir = 0, dist = tmp_win->frame_x, dist1;
 
2715
 
 
2716
        dist1 = tmp_win->frame_y;
 
2717
        if(dist1 < dist) {
 
2718
                dir = 1;
 
2719
                dist = dist1;
 
2720
        }
 
2721
        dist1 = tmp_win->vs->w - (tmp_win->frame_x + tmp_win->frame_width);
 
2722
        if(dist1 < dist) {
 
2723
                dir = 2;
 
2724
                dist = dist1;
 
2725
        }
 
2726
        dist1 = tmp_win->vs->h - (tmp_win->frame_y + tmp_win->frame_height);
 
2727
        if(dist1 < dist) {
 
2728
                dir = 3;
 
2729
                dist = dist1;
 
2730
        }
 
2731
 
 
2732
        switch(dir) {
 
2733
                case 0:
 
2734
                        step = tmp_win->frame_x + tmp_win->frame_width;
 
2735
                        break;
 
2736
                case 1:
 
2737
                        step = tmp_win->frame_y + tmp_win->frame_height;
 
2738
                        break;
 
2739
                case 2:
 
2740
                        step = tmp_win->vs->w - tmp_win->frame_x;
 
2741
                        break;
 
2742
                case 3:
 
2743
                        step = tmp_win->vs->h - tmp_win->frame_y;
 
2744
                        break;
 
2745
        }
 
2746
        step /= (float) nsteps;
 
2747
        step /= (float) nsteps;
 
2748
        for(i = 0; i < 20; i++) {
 
2749
                int x = tmp_win->frame_x;
 
2750
                int y = tmp_win->frame_y;
 
2751
                switch(dir) {
 
2752
                        case 0:
 
2753
                                x -= i * i * step;
 
2754
                                break;
 
2755
                        case 1:
 
2756
                                y -= i * i * step;
 
2757
                                break;
 
2758
                        case 2:
 
2759
                                x += i * i * step;
 
2760
                                break;
 
2761
                        case 3:
 
2762
                                y += i * i * step;
 
2763
                                break;
 
2764
                }
 
2765
                XMoveWindow(dpy, blanket, x, y);
 
2766
                XFlush(dpy);
 
2767
                waitamoment(0.020);
 
2768
        }
 
2769
}
 
2770
 
 
2771
static void waitamoment(float timeout)
 
2772
{
 
2773
        struct timeval timeoutstruct;
 
2774
        int usec = timeout * 1000000;
 
2775
        timeoutstruct.tv_usec = usec % (unsigned long) 1000000;
 
2776
        timeoutstruct.tv_sec  = usec / (unsigned long) 1000000;
 
2777
        select(0, NULL, NULL, NULL, &timeoutstruct);
 
2778
}
 
2779
 
 
2780
void TryToPack(TwmWindow *tmp_win, int *x, int *y)
 
2781
{
 
2782
        TwmWindow   *t;
 
2783
        int         newx, newy;
 
2784
        int         w, h;
 
2785
        int         winw = tmp_win->frame_width  + 2 * tmp_win->frame_bw;
 
2786
        int         winh = tmp_win->frame_height + 2 * tmp_win->frame_bw;
 
2787
 
 
2788
        newx = *x;
 
2789
        newy = *y;
 
2790
        for(t = Scr->FirstWindow; t != NULL; t = t->next) {
 
2791
                if(t == tmp_win) {
 
2792
                        continue;
 
2793
                }
 
2794
                if(t->winbox != tmp_win->winbox) {
 
2795
                        continue;
 
2796
                }
 
2797
                if(t->vs != tmp_win->vs) {
 
2798
                        continue;
 
2799
                }
 
2800
                if(!t->mapped) {
 
2801
                        continue;
 
2802
                }
 
2803
 
 
2804
                w = t->frame_width  + 2 * t->frame_bw;
 
2805
                h = t->frame_height + 2 * t->frame_bw;
 
2806
                if(newx >= t->frame_x + w) {
 
2807
                        continue;
 
2808
                }
 
2809
                if(newy >= t->frame_y + h) {
 
2810
                        continue;
 
2811
                }
 
2812
                if(newx + winw <= t->frame_x) {
 
2813
                        continue;
 
2814
                }
 
2815
                if(newy + winh <= t->frame_y) {
 
2816
                        continue;
 
2817
                }
 
2818
 
 
2819
                if(newx + Scr->MovePackResistance > t->frame_x + w) {  /* left */
 
2820
                        newx = MAX(newx, t->frame_x + w);
 
2821
                        continue;
 
2822
                }
 
2823
                if(newx + winw < t->frame_x + Scr->MovePackResistance) {  /* right */
 
2824
                        newx = MIN(newx, t->frame_x - winw);
 
2825
                        continue;
 
2826
                }
 
2827
                if(newy + Scr->MovePackResistance > t->frame_y + h) {  /* top */
 
2828
                        newy = MAX(newy, t->frame_y + h);
 
2829
                        continue;
 
2830
                }
 
2831
                if(newy + winh < t->frame_y + Scr->MovePackResistance) {  /* bottom */
 
2832
                        newy = MIN(newy, t->frame_y - winh);
 
2833
                        continue;
 
2834
                }
 
2835
        }
 
2836
        *x = newx;
 
2837
        *y = newy;
 
2838
}
 
2839
 
 
2840
 
 
2841
void
 
2842
TryToPush(TwmWindow *tmp_win, int x, int y)
 
2843
{
 
2844
        TryToPush_be(tmp_win, x, y, PD_ANY);
 
2845
}
 
2846
 
 
2847
static void
 
2848
TryToPush_be(TwmWindow *tmp_win, int x, int y, PushDirection dir)
 
2849
{
 
2850
        TwmWindow   *t;
 
2851
        int         newx, newy, ndir;
 
2852
        bool        move;
 
2853
        int         w, h;
 
2854
        int         winw = tmp_win->frame_width  + 2 * tmp_win->frame_bw;
 
2855
        int         winh = tmp_win->frame_height + 2 * tmp_win->frame_bw;
 
2856
 
 
2857
        for(t = Scr->FirstWindow; t != NULL; t = t->next) {
 
2858
                if(t == tmp_win) {
 
2859
                        continue;
 
2860
                }
 
2861
                if(t->winbox != tmp_win->winbox) {
 
2862
                        continue;
 
2863
                }
 
2864
                if(t->vs != tmp_win->vs) {
 
2865
                        continue;
 
2866
                }
 
2867
                if(!t->mapped) {
 
2868
                        continue;
 
2869
                }
 
2870
 
 
2871
                w = t->frame_width  + 2 * t->frame_bw;
 
2872
                h = t->frame_height + 2 * t->frame_bw;
 
2873
                if(x >= t->frame_x + w) {
 
2874
                        continue;
 
2875
                }
 
2876
                if(y >= t->frame_y + h) {
 
2877
                        continue;
 
2878
                }
 
2879
                if(x + winw <= t->frame_x) {
 
2880
                        continue;
 
2881
                }
 
2882
                if(y + winh <= t->frame_y) {
 
2883
                        continue;
 
2884
                }
 
2885
 
 
2886
                move = false;
 
2887
                if((dir == PD_ANY || dir == PD_LEFT) &&
 
2888
                                (x + Scr->MovePackResistance > t->frame_x + w)) {
 
2889
                        newx = x - w;
 
2890
                        newy = t->frame_y;
 
2891
                        ndir = PD_LEFT;
 
2892
                        move = true;
 
2893
                }
 
2894
                else if((dir == PD_ANY || dir == PD_RIGHT) &&
 
2895
                                (x + winw < t->frame_x + Scr->MovePackResistance)) {
 
2896
                        newx = x + winw;
 
2897
                        newy = t->frame_y;
 
2898
                        ndir = PD_RIGHT;
 
2899
                        move = true;
 
2900
                }
 
2901
                else if((dir == PD_ANY || dir == PD_TOP) &&
 
2902
                                (y + Scr->MovePackResistance > t->frame_y + h)) {
 
2903
                        newx = t->frame_x;
 
2904
                        newy = y - h;
 
2905
                        ndir = PD_TOP;
 
2906
                        move = true;
 
2907
                }
 
2908
                else if((dir == PD_ANY || dir == PD_BOTTOM) &&
 
2909
                                (y + winh < t->frame_y + Scr->MovePackResistance)) {
 
2910
                        newx = t->frame_x;
 
2911
                        newy = y + winh;
 
2912
                        ndir = PD_BOTTOM;
 
2913
                        move = true;
 
2914
                }
 
2915
                if(move) {
 
2916
                        TryToPush_be(t, newx, newy, ndir);
 
2917
                        TryToPack(t, &newx, &newy);
 
2918
                        ConstrainByBorders(tmp_win,
 
2919
                                           &newx, t->frame_width  + 2 * t->frame_bw,
 
2920
                                           &newy, t->frame_height + 2 * t->frame_bw);
 
2921
                        SetupWindow(t, newx, newy, t->frame_width, t->frame_height, -1);
 
2922
                }
 
2923
        }
 
2924
}
 
2925
 
 
2926
 
 
2927
void TryToGrid(TwmWindow *tmp_win, int *x, int *y)
 
2928
{
 
2929
        int w    = tmp_win->frame_width  + 2 * tmp_win->frame_bw;
 
2930
        int h    = tmp_win->frame_height + 2 * tmp_win->frame_bw;
 
2931
        int grav = ((tmp_win->hints.flags & PWinGravity)
 
2932
                    ? tmp_win->hints.win_gravity : NorthWestGravity);
 
2933
 
 
2934
        switch(grav) {
 
2935
                case ForgetGravity :
 
2936
                case StaticGravity :
 
2937
                case NorthWestGravity :
 
2938
                case NorthGravity :
 
2939
                case WestGravity :
 
2940
                case CenterGravity :
 
2941
                        *x = ((*x - Scr->BorderLeft) / Scr->XMoveGrid) * Scr->XMoveGrid
 
2942
                             + Scr->BorderLeft;
 
2943
                        *y = ((*y - Scr->BorderTop) / Scr->YMoveGrid) * Scr->YMoveGrid
 
2944
                             + Scr->BorderTop;
 
2945
                        break;
 
2946
                case NorthEastGravity :
 
2947
                case EastGravity :
 
2948
                        *x = (((*x + w - Scr->BorderLeft) / Scr->XMoveGrid) *
 
2949
                              Scr->XMoveGrid) - w + Scr->BorderLeft;
 
2950
                        *y = ((*y - Scr->BorderTop) / Scr->YMoveGrid) *
 
2951
                             Scr->YMoveGrid + Scr->BorderTop;
 
2952
                        break;
 
2953
                case SouthWestGravity :
 
2954
                case SouthGravity :
 
2955
                        *x = ((*x - Scr->BorderLeft) / Scr->XMoveGrid) * Scr->XMoveGrid
 
2956
                             + Scr->BorderLeft;
 
2957
                        *y = (((*y + h - Scr->BorderTop) / Scr->YMoveGrid) * Scr->YMoveGrid)
 
2958
                             - h + Scr->BorderTop;
 
2959
                        break;
 
2960
                case SouthEastGravity :
 
2961
                        *x = (((*x + w - Scr->BorderLeft) / Scr->XMoveGrid) *
 
2962
                              Scr->XMoveGrid) - w + Scr->BorderLeft;
 
2963
                        *y = (((*y + h - Scr->BorderTop) / Scr->YMoveGrid) *
 
2964
                              Scr->YMoveGrid) - h + Scr->BorderTop;
 
2965
                        break;
 
2966
        }
 
2967
}
2012
2968
 
2013
2969
void WarpCursorToDefaultEntry(MenuRoot *menu)
2014
2970
{