From aba739e980e297bb15ae5b7fb28014c3aab246ee Mon Sep 17 00:00:00 2001 From: Panagiotis Dimopoulos Date: Mon, 2 Apr 2018 14:34:00 +0300 Subject: [PATCH] Update to version 1.1 --- wmArchUp/CHANGES | 11 ++- wmArchUp/Makefile | 3 +- wmArchUp/README | 11 ++- wmArchUp/arch_update.sh | 7 ++ wmArchUp/loading.xpm | 64 ++++++++++++++++ wmArchUp/wmarchup.c | 166 +++++++++++++++++++++++++++------------- 6 files changed, 203 insertions(+), 59 deletions(-) create mode 100755 wmArchUp/arch_update.sh create mode 100644 wmArchUp/loading.xpm diff --git a/wmArchUp/CHANGES b/wmArchUp/CHANGES index 6f912d2..dbb71d1 100644 --- a/wmArchUp/CHANGES +++ b/wmArchUp/CHANGES @@ -1,3 +1,12 @@ +2018-04-02 Panagiotis A. Dimopoulos + + - Release 1.1 + - Add a gear icon to show when checking for updates + - Right click initiate a check for updates + - Left click will open an xterm and start system update + - You can now define that check interval with -c or --check-interval + command line arguments + 2018-03-29 Panagiotis A. Dimopoulos - Initial Release 1.0 + - Initial Release 1.0 diff --git a/wmArchUp/Makefile b/wmArchUp/Makefile index eb1baf8..803e267 100644 --- a/wmArchUp/Makefile +++ b/wmArchUp/Makefile @@ -1,7 +1,7 @@ CC=gcc INSTALL=install PREFIX=/usr/local -CFLAGS+=-Wall `pkg-config --cflags dockapp` +CFLAGS+=-Wall -O3 `pkg-config --cflags dockapp` LIBS=`pkg-config --libs dockapp` wmarchup: wmarchup.o @@ -13,6 +13,7 @@ wmarchup.o: wmarchup.c install: $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin $(INSTALL) wmarchup $(DESTDIR)$(PREFIX)/bin + $(INSTALL) arch_update.sh $(DESTDIR)$(PREFIX)/bin clean: rm -f wmarchup wmarchup.o diff --git a/wmArchUp/README b/wmArchUp/README index b20c896..0f3ac4b 100644 --- a/wmArchUp/README +++ b/wmArchUp/README @@ -17,13 +17,19 @@ managers such as Window Maker, AfterStep, BlackBox, Fluxbox and Enlightenment. This dockapp is quite simple. It contains an Arch Linux logo icon. When there is not package updates then the Arch Linux logo icon is greyed. When there are package updates then the Arch Linux logo icon is blue. The program check for -updates every 10 minutes. +updates every 10 minutes by default. However you can specify the checking +interval by using the -c or --check-interval command line arguments. When the +program checks for updates it change its icon in a gear. If you right click the +Arch Linux logo icon then it immediately starts a check for updates. If you left +click the Arch Linux log the it opens an xterm window and start a system update. *************** *** OPTIONS *** *************** -This program has no command line options. +This program has the following command line options +-c : Sets the checking time interval in minutes. Default is 10 minutes. +--check-interval : Same as -c ********************* *** REQUIREMENTS *** @@ -31,6 +37,7 @@ This program has no command line options. This program needs libdockapp library files in order to compile. You can find libdockapp at http://www.dockapps.net/libdockapp +Also you need to have xterm installed. ******************* *** COMPILATION *** diff --git a/wmArchUp/arch_update.sh b/wmArchUp/arch_update.sh new file mode 100755 index 0000000..d3b0241 --- /dev/null +++ b/wmArchUp/arch_update.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +statusfile=$(mktemp) +xterm -e sh -c 'sudo pacman -Syu; echo $? > '$statusfile +status=$(cat $statusfile) +rm $statusfile +exit $status diff --git a/wmArchUp/loading.xpm b/wmArchUp/loading.xpm new file mode 100644 index 0000000..7a71655 --- /dev/null +++ b/wmArchUp/loading.xpm @@ -0,0 +1,64 @@ +/* XPM */ +static char *loading[] = { +/* columns rows colors chars-per-pixel */ +"56 56 2 1 ", +" c #FF727D", +". c None", +/* pixels */ +"........................................................", +"......................... .........................", +"........................ ........................", +"................. ...... ...... .................", +"................ ..... ..... ................", +".............. ..... ..... ..............", +"............ .... .... ............", +"............ .. .. ............", +"............. .............", +"............. .............", +".............. ..............", +".............. ..............", +"...... ..... ..... ......", +"...... .. .. ......", +"..... .....", +"..... .....", +".... ....", +"... ........ ...", +".... ............ ....", +"...... .............. ......", +"........ ................ ........", +"........ .................. ........", +"....... .................... .......", +"....... .................... .......", +".. ...................... ..", +". ...................... .", +". ...................... .", +". ...................... .", +". ...................... .", +". ...................... .", +". ...................... .", +".. ...................... ..", +"....... .................... .......", +"....... .................... .......", +"........ .................. ........", +"........ ................ ........", +"...... .............. ......", +".... ............ ....", +"... ........ ...", +".... ....", +"..... .....", +"..... .....", +"...... .. .. ......", +"...... ..... ..... ......", +".............. ..............", +".............. ..............", +"............. .............", +"............. .............", +"............ .. .. ............", +"............ .... .... ............", +".............. ..... ..... ..............", +"................ ..... ..... ................", +"................. ...... ...... .................", +"........................ ........................", +"......................... .........................", +"........................................................" +}; diff --git a/wmArchUp/wmarchup.c b/wmArchUp/wmarchup.c index 18134ec..71b38cc 100644 --- a/wmArchUp/wmarchup.c +++ b/wmArchUp/wmarchup.c @@ -1,36 +1,34 @@ -/* - * Copyright (c) 2002 Alban G. Hertroys - * - * Basic example of libDockapp usage - * - * This dockapp will draw a rectangle with a - * bouncing ball in it. - */ - -/* also includes Xlib, Xresources, XPM, stdlib and stdio */ +/* Also includes Xlib, Xresources, XPM, stdlib and stdio */ #include #include -/* include the pixmap to use */ +/* Include the pixmap to use */ #include "archlinux.xpm" #include "archlinux_bw.xpm" +#include "loading.xpm" -#define TRUE 1 -#define FALSE 0 -#define MAX 256 +#define TRUE 1 +#define FALSE 0 +#define MAX 256 +#define CHK_INTERVAL 600 +#define WMARCHUP_VER "1.1" +#define VERSION "wmArchUp version " WMARCHUP_VER /* * Prototypes for local functions */ void destroy(void); -int check_for_updates(); +void check_for_updates(); +void buttonrelease(int button, int state, int x, int y); +void update(); /* * Global variables */ -Pixmap arch, arch_mask, arch_bw, arch_bw_mask; -unsigned short height, width; -XEvent ev; +Pixmap arch, arch_mask, arch_bw, arch_bw_mask, checking, checking_mask; +unsigned short height, width; +unsigned int check_interval = CHK_INTERVAL; +int updates_available = FALSE; /* * M A I N @@ -39,27 +37,43 @@ XEvent ev; int main(int argc, char **argv) { + /* Set callbacks for events */ DACallbacks eventCallbacks = { - destroy, /* destroy */ - NULL, /* buttonPress */ - NULL, /* buttonRelease */ - NULL, /* motion (mouse) */ - NULL, /* mouse enters window */ - NULL, /* mouse leaves window */ - NULL /* timeout */ + destroy, /* destroy */ + NULL, /* buttonPress */ + &buttonrelease, /* buttonRelease */ + NULL, /* motion (mouse) */ + NULL, /* mouse enters window */ + NULL, /* mouse leaves window */ + check_for_updates /* timeout */ + }; + + int interval = 0; + + /* Set program options */ + DAProgramOption options[] = { + { + "-c", + "--check-interval", + "Check interval in minutes. Default 10 minutes.", + DONatural, + False, + {&interval} + }, }; /* provide standard command-line options */ DAParseArguments( - argc, argv, /* Where the options come from */ - NULL, 0, /* Our list with options - none as you can see */ + argc, argv, /* Where the options come from */ + options, 1, /* Our list with options */ "This is dockapp watch for available updates " "in Arch Linux packages.\n", - "wmarchup version 1.0"); + VERSION); - /* Tell libdockapp what version we expect it to be (a date from - * NEWS should do). - */ + /* Set the check interval */ + check_interval = interval ? (interval * 60) : CHK_INTERVAL; + + /* Check if correct libdockapp version exists in system */ DASetExpectedVersion(20050716); DAInitialize("", "WMArchUp", 56, 56, argc, argv); @@ -78,50 +92,80 @@ main(int argc, char **argv) &height, &width); - DASetShape(arch_bw_mask); - DASetPixmap(arch_bw); + DAMakePixmapFromData( + loading, + &checking, + &checking_mask, + &height, + &width); /* Respond to destroy and timeout events (the ones not NULL in the * eventCallbacks variable. */ DASetCallbacks(&eventCallbacks); - DAShow(); /* Show the dockapp window. */ + /* Set timeout in msec */ + DASetTimeout(check_interval * 1000); - while (1) { - if (check_for_updates() == TRUE) { - DASetShape(arch_mask); - DASetPixmap(arch); - } else { - DASetShape(arch_bw_mask); - DASetPixmap(arch_bw); - } + /* Show the dockapp window. */ + DAShow(); - /* handle all pending X events */ - while (XPending(DADisplay)) { - XNextEvent(DADisplay, &ev); - DAProcessEvent(&ev); - } - sleep(600); - } + /* Check for updates at the begining */ + check_for_updates(); + + /* Loop for events */ + DAEventLoop(); /* not reached */ exit(EXIT_SUCCESS); } -int -check_for_updates() { +void +update() +{ + if (updates_available == TRUE) { + XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask); + + char *update_script = "./arch_update.sh"; + int ret = system(update_script); + + if (WEXITSTATUS(ret) == 0) { + updates_available = FALSE; + DASetShape(arch_bw_mask); + DASetPixmap(arch_bw); + } + + XSelectInput(DAGetDisplay(NULL), DAGetWindow(), + ButtonPressMask | ButtonReleaseMask); + } +} + +void +check_for_updates() +{ + XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask); FILE *fp; char res[MAX]; + + DASetShape(checking_mask); + DASetPixmap(checking); + /* Read output from command */ - fp = popen("checkupdates","r"); - if( fgets (res, MAX, fp)!=NULL ) { + fp = popen("checkupdates", "r"); + if (fgets(res, MAX, fp) != NULL) { fclose(fp); - return TRUE; + updates_available = TRUE; + DASetShape(arch_mask); + DASetPixmap(arch); } else { - return FALSE; + updates_available = FALSE; + DASetShape(arch_bw_mask); + DASetPixmap(arch_bw); } + + XSelectInput(DAGetDisplay(NULL), DAGetWindow(), + ButtonPressMask | ButtonReleaseMask); } void @@ -129,3 +173,15 @@ destroy(void) { return; } + +/* A mouse button was pressed and released. + * See if it was button 1 left click or button 3 right click. */ +void +buttonrelease(int button, int state, int x, int y) +{ + if (button == 1) { + update(); + } else if (button == 3) { + check_for_updates(); + } +}