commit 344c3b8431b75133a05f992edf80263490c8a80d Author: Sasha Koshka Date: Fri Nov 3 17:59:24 2023 -0400 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6f436ae --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab +indent_size = 8 +charset = utf-8 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86b34b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +lib/ +~* diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..4ce85c1 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,34 @@ +# Installing + +## Dependencies + +- Xlib +- Xt +- Motif +- A C compiler + +Installing via APK: + +```sh +# apk add libx11 libx11-dev libxt libxt-dev motif motif-dev clang +``` + +## libXmd + +Before building any of the applications you will need to build libXmd, which +contains code common to most of them: + +``` +# cd libXmd +# ./build.sh install +``` + +## Individual applications + +Individual applications can be installed using `./build.sh` in their respective +subdirectories: + +``` +# cd +# ./build.sh install +``` diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef07731 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Xmd + +A collection of X11 Motif desktop utilities written in C99. diff --git a/libXmd/XmdIcon.c b/libXmd/XmdIcon.c new file mode 100644 index 0000000..9b8d633 --- /dev/null +++ b/libXmd/XmdIcon.c @@ -0,0 +1,14 @@ +#include + +Pixmap _XmdLoadBitmapIcon (Widget widget, unsigned char *bits, int width, int height) { + Pixel fg, bg; + XtVaGetValues (widget, + XmNforeground, &fg, + XmNbackground, &bg, + NULL); + return XCreatePixmapFromBitmapData ( + XtDisplay (widget), + RootWindowOfScreen(XtScreen(widget)), + (char *)(bits), width, height, + fg, bg, DefaultDepthOfScreen(XtScreen(widget))); +} diff --git a/libXmd/build.sh b/libXmd/build.sh new file mode 100755 index 0000000..6f85513 --- /dev/null +++ b/libXmd/build.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +. ../scripts/flags.sh + +function build() { + cc $CFLAGS -shared -o "lib/libXmd.so" *.c || \ + echo "XXX FAIL!" +} + +function clean() { + rm -f lib/* +} + +case "$1" in +install) + clean; build + cp lib/*.so "$PREFIX/lib" + cp include/Xmd/*.h "$PREFIX/include/Xmd" + clean + ;; +clean) + clean + ;; +*) + build +esac diff --git a/libXmd/include/Xmd/Icon.h b/libXmd/include/Xmd/Icon.h new file mode 100644 index 0000000..b709e7b --- /dev/null +++ b/libXmd/include/Xmd/Icon.h @@ -0,0 +1,13 @@ +#ifndef _XmdIcon_h +#define _XmdIcon_h + +#include +#include +#include + +/* XmdLoadBitmapIcon is a macro that loads an icon with the specified name. That Icon must + be #include'd in your code somewhere. The name parameter must be a token, not a string. */ +#define XmdLoadBitmapIcon(widget, name) _XmdLoadBitmapIcon(widget, name##_bits, name##_width, name##_height) +Pixmap _XmdLoadBitmapIcon (Widget widget, unsigned char *bits, int width, int height); + +#endif diff --git a/libXmd/include/Xmd/Launcher.h b/libXmd/include/Xmd/Launcher.h new file mode 100644 index 0000000..e24ec80 --- /dev/null +++ b/libXmd/include/Xmd/Launcher.h @@ -0,0 +1,13 @@ +#ifndef _XmdLauncher_h +#define _XmdLauncher_h + +#include +#include +#include + +typedef struct { + Pixmap icon; + const char *command; +} XmdLauncher; + +#endif diff --git a/scripts/buildapp.sh b/scripts/buildapp.sh new file mode 100755 index 0000000..e93fecf --- /dev/null +++ b/scripts/buildapp.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. `dirname $0`/flags.sh + +function build() { + mkdir -p bin + cc $CFLAGS -c -o "bin/$1.o" src/*.c && \ + cc -o "bin/$1" "bin/$1.o" $APP_LIBS || \ + echo "XXX FAIL!" +} + +function clean() { + rm -f bin/* +} + +case "$2" in +install) + clean; build "$1" + cp "bin/$1" "$PREFIX/bin" + clean + ;; +clean) + clean + ;; +*) + build "$1" +esac diff --git a/scripts/flags.sh b/scripts/flags.sh new file mode 100644 index 0000000..38d9d40 --- /dev/null +++ b/scripts/flags.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +CFLAGS="-std=c99 -Wall -Wextra -Werror -fPIC" +PREFIX="/usr/local" +APP_LIBS="-lXmd -lXm -lXt -lX11" diff --git a/xmbattery/..o b/xmbattery/..o new file mode 100644 index 0000000..6774986 Binary files /dev/null and b/xmbattery/..o differ diff --git a/xmbattery/.o b/xmbattery/.o new file mode 100644 index 0000000..3f52db4 Binary files /dev/null and b/xmbattery/.o differ diff --git a/xmbattery/build.sh b/xmbattery/build.sh new file mode 100755 index 0000000..4e43ba8 --- /dev/null +++ b/xmbattery/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +../scripts/buildapp.sh xmbattery "$@" diff --git a/xmbattery/src/icons/charging.xbm b/xmbattery/src/icons/charging.xbm new file mode 100644 index 0000000..6a4dabb --- /dev/null +++ b/xmbattery/src/icons/charging.xbm @@ -0,0 +1,15 @@ +#define charging_width 48 +#define charging_height 24 +static unsigned char charging_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x33, + 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x37, 0x0c, 0xe6, 0xff, 0x3f, 0xfe, 0x37, + 0x46, 0xec, 0xff, 0x07, 0xff, 0x67, 0xe6, 0xec, 0xff, 0x80, 0xff, 0x6f, + 0xe6, 0xec, 0x1f, 0xc0, 0xff, 0x6f, 0xe6, 0xec, 0x07, 0xe3, 0xff, 0x6f, + 0xe6, 0xec, 0xff, 0x63, 0xf0, 0x6f, 0xe6, 0xec, 0xff, 0x01, 0xfc, 0x6f, + 0xe6, 0xec, 0xff, 0x80, 0xff, 0x6f, 0x46, 0xec, 0x7f, 0xf0, 0xff, 0x67, + 0x0c, 0xe6, 0x3f, 0xfe, 0xff, 0x37, 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x37, + 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x33, 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/icons/error.xbm b/xmbattery/src/icons/error.xbm new file mode 100644 index 0000000..2e91fd4 --- /dev/null +++ b/xmbattery/src/icons/error.xbm @@ -0,0 +1,15 @@ +#define error_width 48 +#define error_height 24 +static unsigned char error_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x30, + 0x0c, 0x06, 0x40, 0x80, 0x00, 0x30, 0x0c, 0x06, 0xe0, 0xc0, 0x01, 0x30, + 0x46, 0x0c, 0xc0, 0xe1, 0x00, 0x60, 0xe6, 0x0c, 0x80, 0x73, 0x00, 0x60, + 0xe6, 0x0c, 0x00, 0x3f, 0x00, 0x60, 0xe6, 0x0c, 0x00, 0x1e, 0x00, 0x60, + 0xe6, 0x0c, 0x00, 0x1e, 0x00, 0x60, 0xe6, 0x0c, 0x00, 0x3f, 0x00, 0x60, + 0xe6, 0x0c, 0x80, 0x73, 0x00, 0x60, 0x46, 0x0c, 0xc0, 0xe1, 0x00, 0x60, + 0x0c, 0x06, 0xe0, 0xc0, 0x01, 0x30, 0x0c, 0x06, 0x40, 0x80, 0x00, 0x30, + 0x0c, 0x06, 0x00, 0x00, 0x00, 0x30, 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/icons/level0.xbm b/xmbattery/src/icons/level0.xbm new file mode 100644 index 0000000..7afadbb --- /dev/null +++ b/xmbattery/src/icons/level0.xbm @@ -0,0 +1,15 @@ +#define level0_width 48 +#define level0_height 24 +static unsigned char level0_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x32, + 0x0c, 0x06, 0x00, 0x02, 0x00, 0x37, 0x0c, 0x06, 0x00, 0x07, 0x00, 0x37, + 0x46, 0x0c, 0x00, 0x07, 0x00, 0x67, 0xe6, 0x0c, 0x00, 0x07, 0x80, 0x6f, + 0xe6, 0x0c, 0x00, 0x07, 0x80, 0x6f, 0xe6, 0x0c, 0x00, 0x07, 0x80, 0x6f, + 0xe6, 0x0c, 0x00, 0x02, 0x80, 0x6f, 0xe6, 0x0c, 0x00, 0x02, 0x80, 0x6f, + 0xe6, 0x0c, 0x00, 0x00, 0x80, 0x6f, 0x46, 0x0c, 0x00, 0x02, 0x00, 0x67, + 0x0c, 0x06, 0x00, 0x07, 0x00, 0x37, 0x0c, 0x06, 0x00, 0x02, 0x00, 0x37, + 0x0c, 0x06, 0x00, 0x00, 0x00, 0x32, 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/icons/level1.xbm b/xmbattery/src/icons/level1.xbm new file mode 100644 index 0000000..914ff86 --- /dev/null +++ b/xmbattery/src/icons/level1.xbm @@ -0,0 +1,15 @@ +#define level1_width 48 +#define level1_height 24 +static unsigned char level1_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0x00, 0x00, 0xfe, 0x33, + 0x0c, 0x06, 0x00, 0x00, 0xff, 0x37, 0x0c, 0x06, 0x00, 0x00, 0xff, 0x37, + 0x46, 0x0c, 0x00, 0x00, 0xff, 0x67, 0xe6, 0x0c, 0x00, 0x80, 0xff, 0x6f, + 0xe6, 0x0c, 0x00, 0x80, 0xff, 0x6f, 0xe6, 0x0c, 0x00, 0x80, 0xff, 0x6f, + 0xe6, 0x0c, 0x00, 0x80, 0xff, 0x6f, 0xe6, 0x0c, 0x00, 0x80, 0xff, 0x6f, + 0xe6, 0x0c, 0x00, 0x80, 0xff, 0x6f, 0x46, 0x0c, 0x00, 0x00, 0xff, 0x67, + 0x0c, 0x06, 0x00, 0x00, 0xff, 0x37, 0x0c, 0x06, 0x00, 0x00, 0xff, 0x37, + 0x0c, 0x06, 0x00, 0x00, 0xfe, 0x33, 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/icons/level2.xbm b/xmbattery/src/icons/level2.xbm new file mode 100644 index 0000000..741d49f --- /dev/null +++ b/xmbattery/src/icons/level2.xbm @@ -0,0 +1,15 @@ +#define level2_width 48 +#define level2_height 24 +static unsigned char level2_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0x00, 0xf8, 0xff, 0x33, + 0x0c, 0x06, 0x00, 0xfc, 0xff, 0x37, 0x0c, 0x06, 0x00, 0xfc, 0xff, 0x37, + 0x46, 0x0c, 0x00, 0xfc, 0xff, 0x67, 0xe6, 0x0c, 0x00, 0xfe, 0xff, 0x6f, + 0xe6, 0x0c, 0x00, 0xfe, 0xff, 0x6f, 0xe6, 0x0c, 0x00, 0xfe, 0xff, 0x6f, + 0xe6, 0x0c, 0x00, 0xfe, 0xff, 0x6f, 0xe6, 0x0c, 0x00, 0xfe, 0xff, 0x6f, + 0xe6, 0x0c, 0x00, 0xfe, 0xff, 0x6f, 0x46, 0x0c, 0x00, 0xfc, 0xff, 0x67, + 0x0c, 0x06, 0x00, 0xfc, 0xff, 0x37, 0x0c, 0x06, 0x00, 0xfc, 0xff, 0x37, + 0x0c, 0x06, 0x00, 0xf8, 0xff, 0x33, 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/icons/level3.xbm b/xmbattery/src/icons/level3.xbm new file mode 100644 index 0000000..c5eac37 --- /dev/null +++ b/xmbattery/src/icons/level3.xbm @@ -0,0 +1,15 @@ +#define level3_width 48 +#define level3_height 24 +static unsigned char level3_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0xfe, 0xff, 0xff, 0x33, + 0x0c, 0x06, 0xff, 0xff, 0xff, 0x37, 0x0c, 0x06, 0xff, 0xff, 0xff, 0x37, + 0x46, 0x0c, 0xff, 0xff, 0xff, 0x67, 0xe6, 0x8c, 0xff, 0xff, 0xff, 0x6f, + 0xe6, 0x8c, 0xff, 0xff, 0xff, 0x6f, 0xe6, 0x8c, 0xff, 0xff, 0xff, 0x6f, + 0xe6, 0x8c, 0xff, 0xff, 0xff, 0x6f, 0xe6, 0x8c, 0xff, 0xff, 0xff, 0x6f, + 0xe6, 0x8c, 0xff, 0xff, 0xff, 0x6f, 0x46, 0x0c, 0xff, 0xff, 0xff, 0x67, + 0x0c, 0x06, 0xff, 0xff, 0xff, 0x37, 0x0c, 0x06, 0xff, 0xff, 0xff, 0x37, + 0x0c, 0x06, 0xfe, 0xff, 0xff, 0x33, 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/icons/level4.xbm b/xmbattery/src/icons/level4.xbm new file mode 100644 index 0000000..0944b86 --- /dev/null +++ b/xmbattery/src/icons/level4.xbm @@ -0,0 +1,15 @@ +#define level4_width 48 +#define level4_height 24 +static unsigned char level4_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x33, + 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x37, 0x0c, 0xe6, 0xff, 0xff, 0xff, 0x37, + 0x46, 0xec, 0xff, 0xff, 0xff, 0x67, 0xe6, 0xec, 0xff, 0xff, 0xff, 0x6f, + 0xe6, 0xec, 0xff, 0xff, 0xff, 0x6f, 0xe6, 0xec, 0xff, 0xff, 0xff, 0x6f, + 0xe6, 0xec, 0xff, 0xff, 0xff, 0x6f, 0xe6, 0xec, 0xff, 0xff, 0xff, 0x6f, + 0xe6, 0xec, 0xff, 0xff, 0xff, 0x6f, 0x46, 0xec, 0xff, 0xff, 0xff, 0x67, + 0x0c, 0xe6, 0xff, 0xff, 0xff, 0x37, 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x37, + 0x0c, 0xf6, 0xff, 0xff, 0xff, 0x33, 0x18, 0x03, 0x00, 0x00, 0x00, 0x18, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/icons/not.xbm b/xmbattery/src/icons/not.xbm new file mode 100644 index 0000000..fab9cd6 --- /dev/null +++ b/xmbattery/src/icons/not.xbm @@ -0,0 +1,15 @@ +#define not_width 48 +#define not_height 24 +static unsigned char not_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa0, 0xaa, 0xaa, 0xaa, 0xaa, 0x02, 0x50, 0x55, 0x55, 0x55, 0x55, 0x05, + 0x08, 0x02, 0x00, 0x00, 0x00, 0x08, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10, + 0x08, 0x02, 0x00, 0x00, 0x00, 0x20, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10, + 0x02, 0x08, 0x00, 0x00, 0x00, 0x20, 0x44, 0x04, 0x00, 0x00, 0x00, 0x40, + 0xa2, 0x08, 0x00, 0x00, 0x00, 0x20, 0x44, 0x04, 0x00, 0x00, 0x00, 0x40, + 0xa2, 0x08, 0x00, 0x00, 0x00, 0x20, 0x44, 0x04, 0x00, 0x00, 0x00, 0x40, + 0xa2, 0x08, 0x00, 0x00, 0x00, 0x20, 0x44, 0x04, 0x00, 0x00, 0x00, 0x40, + 0x08, 0x02, 0x00, 0x00, 0x00, 0x20, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10, + 0x08, 0x02, 0x00, 0x00, 0x00, 0x20, 0x10, 0x01, 0x00, 0x00, 0x00, 0x10, + 0xa0, 0xaa, 0xaa, 0xaa, 0xaa, 0x0a, 0x40, 0x55, 0x55, 0x55, 0x55, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmbattery/src/main.c b/xmbattery/src/main.c new file mode 100644 index 0000000..ad474a0 --- /dev/null +++ b/xmbattery/src/main.c @@ -0,0 +1,242 @@ +/* C99 */ + +#define _XOPEN_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "icons/level0.xbm" +#include "icons/level1.xbm" +#include "icons/level2.xbm" +#include "icons/level3.xbm" +#include "icons/level4.xbm" +#include "icons/charging.xbm" +#include "icons/error.xbm" +#include "icons/not.xbm" + +typedef enum { + BatteryStateCharging, + BatteryStateNotCharging, + BatteryStateFull, + BatteryStateDischarging, + BatteryStateError +} BatteryState; + +typedef struct { + int level; + BatteryState state; + int hours; + int minutes; + int seconds; +} BatteryInfo; + +BatteryInfo getBatteryInfo (void); +Pixmap selectBatteryIcon (BatteryInfo); +void loadAllPixmaps (Widget); +void batteryPoll (XtPointer, XtIntervalId *); +void resetBatteryPollTimeout(void); +void batteryInfoDialog (Widget, XtPointer, XtPointer); + +Pixmap levels[8] = { 0 }; +XtAppContext application; +Widget icon; +Widget text; +Widget layout; +Widget window; + +int main (int argc, char *argv[]) { + window = XtVaAppInitialize ( + &application, "Battery", + NULL, 0, + &argc, argv, + NULL, + XmNtitle, "Battery", + NULL); + + layout = XtVaCreateWidget ( + "layout", xmRowColumnWidgetClass, window, + XmNorientation, XmHORIZONTAL, + NULL); + + loadAllPixmaps(layout); + icon = XtVaCreateManagedWidget ( + "batteryIcon", xmPushButtonWidgetClass, layout, + XmNleftAttachment, XmATTACH_FORM, + XmNlabelType, XmPIXMAP, + NULL); + XtAddCallback(icon, XmNactivateCallback, batteryInfoDialog, NULL); + + XtVaCreateManagedWidget ( + "separator", xmSeparatorWidgetClass, layout, + XmNorientation, XmVERTICAL, + NULL); + + text = XtVaCreateManagedWidget ( + "text", xmLabelGadgetClass, layout, + XmNalignment, XmALIGNMENT_CENTER, + NULL); + + batteryPoll(NULL, NULL); + + XtManageChild(layout); + XtRealizeWidget(window); + XtAppMainLoop(application); +} + +BatteryInfo getBatteryInfo (void) { + BatteryInfo result = { 0 }; + char charging[16] = { 0 }; + int battery; + + FILE *stream = popen("acpi -b", "r"); + if (stream == NULL) { + result.state = BatteryStateError; + return result; + } + fscanf ( + stream, "Battery %d: %16s %d%%, %d:%d:%d", + &battery, charging, &result.level, + &result.hours, &result.minutes, &result.seconds); + + switch (charging[0]) { + case 'C': result.state = BatteryStateCharging; break; + case 'N': result.state = BatteryStateNotCharging; break; + case 'D': result.state = BatteryStateDischarging; break; + case 'F': result.state = BatteryStateFull; break; + default: result.state = BatteryStateError; break; + } + if (pclose(stream) != 0) { + result.state = BatteryStateError; + } + return result; +} + +Pixmap selectBatteryIcon (BatteryInfo info) { + if (info.state == BatteryStateCharging) { + return levels[5]; + } else if (info.state == BatteryStateNotCharging) { + return levels[7]; + } else if (info.state == BatteryStateError) { + return levels[6]; + } else if (info.level < 15) { + return levels[0]; + } else if (info.level < 35) { + return levels[1]; + } else if (info.level < 65) { + return levels[2]; + } else if (info.level < 85) { + return levels[3]; + } else { + return levels[4]; + } +} + +void loadAllPixmaps (Widget widget) { + levels[0] = XmdLoadBitmapIcon(widget, level0); + levels[1] = XmdLoadBitmapIcon(widget, level1); + levels[2] = XmdLoadBitmapIcon(widget, level2); + levels[3] = XmdLoadBitmapIcon(widget, level3); + levels[4] = XmdLoadBitmapIcon(widget, level4); + levels[5] = XmdLoadBitmapIcon(widget, charging); + levels[6] = XmdLoadBitmapIcon(widget, error); + levels[7] = XmdLoadBitmapIcon(widget, not); +} + +void batteryPoll (XtPointer clientData, XtIntervalId *timer) { + (void)(clientData); + (void)(timer); + BatteryInfo info = getBatteryInfo(); + + XtVaSetValues ( + icon, + XmNlabelType, XmPIXMAP, + XmNlabelPixmap, selectBatteryIcon(info), + NULL); + XtVaSetValues ( + window, + XmNiconPixmap, selectBatteryIcon(info), + NULL); + + #define BUFFER_LEN 32 + char buffer[BUFFER_LEN]; + snprintf(buffer, BUFFER_LEN, "%d%%", info.level); + #undef BUFFER_LEN + + /* if we don't unmanage and then re-manage the child, the text flies to + * the top which is rather annoying. this little quirk bent me over and + * fucked me for hours. */ + XtUnmanageChild(text); + XmString string = XmStringCreateLocalized(buffer); + XtVaSetValues ( + text, + XmNlabelString, string, + NULL); + XmStringFree(string); + XtManageChild(text); + + resetBatteryPollTimeout(); +} + +void resetBatteryPollTimeout (void) { + XtAppAddTimeOut(application, 2000, batteryPoll, NULL); +} + +void batteryInfoDialog (Widget button, XtPointer clientData, XtPointer callData) { + (void)(clientData); + (void)(callData); + + BatteryInfo info = getBatteryInfo(); + + static const char *states[] = { + "Charging", + "Full", + "Discharging", + "Error" + }; + + #define BUFFER_LEN 48 + char timeBuffer[BUFFER_LEN] = { 0 }; + switch (info.state) { + case BatteryStateCharging: + snprintf ( + timeBuffer, BUFFER_LEN, "\n%d:%02d:%02d until charged.", + info.hours, info.minutes, info.seconds); + break; + case BatteryStateDischarging: + snprintf ( + timeBuffer, BUFFER_LEN, "\n%d:%02d:%02d until empty.", + info.hours, info.minutes, info.seconds); + break; + default: + } + #undef BUFFER_LEN + #define BUFFER_LEN 128 + char messageBuffer[BUFFER_LEN]; + snprintf ( + messageBuffer, BUFFER_LEN, "%d%%, %s%s", + info.level, states[info.state], timeBuffer); + #undef BUFFER_LEN + + Arg args[5] = { 0 }; + int n = 0; + XmString message = XmStringCreateLocalized(messageBuffer); + XtSetArg(args[n], XmNmessageString, message); n ++; + XmString title = XmStringCreateLocalized("Battery Status"); + XtSetArg(args[n], XmNdialogTitle, title); n ++; + + Widget dialog = XmCreateInformationDialog(button, "batteryInfo", args, n); + + XmStringFree(message); + XmStringFree(title); + + XtManageChild(dialog); + XtPopup(XtParent(dialog), XtGrabNone); +} diff --git a/xmbrightness/build.sh b/xmbrightness/build.sh new file mode 100755 index 0000000..d7847b7 --- /dev/null +++ b/xmbrightness/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +../scripts/buildapp.sh xmbrightness "$@" diff --git a/xmbrightness/src/main.c b/xmbrightness/src/main.c new file mode 100644 index 0000000..9e324ab --- /dev/null +++ b/xmbrightness/src/main.c @@ -0,0 +1,86 @@ +/* C99 */ + +#define _XOPEN_SOURCE +#include +#include +#include +#include +#include +#include +#include + +void valueChanged (Widget, XtPointer, XtPointer); +void setBrightness (int); +int getBrightness (); +int getMaxBrightness (); + +int main (int argc, char *argv[]) { + XtAppContext application; + Widget window = XtVaAppInitialize ( + &application, "Brightness", + NULL, 0, + &argc, argv, + NULL, + XmNtitle, "Battery", + NULL); + + int level = getBrightness(); + int max = getMaxBrightness(); + int percent = + (float)(level) / + (float)(max) * 100; + + Widget scale = XtVaCreateManagedWidget ( + "Brightness", xmScaleWidgetClass, window, + XmNmaximum, 100, + XmNminimum, 1, + XmNvalue, percent, + NULL); + XtAddCallback(scale, XmNvalueChangedCallback, valueChanged, NULL); + + XtVaSetValues(window, XmNmwmDecorations, MWM_DECOR_BORDER, NULL); + XtVaSetValues(window, XmNmwmFunctions, MWM_FUNC_RESIZE, NULL); + + //XtVaSetValues(window, XtNheight, 400, NULL); + //XtVaSetValues(window, XtNwidth, 400, NULL); + + XtRealizeWidget(window); + XtAppMainLoop(application); +} + +void valueChanged (Widget scale, XtPointer clientData, XtPointer callData) { + (void)(scale); + (void)(clientData); + XmScaleCallbackStruct *event = (XmScaleCallbackStruct *)(callData); + setBrightness(event->value); +} + +void setBrightness (int level) { + char command[32] = { 0 }; + snprintf(command, 32, "brightnessctl s %d%% -q", level); + system(command); +} + +int getBrightness () { + FILE *stream = popen("brightnessctl g", "r"); + if (stream == NULL) { + fprintf(stderr, "ERR could not get brightness\n"); + return 1; + } + int result = 1; + fscanf(stream, "%d", &result); + pclose(stream); + return result; +} + +int getMaxBrightness () { + FILE *stream = popen("brightnessctl m", "r"); + if (stream == NULL) { + fprintf(stderr, "ERR could not get brightness\n"); + return 1; + } + int result = 1; + fscanf(stream, "%d", &result); + pclose(stream); + return result; +} diff --git a/xmpanel/build.sh b/xmpanel/build.sh new file mode 100755 index 0000000..b773df2 --- /dev/null +++ b/xmpanel/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +../scripts/buildapp.sh xmpanel "$@" diff --git a/xmpanel/src/icons/appCalculator.xbm b/xmpanel/src/icons/appCalculator.xbm new file mode 100644 index 0000000..5893970 --- /dev/null +++ b/xmpanel/src/icons/appCalculator.xbm @@ -0,0 +1,27 @@ +#define appCalculator_width 48 +#define appCalculator_height 48 +static unsigned char appCalculator_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xdf, 0x00, + 0x00, 0x13, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x5b, 0x62, 0x00, 0xd8, 0x00, + 0x00, 0x53, 0x4a, 0x00, 0xc8, 0x00, 0x00, 0xdb, 0x48, 0x05, 0xd8, 0x00, + 0x00, 0x13, 0x00, 0x00, 0xc8, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xdf, 0x00, + 0x00, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xdf, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xdf, 0x00, + 0x00, 0xf3, 0xff, 0xcf, 0xcf, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0xf3, 0xff, 0xcf, 0xcf, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xdf, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xdf, 0x00, + 0x00, 0xf3, 0xff, 0xcf, 0xcf, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0x13, 0x42, 0x48, 0xc8, 0x00, 0x00, 0x1b, 0x42, 0x78, 0xd8, 0x00, + 0x00, 0xf3, 0xff, 0xcf, 0xcf, 0x00, 0x00, 0xfb, 0xff, 0xff, 0xdf, 0x00, + 0x00, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmpanel/src/icons/appEditor.xbm b/xmpanel/src/icons/appEditor.xbm new file mode 100644 index 0000000..e86bf27 --- /dev/null +++ b/xmpanel/src/icons/appEditor.xbm @@ -0,0 +1,27 @@ +#define appEditor_width 48 +#define appEditor_height 48 +static unsigned char appEditor_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0x01, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x01, + 0x80, 0x01, 0x00, 0x00, 0x05, 0x01, 0x80, 0x01, 0x00, 0x00, 0x09, 0x01, + 0x80, 0x01, 0x00, 0x00, 0x11, 0x01, 0x80, 0xf1, 0x6f, 0x00, 0x21, 0x01, + 0x80, 0x01, 0x00, 0x00, 0x7f, 0x01, 0x80, 0x71, 0x02, 0x00, 0xfe, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x91, 0x3f, 0x0f, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0xf1, 0xdc, 0x7b, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0xf1, 0x8f, 0xff, 0xc7, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x71, 0x07, 0x00, 0xc0, 0x01, 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x81, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x71, 0x07, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, + 0x80, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x80, 0xff, 0xff, 0xff, 0xff, 0x01, + 0x80, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmpanel/src/icons/appFiles.xbm b/xmpanel/src/icons/appFiles.xbm new file mode 100644 index 0000000..2c6abc3 --- /dev/null +++ b/xmpanel/src/icons/appFiles.xbm @@ -0,0 +1,27 @@ +#define appFiles_width 48 +#define appFiles_height 48 +static unsigned char appFiles_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0x06, 0x00, 0x00, 0x60, 0x00, 0x00, 0xf6, 0xff, 0xff, 0x6f, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, 0x00, 0x56, 0x00, 0x00, 0x6a, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, 0x00, 0x16, 0xf8, 0x1f, 0x68, 0x00, + 0x00, 0x16, 0x08, 0x10, 0x68, 0x00, 0x00, 0x16, 0x08, 0x10, 0x68, 0x00, + 0x00, 0x16, 0xf8, 0x1f, 0x68, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x16, 0x08, 0x10, 0x68, 0x00, 0x00, 0x16, 0xf8, 0x1f, 0x68, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x56, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0xf6, 0xff, 0xff, 0x6f, 0x00, 0x00, 0x06, 0x00, 0x00, 0x60, 0x00, + 0x00, 0xf6, 0xff, 0xff, 0x6f, 0x00, 0x00, 0x36, 0x00, 0x00, 0x6c, 0x00, + 0x00, 0xf6, 0xff, 0xff, 0x6f, 0x00, 0x00, 0x36, 0x00, 0x00, 0x6c, 0x00, + 0x00, 0xf6, 0xff, 0xff, 0x6f, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x56, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x16, 0xf8, 0x1f, 0x68, 0x00, 0x00, 0x16, 0x08, 0x10, 0x68, 0x00, + 0x00, 0x16, 0x08, 0x10, 0x68, 0x00, 0x00, 0x16, 0xf8, 0x1f, 0x68, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, 0x00, 0x16, 0x08, 0x10, 0x68, 0x00, + 0x00, 0x16, 0xf8, 0x1f, 0x68, 0x00, 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x16, 0x00, 0x00, 0x68, 0x00, 0x00, 0x56, 0x00, 0x00, 0x6a, 0x00, + 0x00, 0x1e, 0x00, 0x00, 0x78, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmpanel/src/icons/appMail.xbm b/xmpanel/src/icons/appMail.xbm new file mode 100644 index 0000000..2e36954 --- /dev/null +++ b/xmpanel/src/icons/appMail.xbm @@ -0,0 +1,27 @@ +#define appMail_width 48 +#define appMail_height 48 +static unsigned char appMail_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x1c, 0x00, 0x00, 0x00, 0x00, 0x38, 0x2c, 0x00, 0x00, 0x50, 0x55, 0x34, + 0x4c, 0x00, 0x00, 0xa8, 0x00, 0x32, 0x8c, 0x00, 0x00, 0x00, 0x44, 0x31, + 0x0c, 0x01, 0x00, 0x50, 0x81, 0x30, 0x0c, 0x02, 0x00, 0xa8, 0x54, 0x30, + 0x0c, 0x04, 0x00, 0x00, 0x20, 0x30, 0x0c, 0x08, 0x00, 0x00, 0x10, 0x30, + 0x0c, 0x10, 0x00, 0x00, 0x08, 0x30, 0x0c, 0x20, 0x00, 0x00, 0x04, 0x30, + 0x0c, 0x40, 0x00, 0x00, 0x02, 0x30, 0x0c, 0x80, 0x00, 0x00, 0x01, 0x30, + 0x0c, 0x00, 0x01, 0x80, 0x00, 0x30, 0x0c, 0x00, 0x02, 0x40, 0x00, 0x30, + 0x0c, 0x00, 0x06, 0x60, 0x00, 0x30, 0x0c, 0x00, 0x09, 0x90, 0x00, 0x30, + 0x0c, 0x80, 0x10, 0x08, 0x01, 0x30, 0x0c, 0x40, 0x20, 0x04, 0x02, 0x30, + 0x0c, 0x20, 0x40, 0x02, 0x04, 0x30, 0x0c, 0x10, 0x80, 0x01, 0x08, 0x30, + 0x0c, 0x08, 0x00, 0x00, 0x10, 0x30, 0x0c, 0x04, 0x00, 0x00, 0x20, 0x30, + 0x0c, 0x02, 0x00, 0x00, 0x40, 0x30, 0x0c, 0x01, 0x00, 0x00, 0x80, 0x30, + 0x8c, 0x00, 0x00, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x32, + 0x2c, 0x00, 0x00, 0x00, 0x00, 0x34, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x38, + 0xfc, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmpanel/src/icons/appTerminal.xbm b/xmpanel/src/icons/appTerminal.xbm new file mode 100644 index 0000000..2e0a026 --- /dev/null +++ b/xmpanel/src/icons/appTerminal.xbm @@ -0,0 +1,27 @@ +#define appTerminal_width 48 +#define appTerminal_height 48 +static unsigned char appTerminal_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xff, 0xff, 0xff, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0x0e, 0xfd, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0x0e, 0x80, 0xf2, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0x0e, 0xfd, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0x0e, 0xf0, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, + 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, 0x60, 0xfe, 0xff, 0xff, 0x3f, 0x03, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x60, 0x00, 0x00, 0x00, 0x33, 0x03, 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, + 0xc0, 0xff, 0xff, 0xff, 0xff, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x30, 0x00, 0x00, 0x00, 0x00, 0x06, 0x18, 0x00, 0x00, 0x00, 0x00, 0x0c, + 0x0c, 0xc0, 0xff, 0xff, 0x03, 0x18, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x18, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xfc, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmpanel/src/icons/appWebBrowser.xbm b/xmpanel/src/icons/appWebBrowser.xbm new file mode 100644 index 0000000..5d72c2f --- /dev/null +++ b/xmpanel/src/icons/appWebBrowser.xbm @@ -0,0 +1,27 @@ +#define appWebBrowser_width 48 +#define appWebBrowser_height 48 +static unsigned char appWebBrowser_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, + 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0xf0, 0x18, 0x1c, 0x0f, 0x00, + 0x00, 0xfc, 0xff, 0xfc, 0x3f, 0x00, 0x00, 0x0e, 0x80, 0x07, 0x70, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xef, 0x00, 0x80, 0xf3, 0x00, 0x00, 0xc6, 0x01, + 0xc0, 0x01, 0xff, 0xff, 0x81, 0x03, 0xc0, 0x00, 0x38, 0x10, 0x00, 0x03, + 0x60, 0x00, 0xfc, 0x3f, 0x00, 0x06, 0x70, 0x00, 0x04, 0xc0, 0x00, 0x0e, + 0x30, 0x00, 0xf8, 0xff, 0x03, 0x0c, 0x30, 0x00, 0x10, 0x00, 0x0e, 0x0c, + 0x18, 0x00, 0xf0, 0xff, 0x0f, 0x18, 0x18, 0x00, 0x20, 0x00, 0x0e, 0x18, + 0x18, 0x00, 0xff, 0xff, 0x01, 0x18, 0x0c, 0xff, 0x01, 0x00, 0x01, 0x30, + 0x0c, 0xff, 0xff, 0xff, 0x07, 0x30, 0x0c, 0x01, 0x00, 0x00, 0x02, 0x30, + 0x8c, 0xff, 0xff, 0xff, 0xa1, 0x3f, 0x8c, 0x00, 0x00, 0x18, 0xc0, 0x31, + 0x8c, 0xff, 0xff, 0x0f, 0x00, 0x37, 0x9c, 0x00, 0x00, 0xc8, 0xff, 0x30, + 0xac, 0xff, 0xff, 0xcf, 0xff, 0x31, 0x2c, 0x04, 0x00, 0xc8, 0x80, 0x23, + 0x1c, 0xf8, 0xff, 0xcf, 0x80, 0x06, 0x18, 0x10, 0x00, 0xc8, 0x9c, 0x0c, + 0x18, 0xf0, 0xff, 0xdf, 0x80, 0x18, 0x18, 0x10, 0x00, 0xd0, 0x84, 0x3f, + 0x30, 0xf0, 0xff, 0xdf, 0x00, 0x3f, 0x30, 0x10, 0x00, 0xd0, 0x1c, 0x30, + 0x70, 0xf0, 0xff, 0xdf, 0x00, 0x30, 0x60, 0x10, 0x00, 0xd0, 0x7c, 0x33, + 0xc0, 0xf0, 0xff, 0xdf, 0x00, 0x30, 0xc0, 0x11, 0x00, 0xd0, 0x00, 0x30, + 0x80, 0xf3, 0xff, 0xdf, 0x00, 0x30, 0x00, 0x37, 0x00, 0xd3, 0x00, 0x30, + 0x00, 0xee, 0xff, 0xdd, 0x00, 0x30, 0x00, 0x3c, 0xf8, 0xd8, 0x00, 0x30, + 0x00, 0xf0, 0x0f, 0xc0, 0x00, 0x30, 0x00, 0xe0, 0x07, 0xc0, 0x00, 0x30, + 0x00, 0x00, 0xff, 0xcf, 0xff, 0x3f, 0x00, 0x00, 0xf8, 0xcf, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/xmpanel/src/main.c b/xmpanel/src/main.c new file mode 100644 index 0000000..accea8e --- /dev/null +++ b/xmpanel/src/main.c @@ -0,0 +1,75 @@ +#define _XOPEN_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "icons/appCalculator.xbm" +#include "icons/appEditor.xbm" +#include "icons/appFiles.xbm" +#include "icons/appMail.xbm" +#include "icons/appTerminal.xbm" +#include "icons/appWebBrowser.xbm" + +typedef struct { + Pixmap icon; + const char * command; +} Launcher; + +void createAllLaunchers (Widget); +Widget createLauncher (Widget, Launcher); +void activateLauncher (Widget, XtPointer, XtPointer); + +XtAppContext application; + +int main (int argc, char *argv[]) { + Widget window = XtVaAppInitialize ( + &application, "Panel", + NULL, 0, + &argc, argv, + NULL, NULL); + + Widget layout = XtVaCreateWidget ( + "layout", xmRowColumnWidgetClass, window, + XmNorientation, XmHORIZONTAL, + NULL); + createAllLaunchers(layout); + + XtManageChild(layout); + XtRealizeWidget(window); + XtAppMainLoop(application); +} + +void createAllLaunchers (Widget parent) { + #define add(name, cmd) createLauncher(parent, (Launcher){\ + .icon = XmdLoadBitmapIcon(parent, app##name),\ + .command = cmd " &"\ + } ); + add(Calculator, "xcalc"); + add(Editor, "nedit"); + add(Files, "caja"); + add(Mail, "nedit"); + add(Terminal, "xterm"); + add(WebBrowser, "firefox"); + #undef add +} + +Widget createLauncher (Widget parent, Launcher launcher) { + Widget button = XtVaCreateManagedWidget ( + "launcher", xmPushButtonWidgetClass, parent, + XmNleftAttachment, XmATTACH_FORM, + XmNlabelType, XmPIXMAP, + XmNlabelPixmap, launcher.icon, + NULL); + XtAddCallback(button, XmNactivateCallback, activateLauncher, (XtPointer)(launcher.command)); + return button; +} + +void activateLauncher (Widget button, XtPointer clientData, XtPointer callData) { + (void)(button); + (void)(callData); + system((char *)(clientData)); +}