Convert menus.c to C++ menus.cc

This commit is contained in:
Mike Small 2021-01-31 12:39:10 -05:00
parent 86161c72c5
commit 893bdb5928
17 changed files with 419 additions and 408 deletions

View File

@ -1,3 +1,25 @@
2021-01-31 Mike Small <smallm@sdf.org>
* src/util.h: move CreateMenuIcon prototype here
* src/add_window.h: C++ compatibility (extern "C")
* src/events.h: ditto
* src/resize.h: ditto
* src/twm.h: ditto and move or remove some functions
* src/twm.c (InitVariables): remove use of CaseSensitive variable
* src/screen.h (ScreenInfo): remove CaseSensitive variable
* src/menus.h: C++ compatibility (extern "C"), move GetWMState here
* src/menus.cc: convert to C++ (beginning, enough to build)
* src/Makefile.am (AM_CXXFLAGS): remove -Wno-logical-op-parenthesis
2019-10-21 Mike Small <smallm@sdf.org>
* src/icons.h: Remove IconUp and IconDown from icons interface

View File

@ -346,6 +346,7 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -295,6 +295,7 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -32,7 +32,7 @@ AM_CPPFLAGS = \
AM_CFLAGS = -Werror $(TWM_CFLAGS)
# TWM_CFLAGS has results of pkg-config --cflags x11
AM_CXXFLAGS = -Werror -Wno-logical-op-parenthesis $(TWM_CFLAGS) -std=c++11
AM_CXXFLAGS = -Werror $(TWM_CFLAGS) -std=c++11
twmruined_LDADD = $(TWM_LIBS)
twmruined_SOURCES = \
@ -48,7 +48,7 @@ twmruined_SOURCES = \
icons.h \
list.c \
list.h \
menus.c \
menus.cc \
menus.h \
parse.c \
parse.h \

View File

@ -368,6 +368,7 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@ -384,7 +385,7 @@ AM_CPPFLAGS = \
AM_CFLAGS = -Werror $(TWM_CFLAGS)
# TWM_CFLAGS has results of pkg-config --cflags x11
AM_CXXFLAGS = -Werror -Wno-logical-op-parenthesis $(TWM_CFLAGS) -std=c++11
AM_CXXFLAGS = -Werror $(TWM_CFLAGS) -std=c++11
twmruined_LDADD = $(TWM_LIBS)
twmruined_SOURCES = \
add_window.c \
@ -399,7 +400,7 @@ twmruined_SOURCES = \
icons.h \
list.c \
list.h \
menus.c \
menus.cc \
menus.h \
parse.c \
parse.h \

View File

@ -61,13 +61,20 @@ in this Software without prior written authorization from The Open Group.
#ifndef _ADD_WINDOW_
#define _ADD_WINDOW_
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN extern
#endif
extern char NoName[];
extern void AddDefaultBindings ( void );
EXTERN void AddDefaultBindings( void );
extern TwmWindow* AddWindow( Window w );
EXTERN void ComputeCommonTitleOffsets( void );
extern ColormapWindow * CreateColormapWindow ( Window w, Bool creating_parent, Bool property_window );
extern TwmColormap* CreateTwmColormap( Colormap c );
extern void FetchWmColormapWindows ( TwmWindow *tmp );
EXTERN void FetchWmColormapWindows( TwmWindow *tmp );
extern void FetchWmProtocols ( TwmWindow *tmp );
extern void GetGravityOffsets ( TwmWindow *tmp, int *xp, int *yp );
extern void GetWindowSizeHints ( TwmWindow *tmp );

View File

@ -64,18 +64,24 @@ in this Software without prior written authorization from The Open Group.
#include "screen.h"
#include "twm.h"
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN extern
#endif
typedef void (*event_proc)(void);
extern Time lastTimestamp;
#define LastTimestamp() lastTimestamp
extern void AutoRaiseWindow ( TwmWindow *tmp );
EXTERN void AutoRaiseWindow( TwmWindow *tmp );
extern void SetRaiseWindow( TwmWindow *tmp );
extern void InitEvents( void );
extern Bool StashEventTime( XEvent *ev );
extern Window WindowOfEvent( XEvent *e );
extern Bool DispatchEvent2 ( void );
extern Bool DispatchEvent ( void );
EXTERN Bool DispatchEvent2( void );
EXTERN Bool DispatchEvent( void );
extern void HandleEvents( void );
extern void HandleColormapNotify( void );
extern void HandleVisibilityNotify( void );
@ -97,12 +103,12 @@ extern void HandleEnterNotify ( void );
extern void HandleLeaveNotify( void );
extern void HandleConfigureRequest( void );
extern void HandleShapeNotify( void );
extern void HandleUnknown ( void );
EXTERN void HandleUnknown( void );
extern int Transient( Window w, Window *propw );
extern ScreenInfo* FindScreenInfo( Window w );
extern void InstallWindowColormaps ( int type, TwmWindow *tmp );
extern void InstallRootColormap ( void );
extern void UninstallRootColormap ( void );
EXTERN void InstallWindowColormaps( int type, TwmWindow *tmp );
EXTERN void InstallRootColormap( void );
EXTERN void UninstallRootColormap( void );
extern event_proc EventHandler[];
extern Window DragWindow;

View File

@ -56,13 +56,16 @@ in this Software without prior written authorization from The Open Group.
*
* 17-Nov-87 Thomas E. LaStrange File created
*
* 29-Nov-20 Mike Small Switch to C++
***********************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <X11/Xos.h>
#include "twm.h"
#include "gc.h"
@ -82,14 +85,19 @@ in this Software without prior written authorization from The Open Group.
#include <X11/extensions/sync.h>
#include <X11/SM/SMlib.h>
int RootFunction = 0;
MenuRoot *ActiveMenu = NULL; /**< the active menu */
MenuItem *ActiveItem = NULL; /**< the active menu item */
int MoveFunction; /**< either F_MOVE or F_FORCEMOVE */
int WindowMoved = FALSE;
int menuFromFrameOrWindowOrTitlebar = FALSE;
constexpr Pixel UNUSED_PIXEL{~0UL};
const int SHADOWWIDTH{5}; /* in pixels */
int RootFunction{0};
MenuRoot *ActiveMenu{nullptr}; /**< the active menu */
MenuItem *ActiveItem{nullptr}; /**< the active menu item */
int MoveFunction; /**< either F_MOVE or F_FORCEMOVE */
// change these two to bool when use in events.c changes to C++.
int WindowMoved{false};
int menuFromFrameOrWindowOrTitlebar{false};
int ConstMove{false}; /**< constrained move variables */
int ConstMove = FALSE; /**< constrained move variables */
int ConstMoveDir;
int ConstMoveX;
int ConstMoveY;
@ -103,19 +111,19 @@ int ConstMoveYB;
int ResizeOrigX;
int ResizeOrigY;
int MenuDepth = 0; /**< number of menus up */
int MenuDepth{0}; /**< number of menus up */
static struct {
int x;
int y;
} MenuOrigins[MAXMENUDEPTH];
static Cursor LastCursor;
static Bool belongs_to_twm_window ( TwmWindow *t, Window w );
static void Identify ( TwmWindow *t );
static bool belongs_to_twm_window(const TwmWindow& t, Window w);
static void Identify(const TwmWindow* t);
static void send_clientmessage(Window w, Atom a, Time timestamp);
static void BumpWindowColormap ( TwmWindow *tmp, int inc );
static int DeferExecution ( int context, int func, Cursor cursor );
static Bool NeedToDefer ( MenuRoot *root );
static void BumpWindowColormap(TwmWindow &tmp, int inc);
static bool DeferExecution(int context, int func, Cursor cursor);
static bool NeedToDefer(MenuRoot *root);
static void DestroyMenu(MenuRoot *menu);
static void MakeMenu ( MenuRoot *mr );
static void Execute ( const char *s );
@ -123,8 +131,6 @@ static void WarpAlongRing ( XButtonEvent *ev, Bool forward );
static int WarpThere ( TwmWindow * t );
static void WarpToWindow ( TwmWindow *t );
#define SHADOWWIDTH 5 /* in pixels */
@ -177,7 +183,7 @@ InitMenus(void)
Bool AddFuncKey (char *name, int cont, int mods, int func, char *win_name,
char *action)
{
FuncKey *tmp;
FuncKey *fkey;
KeySym keysym;
KeyCode keycode;
@ -192,29 +198,29 @@ Bool AddFuncKey (char *name, int cont, int mods, int func, char *win_name,
}
/* see if there already is a key defined for this context */
for (tmp = Scr->FuncKeyRoot.next; tmp != NULL; tmp = tmp->next)
for (fkey = Scr->FuncKeyRoot.next; fkey != NULL; fkey = fkey->next)
{
if (tmp->keysym == keysym &&
tmp->cont == cont &&
tmp->mods == mods)
if (fkey->keysym == keysym &&
fkey->cont == cont &&
fkey->mods == mods)
break;
}
if (tmp == NULL)
if (fkey == NULL)
{
tmp = malloc(sizeof(FuncKey));
tmp->next = Scr->FuncKeyRoot.next;
Scr->FuncKeyRoot.next = tmp;
fkey = new FuncKey;
fkey->next = Scr->FuncKeyRoot.next;
Scr->FuncKeyRoot.next = fkey;
}
tmp->name = name;
tmp->keysym = keysym;
tmp->keycode = keycode;
tmp->cont = cont;
tmp->mods = mods;
tmp->func = func;
tmp->win_name = win_name;
tmp->action = action;
fkey->name = name;
fkey->keysym = keysym;
fkey->keycode = keycode;
fkey->cont = cont;
fkey->mods = mods;
fkey->func = func;
fkey->win_name = win_name;
fkey->action = action;
return True;
}
@ -224,29 +230,17 @@ Bool AddFuncKey (char *name, int cont, int mods, int func, char *win_name,
int CreateTitleButton(const char *name, int func, const char *action,
MenuRoot *menuroot, Bool rightside, Bool append)
{
TitleButton *tb = malloc (sizeof(TitleButton));
if (!tb) {
fprintf (stderr,
"%s: unable to allocate %ld bytes for title button\n",
ProgramName, (unsigned long)sizeof(TitleButton));
return 0;
}
tb->next = NULL;
tb->name = name; /* note that we are not copying */
tb->bitmap = None; /* WARNING, values not set yet */
tb->width = 0; /* see InitTitlebarButtons */
tb->height = 0; /* ditto */
tb->func = func;
tb->action = action;
tb->menuroot = menuroot;
tb->rightside = rightside;
if (rightside) {
/* 1. Note that we are not copying name.
* 2. bitmap, width, and height are set later by InitTitlebarButtons */
TitleButton* tb = new TitleButton {
// next, name, bitmap, srcx, srcy, width, height, dstx, dsty
nullptr, name, None, 0, 0, 0, 0, 0, 0,
func, action, menuroot, rightside
};
if (rightside)
Scr->TBInfo.nright++;
} else {
else
Scr->TBInfo.nleft++;
}
/*
* Cases for list:
@ -262,13 +256,13 @@ int CreateTitleButton (const char *name, int func, const char *action,
tb->next = Scr->TBInfo.head;
Scr->TBInfo.head = tb;
} else if (append && rightside) { /* 3 */
register TitleButton *t;
TitleButton *t;
for /* SUPPRESS 530 */
(t = Scr->TBInfo.head; t->next; t = t->next);
t->next = tb;
tb->next = NULL;
} else { /* 2 */
register TitleButton *t, *prev = NULL;
TitleButton *t, *prev = NULL;
for (t = Scr->TBInfo.head; t && !t->rightside; t = t->next) {
prev = t;
}
@ -511,7 +505,7 @@ UpdateMenu(void)
continue;
if (Event.type == ButtonRelease || Cancel) {
menuFromFrameOrWindowOrTitlebar = FALSE;
menuFromFrameOrWindowOrTitlebar = false;
fromMenu = FALSE;
return;
}
@ -626,47 +620,39 @@ UpdateMenu(void)
MenuRoot *
NewMenuRoot(const char *name)
{
MenuRoot *tmp;
MenuRoot *mroot;
#define UNUSED_PIXEL ((unsigned long) (~0)) /* more than 24 bits */
mroot = new MenuRoot {
nullptr, nullptr, nullptr, nullptr,
name, None, None, UNUSED_PIXEL, UNUSED_PIXEL, NEVER_MAPPED,
0, 0, 0, false, false, false };
tmp = malloc(sizeof(MenuRoot));
tmp->hi_fore = UNUSED_PIXEL;
tmp->hi_back = UNUSED_PIXEL;
tmp->name = name;
tmp->prev = NULL;
tmp->first = NULL;
tmp->last = NULL;
tmp->items = 0;
tmp->width = 0;
tmp->mapped = NEVER_MAPPED;
tmp->pull = FALSE;
tmp->w = None;
tmp->shadow = None;
tmp->real_menu = FALSE;
if (Scr->MenuList == NULL)
if (Scr->MenuList == nullptr)
{
Scr->MenuList = tmp;
Scr->MenuList->next = NULL;
Scr->MenuList = mroot;
Scr->MenuList->next = nullptr;
}
if (Scr->LastMenu == NULL)
// This is the only use of LastMenu. Careful. Though the variable
// is only referenced here it builds out the tail of the list
// referenced by MenuList. Might as well keep til the list can
// be put in a std::vector.
if (Scr->LastMenu == nullptr)
{
Scr->LastMenu = tmp;
Scr->LastMenu->next = NULL;
Scr->LastMenu = mroot;
Scr->LastMenu->next = nullptr;
}
else
{
Scr->LastMenu->next = tmp;
Scr->LastMenu = tmp;
Scr->LastMenu->next = NULL;
Scr->LastMenu->next = mroot;
Scr->LastMenu = mroot;
Scr->LastMenu->next = nullptr;
}
if (strcmp(name, TWM_WINDOWS) == 0)
Scr->Windows = tmp;
Scr->Windows = mroot;
return (tmp);
return mroot;
}
@ -686,64 +672,64 @@ MenuItem *
AddToMenu(MenuRoot *menu, const char *item, const char *action,
MenuRoot *sub, int func, const char *fore, const char *back)
{
MenuItem *tmp;
int width;
#ifdef DEBUG_MENUS
fprintf(stderr, "adding menu item=\"%s\", action=%s, sub=%d, f=%d\n",
item, action, sub, func);
#endif
tmp = malloc(sizeof(MenuItem));
tmp->root = menu;
MenuItem *m_item = new MenuItem{
nullptr, // next
nullptr, // prev
sub, // sub
menu, // root
item,
action,
0, // fore
0, // back
0, // hi_fore
0, // hi_back
menu->items++,
0, // x coord for text
static_cast<short>(func),
0, // state
static_cast<short>(strlen(item)),
false // user_colors
};
if (menu->first == NULL)
if (menu->first == nullptr)
{
menu->first = tmp;
tmp->prev = NULL;
menu->first = m_item;
m_item->prev = nullptr;
}
else
{
menu->last->next = tmp;
tmp->prev = menu->last;
menu->last->next = m_item;
m_item->prev = menu->last;
}
menu->last = tmp;
menu->last = m_item;
tmp->item = item;
tmp->strlen = strlen(item);
tmp->action = action;
tmp->next = NULL;
tmp->sub = NULL;
tmp->state = 0;
tmp->func = func;
if (!Scr->HaveFonts)
CreateFonts();
if (!Scr->HaveFonts) CreateFonts();
width = MyFont_TextWidth(&Scr->MenuFont, item, tmp->strlen);
int width{MyFont_TextWidth(&Scr->MenuFont, item, m_item->strlen)};
if (width <= 0)
width = 1;
if (width > menu->width)
menu->width = width;
tmp->user_colors = FALSE;
if (Scr->Monochrome == COLOR && fore != NULL)
if (Scr->Monochrome == COLOR && fore != nullptr)
{
int save;
save = Scr->FirstTime;
Scr->FirstTime = TRUE;
GetColor(COLOR, &tmp->fore, fore);
GetColor(COLOR, &tmp->back, back);
auto save{Scr->FirstTime};
Scr->FirstTime = true;
GetColor(COLOR, &m_item->fore, fore);
GetColor(COLOR, &m_item->back, back);
Scr->FirstTime = save;
tmp->user_colors = TRUE;
m_item->user_colors = true;
}
if (sub != NULL)
{
tmp->sub = sub;
menu->pull = TRUE;
}
tmp->item_num = menu->items++;
if (sub != nullptr)
menu->pull = true;
return (tmp);
return m_item;
}
@ -964,71 +950,50 @@ MakeMenu(MenuRoot *mr)
Bool
PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
{
int WindowNameCount;
TwmWindow **WindowNames;
TwmWindow *tmp_win2,*tmp_win3;
int i;
int (*compar)(const char *, const char *) =
(Scr->CaseSensitive ? strcmp : XmuCompareISOLatin1);
if (!menu) return False;
if (!menu)
return False;
InstallRootColormap();
if (menu == Scr->Windows)
{
TwmWindow *tmp_win;
/* this is the twm windows menu, let's go ahead and build it */
/* this is the windows list menu, rebuild it */
DestroyMenu(menu);
menu->first = NULL;
menu->last = NULL;
menu->first = nullptr;
menu->last = nullptr;
menu->items = 0;
menu->width = 0;
menu->mapped = NEVER_MAPPED;
AddToMenu(menu, "TWM Windows", NULLSTR, NULL, F_TITLE,NULLSTR,NULLSTR);
AddToMenu(menu, "Windows", NULLSTR, nullptr,
F_TITLE, NULLSTR, NULLSTR);
for(tmp_win = Scr->TwmRoot.next , WindowNameCount=0;
tmp_win != NULL;
tmp_win = tmp_win->next)
WindowNameCount++;
if (WindowNameCount != 0)
std::vector<const TwmWindow*> windows;
for(auto w = Scr->TwmRoot.next; w; w = w->next)
windows.push_back(w);
std::sort(windows.begin(), windows.end(),
[](const TwmWindow* w1, const TwmWindow* w2) {
return 0 > XmuCompareISOLatin1(w1->name, w2->name);
});
for (auto w : windows)
{
WindowNames = malloc(sizeof(TwmWindow *) * WindowNameCount);
WindowNames[0] = Scr->TwmRoot.next;
for(tmp_win = Scr->TwmRoot.next->next , WindowNameCount=1;
tmp_win != NULL;
tmp_win = tmp_win->next,WindowNameCount++)
{
tmp_win2 = tmp_win;
for (i=0;i<WindowNameCount;i++)
{
if ((*compar)(tmp_win2->name,WindowNames[i]->name) < 0)
{
tmp_win3 = tmp_win2;
tmp_win2 = WindowNames[i];
WindowNames[i] = tmp_win3;
}
}
WindowNames[WindowNameCount] = tmp_win2;
}
for (i=0; i<WindowNameCount; i++)
{
AddToMenu(menu, WindowNames[i]->name, (char *)WindowNames[i],
NULL, F_POPUP,NULL,NULL);
}
free(WindowNames);
// 3rd argument char* (action)? How does that work?
AddToMenu(menu, w->name, (char *)w, nullptr, F_POPUP,
nullptr, nullptr);
}
MakeMenu(menu);
}
if (menu->w == None || menu->items == 0) return False;
if (menu->w == None || menu->items == 0)
return False;
/* Prevent recursively bringing up menus. */
if (menu->mapped == MAPPED) return False;
if (menu->mapped == MAPPED)
return False;
/*
* Dynamically set the parent; this allows pull-ups to also be main
@ -1116,7 +1081,7 @@ PopDownMenu(void)
ActiveItem = NULL;
MenuDepth = 0;
if (Context == C_WINDOW || Context == C_FRAME || Context == C_TITLE)
menuFromFrameOrWindowOrTitlebar = TRUE;
menuFromFrameOrWindowOrTitlebar = true;
}
@ -1143,22 +1108,20 @@ FindMenuRoot(const char *name)
static Bool
belongs_to_twm_window (TwmWindow *t, Window w)
static bool
belongs_to_twm_window(const TwmWindow& t, Window w)
{
if (!t) return False;
if (w == t.frame || w == t.title_w || w == t.hilite_w ||
w == t.icon_w || w == t.icon_bm_w) return true;
if (w == t->frame || w == t->title_w || w == t->hilite_w ||
w == t->icon_w || w == t->icon_bm_w) return True;
if (t && t->titlebuttons) {
register TBWindow *tbw;
register int nb = Scr->TBInfo.nleft + Scr->TBInfo.nright;
for (tbw = t->titlebuttons; nb > 0; tbw++, nb--) {
if (tbw->window == w) return True;
if (t.titlebuttons) {
int nb = Scr->TBInfo.nleft + Scr->TBInfo.nright;
for (const TBWindow* tbw = t.titlebuttons; nb > 0; tbw++, nb--) {
if (tbw->window == w)
return true;
}
}
return False;
return false;
}
@ -1348,18 +1311,18 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_IDENTIFY:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
Identify(tmp_win);
break;
case F_VERSION:
Identify ((TwmWindow *) NULL);
Identify(nullptr);
break;
case F_AUTORAISE:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
tmp_win->auto_raise = !tmp_win->auto_raise;
if (tmp_win->auto_raise) ++(Scr->NumAutoRaises);
@ -1389,7 +1352,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
EventHandler[EnterNotify] = HandleUnknown;
EventHandler[LeaveNotify] = HandleUnknown;
if (DeferExecution(context, func, Scr->MoveCursor))
return TRUE;
return true;
PopDownMenu();
@ -1407,7 +1370,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
* see if this is being done from the titlebar
*/
fromtitlebar =
belongs_to_twm_window (tmp_win, eventp->xbutton.window);
belongs_to_twm_window(*tmp_win, eventp->xbutton.window);
/* Save pointer position so we can tell if it was moved or
not during the resize. */
@ -1453,14 +1416,14 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_TOPZOOM:
case F_BOTTOMZOOM:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
fullzoom(tmp_win, func);
break;
case F_MOVE:
case F_FORCEMOVE:
if (DeferExecution(context, func, Scr->MoveCursor))
return TRUE;
return true;
PopDownMenu();
rootw = eventp->xbutton.root;
@ -1487,7 +1450,6 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
DragY = eventp->xbutton.y;
moving_icon = TRUE;
}
else if (w != tmp_win->icon_w)
{
XTranslateCoordinates(dpy, w, tmp_win->frame,
@ -1518,7 +1480,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
{
int width, height;
ConstMove = TRUE;
ConstMove = true;
ConstMoveDir = MOVE_NONE;
ConstMoveX = eventp->xbutton.x_root - DragX - JunkBW;
ConstMoveY = eventp->xbutton.y_root - DragY - JunkBW;
@ -1565,7 +1527,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
/*
* see if this is being done from the titlebar
*/
fromtitlebar = belongs_to_twm_window (tmp_win, eventp->xbutton.window);
fromtitlebar = belongs_to_twm_window(*tmp_win, eventp->xbutton.window);
if (menuFromFrameOrWindowOrTitlebar) {
/* warp the pointer to the middle of the window */
@ -1575,7 +1537,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
XFlush(dpy);
}
while (TRUE)
while (true)
{
long releaseEvent = menuFromFrameOrWindowOrTitlebar ?
ButtonPress : ButtonRelease;
@ -1621,7 +1583,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
if (Cancel)
{
WindowMoved = FALSE;
WindowMoved = false;
UninstallRootColormap();
return TRUE; /* XXX should this be FALSE? */
}
@ -1652,7 +1614,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
abs(eventp->xmotion.y_root - origY) < Scr->MoveDelta)
continue;
WindowMoved = TRUE;
WindowMoved = true;
DragWindow = w;
if (ConstMove)
@ -1771,7 +1733,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
}
if (NeedToDefer(mroot) && DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
else
{
for (mitem = mroot->first; mitem != NULL; mitem = mitem->next)
@ -1787,7 +1749,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_DEICONIFY:
case F_ICONIFY:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
if (tmp_win->icon)
{
@ -1802,7 +1764,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_RAISELOWER:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
if (!WindowMoved) {
XWindowChanges xwc;
@ -1816,7 +1778,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_RAISE:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
/* check to make sure raise is not from the WindowFunction */
if (w == tmp_win->icon_w && Context != C_ROOT)
@ -1828,7 +1790,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_LOWER:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
if (w == tmp_win->icon_w)
XLowerWindow(dpy, tmp_win->icon_w);
@ -1839,7 +1801,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_FOCUS:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
if (tmp_win->icon == FALSE)
{
@ -1868,13 +1830,13 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_DESTROY:
if (DeferExecution(context, func, Scr->DestroyCursor))
return TRUE;
return true;
XKillClient(dpy, tmp_win->w);
break;
case F_DELETE:
if (DeferExecution(context, func, Scr->DestroyCursor))
return TRUE;
return true;
else if (tmp_win->protocols & DoesWmDeleteWindow)
SendDeleteWindowMessage (tmp_win, LastTimestamp());
else
@ -1883,7 +1845,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_SAVEYOURSELF:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
if (tmp_win->protocols & DoesWmSaveYourself)
SendSaveYourselfMessage (tmp_win, LastTimestamp());
@ -1961,12 +1923,14 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_COLORMAP:
{
if (tmp_win != nullptr) {
if (strcmp(action, COLORMAP_NEXT) == 0) {
BumpWindowColormap (tmp_win, 1);
BumpWindowColormap(*tmp_win, 1);
} else if(strcmp (action, COLORMAP_PREV) == 0) {
BumpWindowColormap (tmp_win, -1);
BumpWindowColormap(*tmp_win, -1);
} else {
BumpWindowColormap (tmp_win, 0);
BumpWindowColormap(*tmp_win, 0);
}
}
}
break;
@ -1974,10 +1938,10 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_WARPPREV:
case F_WARPNEXT:
{
register TwmWindow *t;
static TwmWindow *savedwarp = NULL;
TwmWindow* t;
static TwmWindow* savedwarp{nullptr};
TwmWindow *of, *l, *n;
int c=0;
int c{0};
#define wseq(w) (func == F_WARPNEXT ? (w)->next : (w)->prev)
#define nwin(w) ((w) && (n=wseq(w)) != NULL && n != &Scr->TwmRoot ? n : l)
@ -2007,22 +1971,20 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_WARPTO:
{
register TwmWindow *t;
int len;
const size_t len{strlen(action)};
len = strlen(action);
for (t = Scr->TwmRoot.next; t != NULL; t = t->next) {
TwmWindow* t;
for (t = Scr->TwmRoot.next; t != nullptr; t = t->next) {
if (!strncmp(action, t->name, len))
if (WarpThere(t)) break;
}
if (!t) {
for (t = Scr->TwmRoot.next; t != NULL; t = t->next) {
for (t = Scr->TwmRoot.next; t != nullptr; t = t->next) {
if (!strncmp(action, t->classh.res_name, len))
if (WarpThere(t)) break;
}
if (!t) {
for (t = Scr->TwmRoot.next; t != NULL; t = t->next) {
for (t = Scr->TwmRoot.next; t != nullptr; t = t->next) {
if (!strncmp(action, t->classh.res_class, len))
if (WarpThere(t)) break;
}
@ -2091,7 +2053,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_WINREFRESH:
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
if (context == C_ICON && tmp_win->icon_w)
w = XCreateSimpleWindow(dpy, tmp_win->icon_w,
@ -2113,7 +2075,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
if (HasSync)
{
if (DeferExecution(context, func, Scr->SelectCursor))
return TRUE;
return true;
(void)XSyncSetPriority(dpy, tmp_win->w, atoi(action));
}
break;
@ -2136,13 +2098,12 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
*
* \param context the context in which the mouse button was pressed
* \param func the function to defer
* \param cursor cursor the cursor to display while waiting
* \param cursor the cursor to display while waiting
*/
static int
static bool
DeferExecution(int context, int func, Cursor cursor)
{
if (context == C_ROOT)
{
if (context == C_ROOT) {
LastCursor = cursor;
XGrabPointer(dpy, Scr->Root, True,
ButtonPressMask | ButtonReleaseMask,
@ -2151,10 +2112,9 @@ DeferExecution(int context, int func, Cursor cursor)
RootFunction = func;
return (TRUE);
return true;
}
return (FALSE);
return false;
}
@ -2179,12 +2139,10 @@ ReGrab(void)
*
* \param root the menu root to check
*/
static Bool
static bool
NeedToDefer(MenuRoot *root)
{
MenuItem *mitem;
for (mitem = root->first; mitem != NULL; mitem = mitem->next)
for (MenuItem* mitem = root->first; mitem != nullptr; mitem = mitem->next)
{
switch (mitem->func)
{
@ -2208,10 +2166,10 @@ NeedToDefer(MenuRoot *root)
case F_TOPZOOM:
case F_BOTTOMZOOM:
case F_AUTORAISE:
return TRUE;
return true;
}
}
return FALSE;
return false;
}
@ -2426,7 +2384,7 @@ Iconify(TwmWindow *tmp_win, int def_x, int def_y)
static void
Identify (TwmWindow *t)
Identify(const TwmWindow* t)
{
int i, n, twidth, width, height;
int x, y;
@ -2583,45 +2541,46 @@ WarpToScreen (int n, int inc)
* rotate our internal copy of WM_COLORMAP_WINDOWS
*/
static void
BumpWindowColormap (TwmWindow *tmp, int inc)
BumpWindowColormap(TwmWindow& cmw, int inc)
{
int i, j, previously_installed;
ColormapWindow **cwins;
if (!tmp) return;
if (inc && tmp->cmaps.number_cwins > 0) {
cwins = malloc(sizeof(ColormapWindow *) * tmp->cmaps.number_cwins);
if (inc && cmw.cmaps.number_cwins > 0) {
// must use malloc until uses in C files convert to C++ and new.
ColormapWindow **cwins{
static_cast<ColormapWindow**>(malloc(sizeof(ColormapWindow*)
* cmw.cmaps.number_cwins)) };
if (cwins) {
int previously_installed;
if ((previously_installed =
/* SUPPRESS 560 */(Scr->cmapInfo.cmaps == &tmp->cmaps &&
tmp->cmaps.number_cwins))) {
for (i = tmp->cmaps.number_cwins; i-- > 0; )
tmp->cmaps.cwins[i]->colormap->state = 0;
/* SUPPRESS 560 */(Scr->cmapInfo.cmaps == &cmw.cmaps &&
cmw.cmaps.number_cwins))) {
for (int i = cmw.cmaps.number_cwins; i-- > 0; )
cmw.cmaps.cwins[i]->colormap->state = 0;
}
for (i = 0; i < tmp->cmaps.number_cwins; i++) {
j = i - inc;
if (j >= tmp->cmaps.number_cwins)
j -= tmp->cmaps.number_cwins;
for (int i = 0; i < cmw.cmaps.number_cwins; ++i) {
int j{i-inc};
if (j >= cmw.cmaps.number_cwins)
j -= cmw.cmaps.number_cwins;
else if (j < 0)
j += tmp->cmaps.number_cwins;
cwins[j] = tmp->cmaps.cwins[i];
j += cmw.cmaps.number_cwins;
cwins[j] = cmw.cmaps.cwins[i];
}
free(tmp->cmaps.cwins);
free(cmw.cmaps.cwins);
tmp->cmaps.cwins = cwins;
cmw.cmaps.cwins = cwins;
if (tmp->cmaps.number_cwins > 1)
bzero (tmp->cmaps.scoreboard,
ColormapsScoreboardLength(&tmp->cmaps));
if (cmw.cmaps.number_cwins > 1)
bzero (cmw.cmaps.scoreboard,
ColormapsScoreboardLength(&cmw.cmaps));
if (previously_installed)
InstallWindowColormaps(PropertyNotify, (TwmWindow *) NULL);
}
} else
FetchWmColormapWindows (tmp);
FetchWmColormapWindows(&cmw);
}
@ -2643,19 +2602,18 @@ SetBorder (TwmWindow *tmp, Bool onoroff)
static void
DestroyMenu(MenuRoot *menu)
{
MenuItem *item;
if (menu->w) {
XDeleteContext(dpy, menu->w, MenuContext);
XDeleteContext(dpy, menu->w, ScreenContext);
if (Scr->Shadow) XDestroyWindow (dpy, menu->shadow);
if (Scr->Shadow)
XDestroyWindow(dpy, menu->shadow);
XDestroyWindow(dpy, menu->w);
}
for (item = menu->first; item; ) {
MenuItem *tmp = item;
for (MenuItem* item = menu->first; item; ) {
MenuItem* tmp{item};
item = item->next;
free (tmp);
delete tmp;
}
}
@ -2748,15 +2706,15 @@ WarpToWindow (TwmWindow *t)
static void
send_clientmessage(Window w, Atom a, Time timestamp)
{
XClientMessageEvent ev;
XEvent ev;
ev.type = ClientMessage;
ev.window = w;
ev.message_type = _XA_WM_PROTOCOLS;
ev.format = 32;
ev.data.l[0] = a;
ev.data.l[1] = timestamp;
XSendEvent (dpy, w, False, 0L, (XEvent *) &ev);
ev.xclient.type = ClientMessage;
ev.xclient.window = w;
ev.xclient.message_type = _XA_WM_PROTOCOLS;
ev.xclient.format = 32;
ev.xclient.data.l[0] = a;
ev.xclient.data.l[1] = timestamp;
XSendEvent(dpy, w, False, 0L, &ev);
}
void

View File

@ -164,29 +164,36 @@ extern int MenuDepth;
#define COLORMAP_PREV "prev"
#define COLORMAP_DEFAULT "default"
extern void InitMenus ( void );
extern Bool AddFuncKey ( char *name, int cont, int mods, int func, char *win_name, char *action );
extern int CreateTitleButton ( const char *name, int func, const char *action, MenuRoot *menuroot, Bool rightside, Bool append );
extern void InitTitlebarButtons ( void );
extern void PaintEntry ( MenuRoot *mr, MenuItem *mi, int exposure );
extern void PaintMenu ( MenuRoot *mr, XEvent *e );
extern void UpdateMenu ( void );
extern MenuRoot * NewMenuRoot ( const char *name );
extern MenuItem * AddToMenu ( MenuRoot *menu, const char *item, const char *action, MenuRoot *sub, int func, const char *fore, const char *back );
extern void MakeMenus ( void );
extern Bool PopUpMenu ( MenuRoot *menu, int x, int y, Bool center );
extern void PopDownMenu ( void );
extern MenuRoot * FindMenuRoot ( const char *name );
extern int ExecuteFunction ( int func, const char *action, Window w, TwmWindow *tmp_win, XEvent *eventp, int context, int pulldown );
extern void ReGrab ( void );
extern void FocusOnRoot ( void );
extern void DeIconify ( TwmWindow *tmp_win );
extern void Iconify ( TwmWindow *tmp_win, int def_x, int def_y );
extern void SetMapStateProp ( TwmWindow *tmp_win, int state );
extern void WarpToScreen ( int n, int inc );
extern void SetBorder ( TwmWindow *tmp, Bool onoroff );
extern void SendDeleteWindowMessage ( TwmWindow *tmp, Time timestamp );
extern void SendSaveYourselfMessage ( TwmWindow *tmp, Time timestamp );
extern void SendTakeFocusMessage ( TwmWindow *tmp, Time timestamp );
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN extern
#endif
EXTERN void InitMenus( void );
EXTERN Bool AddFuncKey( char *name, int cont, int mods, int func, char *win_name, char *action );
EXTERN int CreateTitleButton( const char *name, int func, const char *action, MenuRoot *menuroot, Bool rightside, Bool append );
EXTERN void InitTitlebarButtons( void );
EXTERN void PaintEntry( MenuRoot *mr, MenuItem *mi, int exposure );
EXTERN void PaintMenu( MenuRoot *mr, XEvent *e );
EXTERN void UpdateMenu( void );
EXTERN MenuRoot * NewMenuRoot( const char *name );
EXTERN MenuItem * AddToMenu( MenuRoot *menu, const char *item, const char *action, MenuRoot *sub, int func, const char *fore, const char *back );
EXTERN void MakeMenus( void );
EXTERN Bool PopUpMenu( MenuRoot *menu, int x, int y, Bool center );
EXTERN void PopDownMenu( void );
EXTERN MenuRoot * FindMenuRoot( const char *name );
EXTERN int ExecuteFunction( int func, const char *action, Window w, TwmWindow *tmp_win, XEvent *eventp, int context, int pulldown );
EXTERN void ReGrab( void );
EXTERN void FocusOnRoot( void );
EXTERN void DeIconify( TwmWindow *tmp_win );
EXTERN void Iconify( TwmWindow *tmp_win, int def_x, int def_y );
EXTERN void SetMapStateProp( TwmWindow *tmp_win, int state );
EXTERN void WarpToScreen( int n, int inc );
EXTERN void SetBorder( TwmWindow *tmp, Bool onoroff );
EXTERN void SendDeleteWindowMessage( TwmWindow *tmp, Time timestamp );
EXTERN void SendSaveYourselfMessage( TwmWindow *tmp, Time timestamp );
EXTERN void SendTakeFocusMessage( TwmWindow *tmp, Time timestamp );
EXTERN Bool GetWMState( Window w, int *statep, Window *iwp );
#endif /* _MENUS_ */

View File

@ -61,18 +61,24 @@ in this Software without prior written authorization from The Open Group.
#ifndef _RESIZE_
#define _RESIZE_
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN extern
#endif
extern void AddEndResize( TwmWindow *tmp_win );
extern void AddStartResize( TwmWindow *tmp_win, int x, int y, int w, int h );
extern void ConstrainSize( TwmWindow *tmp_win, int *widthp, int *heightp );
extern void DoResize( int x_root, int y_root, TwmWindow *tmp_win );
extern void EndResize( void );
extern void fullzoom ( TwmWindow *tmp_win, int flag );
extern void MenuDoResize ( int x_root, int y_root, TwmWindow *tmp_win );
extern void MenuEndResize ( TwmWindow *tmp_win );
extern void MenuStartResize ( TwmWindow *tmp_win, int x, int y, int w, int h );
EXTERN void fullzoom( TwmWindow *tmp_win, int flag );
EXTERN void MenuDoResize( int x_root, int y_root, TwmWindow *tmp_win );
EXTERN void MenuEndResize( TwmWindow *tmp_win );
EXTERN void MenuStartResize( TwmWindow *tmp_win, int x, int y, int w, int h );
extern void SetFrameShape( TwmWindow *tmp );
extern void SetupFrame( TwmWindow *tmp_win, int x, int y, int w, int h, int bw, Bool sendEvent );
extern void SetupWindow( TwmWindow *tmp_win, int x, int y, int w, int h, int bw );
extern void StartResize ( XEvent *evp, TwmWindow *tmp_win, Bool fromtitlebar );
EXTERN void StartResize( XEvent *evp, TwmWindow *tmp_win, Bool fromtitlebar );
#endif /* _RESIZE_ */

View File

@ -87,7 +87,7 @@ typedef struct ScreenInfo
int hilite_pm_width, hilite_pm_height; /* cache the size */
MenuRoot *MenuList; /* head of the menu list */
MenuRoot *LastMenu; /* the last menu (mostly unused?) */
MenuRoot *LastMenu; /* the last menu (for adding to menu list) */
MenuRoot *Windows; /* the TwmWindows menu */
TwmWindow *Ring; /* one of the windows in window ring */
@ -212,7 +212,6 @@ typedef struct ScreenInfo
short InterpolateMenuColors;/* make pretty menus */
short HaveFonts; /* set if fonts have been loaded */
short FirstTime; /* first time we've read .twmrc */
short CaseSensitive; /* be case-sensitive when sorting names */
short WarpUnmapped; /* allow warping to unmapped windows */
FuncKey FuncKeyRoot;

View File

@ -722,7 +722,6 @@ InitVariables(void)
Scr->InterpolateMenuColors = FALSE;
Scr->FirstTime = TRUE;
Scr->HaveFonts = FALSE; /* i.e. not loaded yet */
Scr->CaseSensitive = TRUE;
Scr->WarpUnmapped = FALSE;
/* setup default fonts; overridden by defaults from system.twmrc */

View File

@ -74,6 +74,12 @@ from The Open Group.
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN extern
#endif
#ifndef WithdrawnState
#define WithdrawnState 0
#endif
@ -327,11 +333,10 @@ typedef struct TWMWinConfigEntry
#include <X11/Xosdefs.h>
#include <stdlib.h>
extern void CreateFonts ( void );
EXTERN void CreateFonts( void );
extern void RestoreWithdrawnLocation ( TwmWindow *tmp );
extern void Reborder( Time time);
extern void Done( XtPointer, XtSignalId * ) _X_NORETURN;
extern void ComputeCommonTitleOffsets ( void );
EXTERN void Reborder( Time time);
EXTERN void Done( XtPointer, XtSignalId * ) _X_NORETURN;
extern void ComputeTitleLocation ( TwmWindow *tmp );
extern void ComputeWindowTitleOffsets ( TwmWindow *tmp_win, int width, Bool squeeze );
extern char *ProgramName;
@ -373,7 +378,6 @@ extern int Argc;
extern char **Argv;
extern void NewFontCursor ( Cursor *cp, const char *str );
extern void NewBitmapCursor ( Cursor *cp, char *source, char *mask );
extern Pixmap CreateMenuIcon ( int height, unsigned int *widthp, unsigned int *heightp );
extern Bool ErrorOccurred;
extern XErrorEvent LastErrorEvent;
@ -381,7 +385,6 @@ extern XErrorEvent LastErrorEvent;
#define ResetError() (ErrorOccurred = False)
extern Bool RestartPreviousState;
extern Bool GetWMState ( Window w, int *statep, Window *iwp );
extern void twmrc_error_prefix ( void );

View File

@ -71,6 +71,7 @@ EXTERN void MoveOutline ( Window root, int x, int y, int width, int height,
int bw, int th );
EXTERN void Zoom ( Window wf, Window wt );
EXTERN const char * ExpandFilename ( const char *name );
EXTERN Pixmap CreateMenuIcon( int height, unsigned int *widthp, unsigned int *heightp );
EXTERN void GetUnknownIcon( const char *name );
EXTERN Pixmap FindBitmap ( const char *name, unsigned int *widthp,
unsigned int *heightp );