чување b06f50e4685a0ae2bd2036664b6807e3d11c6419
родитељ a3bcfc963e9106f02702c21c3ea90eb10e1194da
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 11 Dec 2023 22:34:24 +0100
Adjust info panel and wmgen
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 6, додавања: 167(+), брисања: 31(-)
diff --git a/TODO b/TODO
@@ -1,7 +1,7 @@
TODO
====
-[ ] Info panel
+[x] Info panel
[ ] Manpage
[x] Resizeable windows
[x] Dialogs open in screen center?
diff --git a/config.def.h b/config.def.h
@@ -1,3 +1,5 @@
#define default_filename "Untitled"
#define mainwin_title_fmt "%s - [%s%s]"
#define program_name "WMNewApp"
+#define program_author "Yourname Here"
+#define copy_years "2020-2023"
diff --git a/infopanel.c b/infopanel.c
@@ -1,34 +1,141 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
#include "app.h"
#include "infopanel.h"
+#include "config.h"
+
+static struct WMInfoPanel* ip = NULL;
+
+static size_t
+format_author(char** buf, const char* name)
+{
+ size_t size = 0;
+
+ *buf = NULL;
+ size = strlen("Author") + 2 + strlen(name) + 1 + 1;
+ if (!(*buf = calloc(1, size)))
+ exit(error(1, "calloc failed"));
+ snprintf(*buf, size, "%s: %s", "Author", name);
+
+ return size;
+}
+
+static size_t
+format_copy(char** buf, const char* years)
+{
+ size_t size = 0;
+
+ *buf = NULL;
+ size = strlen("Copyright (C)") + 1 + strlen(years) + 1 + 1;
+ if (!(*buf = calloc(1, size)))
+ exit(error(1, "calloc failed"));
+ snprintf(*buf, size, "%s %s", "Copyright (C) ", years);
+
+ return size;
+}
+
void
-create_info_panel(struct WMNewApp* wma, struct WMInfoPanel* ip)
+close_info_panel(WMWidget* self, void* data)
{
+ struct WMInfoPanel* ip = (struct WMInfoPanel*)data;
+ ip->done = 1;
+}
+
+static struct WMInfoPanel*
+create_info_panel(struct WMNewApp* wma)
+{
+ struct WMInfoPanel* ip = NULL;
WMSize icon_size;
+ WMFont* title_font;
+ WMFont* normal_font;
+ int offset, width, height;
+ char* author = NULL;
+ char* copy = NULL;
+
+ if (!(ip = (struct WMInfoPanel*)calloc(sizeof(struct WMInfoPanel), 1)))
+ exit(error(1, "calloc failed"));
+ memset((void*)ip, 0, sizeof(struct WMInfoPanel));
+ width = 500;
+ height = 300;
+
+ ip->app = wma;
ip->window = WMCreateWindow(wma->scr, "info");
- WMResizeWidget(ip->window, 400, 300);
+ WMResizeWidget(ip->window, width, height);
WMSetWindowTitle(ip->window, "Info");
- WMSetWindowCloseAction(ip->window, hide_info_panel, NULL);
+ WMSetWindowCloseAction(ip->window, close_info_panel, ip);
- icon_size = WMGetPixmapSize(wma->wmpixmap);
+ icon_size = WMGetPixmapSize(wma->wmpixmap);
ip->icon_label = WMCreateLabel(ip->window);
WMResizeWidget(ip->icon_label, icon_size.width, icon_size.height);
- WMMoveWidget(ip->icon_label,
- 80 - icon_size.width,
+ WMMoveWidget(ip->icon_label, 80 - icon_size.width,
80 - icon_size.height);
WMSetLabelImage(ip->icon_label, wma->wmpixmap);
WMSetLabelImagePosition(ip->icon_label, WIPImageOnly);
+
+ title_font = WMBoldSystemFontOfSize(wma->scr, 24);
+ normal_font = WMBoldSystemFontOfSize(wma->scr, 12);
+
+ ip->title_label = WMCreateLabel(ip->window);
+ offset = 55;
+ WMMoveWidget(ip->title_label, 90, (80 - 24) / 2);
+ WMResizeWidget(ip->title_label, width - 70, 2 * (24 + 6));
+ WMSetLabelText(ip->title_label, program_name);
+ WMSetLabelFont(ip->title_label, title_font);
+ offset += 24 + 6;
+
+ ip->author_label = WMCreateLabel(ip->window);
+ WMMoveWidget(ip->author_label, 80 - icon_size.width, offset);
+ WMResizeWidget(ip->author_label, width - (80 - icon_size.width) - 20,
+ 20);
+ format_author(&author, program_author);
+ WMSetLabelText(ip->author_label, author);
+ WMSetLabelFont(ip->author_label, normal_font);
+ free(author);
+ offset += 12 + 6;
+
+ ip->copy_label = WMCreateLabel(ip->window);
+ WMMoveWidget(ip->copy_label, 80 - icon_size.width, offset);
+ WMResizeWidget(ip->copy_label, width - (80 - icon_size.width) - 20, 20);
+ format_copy(©, copy_years);
+ WMLog(ip->app, copy);
+ WMSetLabelText(ip->copy_label, copy);
+ WMSetLabelFont(ip->copy_label, normal_font);
+ free(copy);
+
WMRealizeWidget(ip->window);
WMMapSubwidgets(ip->window);
+ WMReleaseFont(title_font);
+ WMReleaseFont(normal_font);
+
+ return ip;
}
void
-hide_info_panel()
+destroy_info_panel(struct WMInfoPanel* ip)
{
+ WMUnmapWidget(ip->window);
+ WMDestroyWidget(ip->window);
+ free((void*)ip);
+ ip = NULL;
}
void
-show_info_panel()
+run_info_panel(struct WMNewApp* wma)
{
+ if (!(ip = create_info_panel(wma)))
+ exit(error(1, "create_info_panel failed"));
+
+ WMMapWidget(ip->window);
+
+ while (!(ip->done))
+ {
+ XEvent event;
+ WMNextEvent(ip->app->dpy, &event);
+ WMHandleEvent(&event);
+ }
+ destroy_info_panel(ip);
}
diff --git a/infopanel.h b/infopanel.h
@@ -1,8 +1,13 @@
struct WMInfoPanel {
+ struct WMNewApp* app;
WMWindow* window;
WMWidget* icon_label;
+ WMWidget* title_label;
+ WMWidget* author_label;
+ WMWidget* copy_label;
+ int done;
};
-void create_info_panel(struct WMNewApp* wma, struct WMInfoPanel* ip);
-void hide_info_panel();
-void show_info_panel();
+void close_info_panel(WMWidget* self, void* data);
+void destroy_info_panel(struct WMInfoPanel* ip);
+void run_info_panel(struct WMNewApp* wma);
diff --git a/main.c b/main.c
@@ -200,15 +200,14 @@ info_panel_action(WMWidget* self, void* data)
{
struct WMNewApp* wma = (struct WMNewApp*)data;
WMLog(wma, "info_panel_action called\n");
- show_info_panel();
- not_implemented(self, wma);
+ run_info_panel(wma);
}
void
info_panel_menu_action(void* data, int code, Time timestamp)
{
- struct WMNewApp* wma = (struct WMNewApp*)data;
- info_panel_action(wma->mainwin, wma);
+ struct WMInfoPanel* ip = (struct WMInfoPanel*)data;
+ info_panel_action(ip->app, ip);
}
void
@@ -330,7 +329,6 @@ main(int argc, char** argv)
create_main_window(&wma);
create_icon(&wma);
create_main_menu(&wma);
- // create_info_panel();
WMSetFocusToWidget(wma.mainwin);
XSaveContext(wma.dpy, WMWidgetXID(wma.mainwin), wma.xctx, NULL);
diff --git a/wmgen b/wmgen
@@ -9,14 +9,14 @@ prompt_for_vars()
printf "Name of the new application (whitespace or just Enter="\
"quit): "
IFS= read -r papp_name
- if [ ! $papp_name ]; then
+ if [ ! "$papp_name" ]; then
exit
fi
app_name=$(echo "$papp_name" | tr -dc [A-Za-z])
else
printf "Name of the new application [%s]: " "$app_name"
IFS= read -r papp_name
- if [ $papp_name ]; then
+ if [ "$papp_name" ]; then
app_name=$(echo "$papp_name" | tr -dc [A-Za-z])
fi
fi
@@ -24,16 +24,28 @@ prompt_for_vars()
app_dir=$(echo "$app_name" | tr [A-Z] [a-z])
printf "Application directory [%s]: " "$app_dir"
IFS= read -r papp_dir
- if [ $papp_dir ]; then
+ if [ "$papp_dir" ]; then
app_dir="$papp_dir"
fi
res_name=$(echo "$app_name" | tr [A-Z] [a-z])
printf "Leader window resource name [%s]: " "$res_name"
IFS= read -r pres_name
- if [ $pres_name ]; then
+ if [ "$pres_name" ]; then
res_name="$pres_name"
fi
+
+ printf "Author name [%s]: " "$author_name"
+ IFS= read -r pauthor_name
+ if [ "$pauthor_name" ]; then
+ author_name="$pauthor_name"
+ fi
+
+ printf "Copyright years [%s]: " "$copy_years"
+ IFS= read -r pcopy_years
+ if [ "$pcopy_years" ]; then
+ copy_years="$pcopy_years"
+ fi
}
while true; do
@@ -48,6 +60,8 @@ App name: $app_name
App directory: $full_app_dir
Leader window resource name: $res_name ($res_name.$app_name)
Main window resource name: mainwin.$app_name
+Author: $author_name
+Copyright years: $copy_years
License: GPL v3+ (copy your own if not)
===========================================================================
ENDSUMMARY
@@ -63,20 +77,28 @@ ENDSUMMARY
done
done
+subst_copy()
+{
+ file=$1
+ app_dir=$2
+ sed -e 's/WMNewApp/'"$app_name"'/g' \
+ -e 's/wmnewapp/'"$res_name"'/g' \
+ -e 's/Yourname Here/'"$author_name"'/g' \
+ -e 's/2020-2023/'"$copy_years"'/g' \
+ "$file" > "$app_dir"/"$file"
+}
+
set -x
mkdir -p "$full_app_dir"
sed 's/^\(PROG.*= \).*/\1'$app_name'/' Makefile > "$full_app_dir"/Makefile
-sed 's/WMNewApp/'$app_name'/g;s/wmnewapp/'$res_name'/g' app.h \
- > "$full_app_dir"/app.h
+subst_copy app.h "$full_app_dir"
cp appicon.xpm "$full_app_dir"/appicon.xpm
-sed 's/WMNewApp/'$app_name'/g;s/wmnewapp/'$res_name'/g' config.def.h \
- > "$full_app_dir"/config.def.h
-cp infopanel.h "$full_app_dir"/infopanel.h
-cp infopanel.c "$full_app_dir"/infopanel.c
-sed 's/WMNewApp/'$app_name'/g;s/wmnewapp/'$res_name'/g' main.c \
- > "$full_app_dir"/main.c
-cp menu.c "$full_app_dir"/menu.c
-cp menu.h "$full_app_dir"/menu.h
+subst_copy config.def.h "$full_app_dir"
+subst_copy infopanel.h "$full_app_dir"
+subst_copy infopanel.c "$full_app_dir"
+subst_copy main.c "$full_app_dir"
+subst_copy menu.c "$full_app_dir"
+subst_copy menu.h "$full_app_dir"
cp windowmanager.c "$full_app_dir"/windowmanager.c
cp windowmanager.h "$full_app_dir"/windowmanager.h
cp LICENSE "$full_app_dir"/LICENSE
@@ -90,6 +112,8 @@ Describe your newly generated application
License
-------
+Copyright (C) $copy_years $author_name
+
License description
ENDREADME
set +x