]> git.draconx.ca Git - fvwmconf.git/commitdiff
Merge branch 'master' of git://git.draconx.com/fvwmconf
authorNick Bowler <draconx@gmail.com>
Sun, 1 Jun 2008 01:01:44 +0000 (21:01 -0400)
committerNick Bowler <draconx@gmail.com>
Sun, 1 Jun 2008 01:01:44 +0000 (21:01 -0400)
scripts/C/Makefile
scripts/C/xaspect.c
scripts/randombg.pl [new file with mode: 0755]

index 342509f12a1acb918726cd15b5db1dabce4888f4..ee422c60f42dbeca8607da75985d7837acd16aa4 100644 (file)
@@ -1,7 +1,7 @@
-CFLAGS  = -O2 -Wall -Wextra -Wno-sign-compare
+CFLAGS  = -O2 -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers
 LDFLAGS = 
 
-CC = c89
+CC = c99
 LD = $(CC)
 
 all: xaspect
index e10f50637f211db421b6006d8a8e985af619b901..3e07caac52727d80b63c5cce18d7e6bd8a83aad8 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
+#include <inttypes.h>
 #include <xcb/xcb.h>
 
 #define MKASPECT(w, h) { (double)w/h, #w ":" #h }
@@ -57,17 +58,38 @@ char *testaspect(xcb_screen_t *screen)
        return best;
 }
 
+struct options {
+       char *displayname;
+       int showdimensions;
+} *parseoptions(int argc, char **argv)
+{
+       static struct options opts = { 0 };
+       int i;
+
+       for (i = 1; i < argc; i++) {
+               if (strcmp(argv[i], "-display") == 0) {
+                       if (++i < argc) {
+                               opts.displayname = argv[i];
+                               continue;
+                       }
+                       fprintf(stderr, "-display requires an argument\n");
+               } else if (strcmp(argv[i], "-dimensions") == 0) {
+                       opts.showdimensions = 1;
+               }
+       }
+
+       return &opts;
+}
+
 int main(int argc, char **argv)
 {
        xcb_connection_t *display;
        xcb_screen_t     *screen;
-       char *dpynam = NULL;
        int screen_num;
 
-       if (argc > 2 && strcmp(argv[1], "-display") == 0)
-               dpynam = argv[2];
+       struct options *opts = parseoptions(argc, argv);
        
-       display = xcb_connect(dpynam, &screen_num);
+       display = xcb_connect(opts->displayname, &screen_num);
        if (xcb_connection_has_error(display)) {
                fprintf(stderr, "Failed to open display.\n");
                xcb_disconnect(display);
@@ -81,6 +103,10 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
+       if (opts->showdimensions) {
+               printf("%" PRIu16 "x%" PRIu16 "-",
+                      screen->width_in_pixels, screen->height_in_pixels);
+       }
        printf("%s\n", testaspect(screen));
 
        xcb_disconnect(display);
diff --git a/scripts/randombg.pl b/scripts/randombg.pl
new file mode 100755 (executable)
index 0000000..941ebe7
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use strict;
+
+my $FVWM = (defined $ENV{FVWM_USERDIR}) ? $ENV{FVWM_USERDIR}
+                                        : $ENV{HOME}."/.fvwm";
+
+die ("usage: randombg.pl <directory>") if (! -d $ARGV[0]);
+
+open XASPECT, "-|", "$FVWM/scripts/C/xaspect", "-dimensions";
+my $aspect = <XASPECT>;
+close XASPECT;
+die ("Incompetent use of xaspect") if ($?);
+
+$aspect =~ s/(^\s*)|(\s*$)//g;
+
+opendir WALLPAPER, $ARGV[0];
+my @dir = grep(/\Q$aspect\E\.png$/, readdir WALLPAPER);
+closedir WALLPAPER;
+
+print $ARGV[0] . "/" . $dir[int(rand(@dir))] . "\n";