чување 15551e7d976a8c10fc5256665224e4ca8ff46f66
родитељ ed948ff1f4b9659788b86bda63258feabb28616f
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 14 Dec 2023 08:09:36 +0100
Separate main window-related functions into a separate file
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | Makefile | | | 14 | ++++++++++++-- |
| M | TODO | | | 1 | - |
| M | TODO.done | | | 1 | + |
| M | app.h | | | 4 | ---- |
| M | main.c | | | 85 | +++---------------------------------------------------------------------------- |
| A | mainwindow.c | | | 89 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | mainwindow.h | | | 3 | +++ |
измењених датотека: 7, додавања: 108(+), брисања: 89(-)
diff --git a/Makefile b/Makefile
@@ -4,7 +4,7 @@ FALLBACKDATE = unknown
FALLBACKVER = unknown
INSTALL = install
LIBS = -lWMaker -lWINGs -lWUtil -lwraster -lX11
-OBJS = infopanel.o main.o menu.o windowmanager.o
+OBJS = infopanel.o main.o mainwindow.o menu.o windowmanager.o
PREFIX = /usr/local
PROG = WMNewApp
@@ -21,7 +21,17 @@ MANPAGE = $(PROG).1
all: $(PROG) $(MANPAGE)
-$(PROG): config.h $(OBJS)
+infopanel.o: infopanel.c infopanel.h app.h config.h
+
+main.o: main.c app.h infopanel.h mainwindow.h menu.h windowmanager.h
+
+mainwindow.o: mainwindow.c mainwindow.h app.h appicon.xpm windowmanager.h
+
+menu.o: menu.c app.h config.h
+
+windowmanager.o: windowmanager.c windowmanager.h
+
+$(PROG): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
diff --git a/TODO b/TODO
@@ -1,5 +1,4 @@
TODO
====
-[ ] Separate main window-related functions into a separate source file
[ ] (non-wmgen) Try out WText; Editor?
diff --git a/TODO.done b/TODO.done
@@ -1,6 +1,7 @@
Done TODOs
==========
+[x] Separate main window-related functions into a separate source file
[x] Info panel
[x] Manpage
[x] Resizeable windows
diff --git a/app.h b/app.h
@@ -27,9 +27,6 @@ struct WMNewApp {
extern struct WMNewApp wma;
void cleanup();
-void create_icon(struct WMNewApp* wma);
-void create_leader_window(struct WMNewApp* wma);
-void create_main_window(struct WMNewApp* wma);
void debug_print_state(struct WMNewApp* wma);
int error(const int code, const char* msg, ...);
void exit_action(WMWidget* self, void* data);
@@ -43,6 +40,5 @@ void open_action(WMWidget* self, void* data);
void open_menu_action(void* data, int code, Time timestamp);
void save_action(WMWidget* self, void* data);
void save_menu_action(void* data, int code, Time timestamp);
-void set_mainwin_title(struct WMNewApp* wma);
void usage(const char* arg0);
void WMLog(const struct WMNewApp* wma, const char* msg, ...);
diff --git a/main.c b/main.c
@@ -1,90 +1,20 @@
-#include <X11/Xutil.h>
#include <X11/Xresource.h>
+#include <X11/Xutil.h>
#include <WMaker.h>
#include <WINGs/WINGs.h>
#include <stdarg.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
+#include <stdlib.h>
#include <unistd.h>
#include "app.h"
#include "infopanel.h"
+#include "mainwindow.h"
#include "menu.h"
#include "windowmanager.h"
#include "config.h"
-#include "appicon.xpm"
-
-/* Assumes main window has been created */
-void
-create_icon(struct WMNewApp* wma)
-{
- RContextAttributes attr;
-
- memset((void*)&attr, 0, sizeof(RContextAttributes));
- attr.flags = (RC_RenderMode | RC_ColorsPerChannel);
- attr.render_mode = 0;
- attr.colors_per_channel = 4;
-
- if (!(wma->rctx
- = RCreateContext(wma->dpy, DefaultScreen(wma->dpy), &attr)))
- exit(error(1, "RCreateContext failed\n"));
- if (!(wma->app_image = RGetImageFromXPMData(wma->rctx, appicon_xpm)))
- exit(error(1, "RGetImageFromXPMData failed\n"));
-
- if (!RConvertImageMask(wma->rctx, wma->app_image, &wma->app_icon,
- &wma->app_mask, 0))
- exit(error(1, "RConvertImageMask failed\n"));
- wma->hints->icon_pixmap = wma->app_icon;
- wma->hints->icon_mask = wma->app_mask;
- wma->hints->flags |= (IconPixmapHint | IconMaskHint);
- XSetWMHints(wma->dpy, WMWidgetXID(wma->mainwin), wma->hints);
-
- if (!(wma->wmpixmap
- = WMCreatePixmapFromRImage(wma->scr, wma->app_image, 0)))
- exit(error(1, "WMCreatePixmapFromRImage failed"));
- WMSetApplicationIconPixmap(wma->scr, wma->wmpixmap);
-}
-
-void
-create_main_window(struct WMNewApp* wma)
-{
- MyGNUstepWMAttributes attributes;
-
- if (!(wma->class_hint = XAllocClassHint()))
- exit(error(1, "XAllocClassHint failed"));
- wma->class_hint->res_name = "wmnewapp";
- wma->class_hint->res_class = "WMNewApp";
-
- wma->mainwin = WMCreateWindow(wma->scr, wma->class_hint->res_name);
- WMRealizeWidget(wma->mainwin);
-
- if (!(wma->hints = XAllocWMHints()))
- exit(error(1, "XAllocWMHints failed"));
- wma->hints->window_group = WMWidgetXID(wma->mainwin);
- wma->hints->flags = WindowGroupHint;
-
- set_mainwin_title(wma);
- WMResizeWidget(wma->mainwin, 640, 480);
- WMSetWindowCloseAction(wma->mainwin, exit_action, wma);
-
- XSetClassHint(wma->dpy, WMWidgetXID(wma->mainwin), wma->class_hint);
- XSetWMHints(wma->dpy, WMWidgetXID(wma->mainwin), wma->hints);
-
- memset((void*)&attributes, 0, sizeof(MyGNUstepWMAttributes));
- attributes.window_style = (WMClosableWindowMask | WMTitledWindowMask
- | WMMiniaturizableWindowMask | WMResizableWindowMask);
- attributes.window_level = WMNormalWindowLevel;
- attributes.extra_flags = GSFullKeyboardEventsFlag;
- attributes.flags
- = (GSWindowStyleAttr | GSWindowLevelAttr | GSExtraFlagsAttr);
- MyWMSetWindowAttributes(wma->dpy, WMWidgetXID(wma->mainwin),
- &attributes);
-
- WMMapSubwidgets(wma->mainwin);
- WMMapWidget(wma->mainwin);
-}
void
debug_print_state(struct WMNewApp* wma)
@@ -251,15 +181,6 @@ save_menu_action(void* data, int code, Time timestamp)
}
void
-set_mainwin_title(struct WMNewApp* wma)
-{
- snprintf(wma->mainwin_title, 4095, mainwin_title_fmt, program_name,
- wma->state.dirty ? "*" : "",
- *(wma->state.filename) ? wma->state.filename : default_filename);
- WMSetWindowTitle(wma->mainwin, wma->mainwin_title);
-}
-
-void
usage(const char* arg0)
{
printf("Usage: %s [-d] [-h]\n", arg0);
diff --git a/mainwindow.c b/mainwindow.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "app.h"
+#include "appicon.xpm"
+#include "mainwindow.h"
+#include "windowmanager.h"
+
+#include "config.h"
+
+/* Assumes main window has been created */
+void
+create_icon(struct WMNewApp* wma)
+{
+ RContextAttributes attr;
+
+ memset((void*)&attr, 0, sizeof(RContextAttributes));
+ attr.flags = (RC_RenderMode | RC_ColorsPerChannel);
+ attr.render_mode = 0;
+ attr.colors_per_channel = 4;
+
+ if (!(wma->rctx
+ = RCreateContext(wma->dpy, DefaultScreen(wma->dpy), &attr)))
+ exit(error(1, "RCreateContext failed\n"));
+ if (!(wma->app_image = RGetImageFromXPMData(wma->rctx, appicon_xpm)))
+ exit(error(1, "RGetImageFromXPMData failed\n"));
+
+ if (!RConvertImageMask(wma->rctx, wma->app_image, &wma->app_icon,
+ &wma->app_mask, 0))
+ exit(error(1, "RConvertImageMask failed\n"));
+ wma->hints->icon_pixmap = wma->app_icon;
+ wma->hints->icon_mask = wma->app_mask;
+ wma->hints->flags |= (IconPixmapHint | IconMaskHint);
+ XSetWMHints(wma->dpy, WMWidgetXID(wma->mainwin), wma->hints);
+
+ if (!(wma->wmpixmap
+ = WMCreatePixmapFromRImage(wma->scr, wma->app_image, 0)))
+ exit(error(1, "WMCreatePixmapFromRImage failed"));
+ WMSetApplicationIconPixmap(wma->scr, wma->wmpixmap);
+}
+
+void
+create_main_window(struct WMNewApp* wma)
+{
+ MyGNUstepWMAttributes attributes;
+
+ if (!(wma->class_hint = XAllocClassHint()))
+ exit(error(1, "XAllocClassHint failed"));
+ wma->class_hint->res_name = "wmnewapp";
+ wma->class_hint->res_class = "WMNewApp";
+
+ wma->mainwin = WMCreateWindow(wma->scr, wma->class_hint->res_name);
+ WMRealizeWidget(wma->mainwin);
+
+ if (!(wma->hints = XAllocWMHints()))
+ exit(error(1, "XAllocWMHints failed"));
+ wma->hints->window_group = WMWidgetXID(wma->mainwin);
+ wma->hints->flags = WindowGroupHint;
+
+ set_mainwin_title(wma);
+ WMResizeWidget(wma->mainwin, 640, 480);
+ WMSetWindowCloseAction(wma->mainwin, exit_action, wma);
+
+ XSetClassHint(wma->dpy, WMWidgetXID(wma->mainwin), wma->class_hint);
+ XSetWMHints(wma->dpy, WMWidgetXID(wma->mainwin), wma->hints);
+
+ memset((void*)&attributes, 0, sizeof(MyGNUstepWMAttributes));
+ attributes.window_style = (WMClosableWindowMask | WMTitledWindowMask
+ | WMMiniaturizableWindowMask | WMResizableWindowMask);
+ attributes.window_level = WMNormalWindowLevel;
+ attributes.extra_flags = GSFullKeyboardEventsFlag;
+ attributes.flags
+ = (GSWindowStyleAttr | GSWindowLevelAttr | GSExtraFlagsAttr);
+ MyWMSetWindowAttributes(wma->dpy, WMWidgetXID(wma->mainwin),
+ &attributes);
+
+ WMMapSubwidgets(wma->mainwin);
+ WMMapWidget(wma->mainwin);
+}
+
+void
+set_mainwin_title(struct WMNewApp* wma)
+{
+ snprintf(wma->mainwin_title, 4095, mainwin_title_fmt, program_name,
+ wma->state.dirty ? "*" : "",
+ *(wma->state.filename) ? wma->state.filename : default_filename);
+ WMSetWindowTitle(wma->mainwin, wma->mainwin_title);
+}
diff --git a/mainwindow.h b/mainwindow.h
@@ -0,0 +1,3 @@
+void create_icon(struct WMNewApp* wma);
+void create_main_window(struct WMNewApp* wma);
+void set_mainwin_title(struct WMNewApp* wma);