Browse Source

Convert menus.c to C++ menus.cc

master
Mike Small 1 year ago
parent
commit
893bdb5928
  1. 22
      ChangeLog
  2. 1
      Makefile.in
  3. 1
      man/Makefile.in
  4. 8
      src/Makefile.am
  5. 7
      src/Makefile.in
  6. 10
      src/add_window.c
  7. 15
      src/add_window.h
  8. 2
      src/events.c
  9. 74
      src/events.h
  10. 576
      src/menus.cc
  11. 55
      src/menus.h
  12. 32
      src/resize.h
  13. 3
      src/screen.h
  14. 5
      src/twm.c
  15. 15
      src/twm.h
  16. 8
      src/util.c
  17. 3
      src/util.h

22
ChangeLog

@ -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

1
Makefile.in

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

1
man/Makefile.in

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

8
src/Makefile.am

@ -32,10 +32,10 @@ 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 = \
twmruined_SOURCES = \
add_window.c \
add_window.h \
cursor.c \
@ -44,11 +44,11 @@ twmruined_SOURCES = \
events.h \
gc.c \
gc.h \
icons.cc \
icons.cc \
icons.h \
list.c \
list.h \
menus.c \
menus.cc \
menus.h \
parse.c \
parse.h \

7
src/Makefile.in

@ -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 \
@ -395,11 +396,11 @@ twmruined_SOURCES = \
events.h \
gc.c \
gc.h \
icons.cc \
icons.cc \
icons.h \
list.c \
list.h \
menus.c \
menus.cc \
menus.h \
parse.c \
parse.h \

10
src/add_window.c

@ -183,7 +183,7 @@ AddWindow(Window w)
tmp_win->classh = NoClass;
XGetClassHint(dpy, tmp_win->w, &tmp_win->classh);
FetchWmProtocols (tmp_win);
FetchWmColormapWindows (tmp_win);
FetchWmColormapWindows(tmp_win);
if (name == NULL)
tmp_win->name = strdup(NoName);
@ -638,7 +638,7 @@ static void do_add_binding (int button, int context, int modifier, int func)
}
void
AddDefaultBindings (void)
AddDefaultBindings(void)
{
/*
* The bindings are stored in Scr->Mouse, indexed by
@ -760,7 +760,7 @@ static Window CreateHighlightWindow (TwmWindow *tmp_win)
}
void ComputeCommonTitleOffsets (void)
void ComputeCommonTitleOffsets(void)
{
int buttonwidth = (Scr->TBInfo.width + Scr->TBInfo.pad);
@ -991,7 +991,7 @@ CreateColormapWindow(Window w, Bool creating_parent, Bool property_window)
}
void
FetchWmColormapWindows (TwmWindow *tmp)
FetchWmColormapWindows(TwmWindow *tmp)
{
register int i, j;
Window *cmap_windows = NULL;
@ -1120,7 +1120,7 @@ FetchWmColormapWindows (TwmWindow *tmp)
}
void GetWindowSizeHints (TwmWindow *tmp)
void GetWindowSizeHints(TwmWindow *tmp)
{
long supplied = 0;

15
src/add_window.h

@ -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 TwmWindow * AddWindow ( Window w );
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 TwmColormap* CreateTwmColormap( Colormap c );
EXTERN void FetchWmColormapWindows( TwmWindow *tmp );
extern void FetchWmProtocols ( TwmWindow *tmp );
extern void GetGravityOffsets ( TwmWindow *tmp, int *xp, int *yp );
extern void GetWindowSizeHints ( TwmWindow *tmp );

2
src/events.c

@ -922,7 +922,7 @@ HandlePropertyNotify(void)
default:
if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS) {
FetchWmColormapWindows (Tmp_win); /* frees old data */
FetchWmColormapWindows(Tmp_win); /* frees old data */
break;
} else if (Event.xproperty.atom == _XA_WM_PROTOCOLS) {
FetchWmProtocols (Tmp_win);

74
src/events.h

@ -64,45 +64,51 @@ 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 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 void HandleEvents ( void );
extern void HandleColormapNotify ( void );
extern void HandleVisibilityNotify ( void );
extern void HandleKeyPress ( void );
extern void free_cwins ( TwmWindow *tmp );
extern void HandlePropertyNotify ( void );
extern void HandleClientMessage ( void );
extern void HandleExpose ( void );
extern void HandleDestroyNotify ( void );
extern void HandleCreateNotify ( void );
extern void HandleMapRequest ( void );
extern void SimulateMapRequest ( Window w );
extern void HandleMapNotify ( void );
extern void HandleUnmapNotify ( void );
extern void HandleMotionNotify ( void );
extern void HandleButtonRelease ( void );
extern void HandleButtonPress ( void );
extern void HandleEnterNotify ( void );
extern void HandleLeaveNotify ( void );
extern void HandleConfigureRequest ( void );
extern void HandleShapeNotify ( 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 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 void HandleEvents( void );
extern void HandleColormapNotify( void );
extern void HandleVisibilityNotify( void );
extern void HandleKeyPress( void );
extern void free_cwins( TwmWindow *tmp );
extern void HandlePropertyNotify( void );
extern void HandleClientMessage( void );
extern void HandleExpose( void );
extern void HandleDestroyNotify( void );
extern void HandleCreateNotify( void );
extern void HandleMapRequest( void );
extern void SimulateMapRequest( Window w );
extern void HandleMapNotify( void );
extern void HandleUnmapNotify( void );
extern void HandleMotionNotify( void );
extern void HandleButtonRelease( void );
extern void HandleButtonPress( void );
extern void HandleEnterNotify( void );
extern void HandleLeaveNotify( void );
extern void HandleConfigureRequest( void );
extern void HandleShapeNotify( 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 event_proc EventHandler[];
extern Window DragWindow;

576
src/menus.c → src/menus.cc

File diff suppressed because it is too large

55
src/menus.h

@ -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_ */

32
src/resize.h

@ -61,18 +61,24 @@ in this Software without prior written authorization from The Open Group.
#ifndef _RESIZE_
#define _RESIZE_
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 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 );
#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 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 );
#endif /* _RESIZE_ */

3
src/screen.h

@ -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;

5
src/twm.c

@ -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 */
@ -748,7 +747,7 @@ InitVariables(void)
}
void
CreateFonts (void)
CreateFonts(void)
{
GetFont(&Scr->TitleBarFont);
GetFont(&Scr->MenuFont);
@ -795,7 +794,7 @@ RestoreWithdrawnLocation (TwmWindow *tmp)
void
Reborder (Time time)
Reborder(Time time)
{
TwmWindow *tmp; /* temp twm window structure */
int scrnum;

15
src/twm.h

@ -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 );

8
src/util.c

@ -919,14 +919,14 @@ CreateQuestionPixmap (unsigned *widthp, unsigned *heightp)
static Pixmap
CreateMenuPixmap (unsigned *widthp, unsigned *heightp)
CreateMenuPixmap(unsigned *widthp, unsigned *heightp)
{
return CreateMenuIcon (Scr->TBInfo.width - Scr->TBInfo.border * 2,
widthp,heightp);
return CreateMenuIcon(Scr->TBInfo.width - Scr->TBInfo.border * 2,
widthp, heightp);
}
Pixmap
CreateMenuIcon (int height, unsigned *widthp, unsigned *heightp)
CreateMenuIcon(int height, unsigned *widthp, unsigned *heightp)
{
int h, w;
int ih, iw;

3
src/util.h

@ -71,7 +71,8 @@ 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 void GetUnknownIcon ( 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 );
EXTERN Pixmap GetBitmap ( const char *name );

Loading…
Cancel
Save