Browse Source

Added ssetbg utility

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/slim/trunk@118 7c53e7cc-98ea-0310-8f1f-a0b24da60408
sip 17 years ago
parent
commit
9276574539
6 changed files with 233 additions and 15 deletions
  1. 10 4
      Makefile
  2. 10 4
      Makefile.freebsd
  3. 10 4
      Makefile.netbsd
  4. 12 3
      Makefile.openbsd
  5. 47 0
      ssetbg.1
  6. 144 0
      ssetbg.cpp

+ 10 - 4
Makefile

@@ -21,32 +21,38 @@ DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
 
 OBJECTS=jpeg.o png.o main.o image.o numlock.o cfg.o switchuser.o input.o app.o panel.o
+BGOBJECTS=jpeg.o png.o image.o ssetbg.o
 
-all: slim
+all: slim ssetbg
 
 slim: $(OBJECTS)
 	$(CXX) $(LDFLAGS) $(OBJECTS) -o $(NAME)
 
+ssetbg: $(BGOBJECTS)
+	$(CXX) $(LDFLAGS) $(BGOBJECTS) -o ssetbg
+
 .cpp.o:
 	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c $< -o $@
 
 .c.o:
 	$(CC) $(CFLAGS) $(DEFINES) $(CUSTOM) -c $< -o $@
 
-install: slim install-theme
+install: slim ssetbg install-theme
 	install -D -m 755 slim $(DESTDIR)$(PREFIX)/bin/slim
+	install -D -m 755 ssetbg $(DESTDIR)$(PREFIX)/bin/ssetbg
 	install -D -m 644 slim.1 $(DESTDIR)$(MANDIR)/man1/slim.1
+	install -D -m 644 ssetbg.1 $(DESTDIR)$(MANDIR)/man1/ssetbg.1
 	test -e $(DESTDIR)$(CFGDIR)/slim.conf || \
 		install -D -m 644 slim.conf $(DESTDIR)$(CFGDIR)/slim.conf
 
 clean:
-	@rm -f slim *.o
+	@rm -f slim ssetbg *.o
 
 dist:
 	@rm -rf $(NAME)-$(VERSION)
 	@mkdir $(NAME)-$(VERSION)
 	@cp -r *.cpp *.h *.c Makefile Makefile.* COPYING ChangeLog INSTALL README TODO \
-		xinitrc.sample slim.1 THEMES themes slim.conf $(NAME)-$(VERSION)
+		xinitrc.sample slim.1 ssetbg.1 THEMES themes slim.conf $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)/themes/.svn	$(NAME)-$(VERSION)/themes/default/.svn
 	@tar cvzf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)

+ 10 - 4
Makefile.freebsd

@@ -21,35 +21,41 @@ DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
 
 OBJECTS=jpeg.o png.o main.o image.o numlock.o cfg.o switchuser.o input.o app.o panel.o
+BGOBJECTS=jpeg.o png.o image.o ssetbg.o
 
-all: slim
+all: slim ssetbg
 
 slim: $(OBJECTS) 
 	$(CXX) $(LDFLAGS) $(OBJECTS) -o $(NAME)
 
+ssetbg: $(BGOBJECTS)
+	$(CXX) $(LDFLAGS) $(BGOBJECTS) -o ssetbg
+
 .cpp.o:
 	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c $< -o $@
 
 .c.o:
 	$(CC) $(CFLAGS) $(DEFINES) $(CUSTOM) -c $< -o $@
 
-install: slim install-theme
+install: slim ssetbg install-theme
 	install -d $(DESTDIR)$(PREFIX)/bin
 	install -d $(DESTDIR)$(MANDIR)/man1
 	install -d $(DESTDIR)$(CFGDIR)
 	install -m 755 slim $(DESTDIR)$(PREFIX)/bin
+	install -D -m 755 ssetbg $(DESTDIR)$(PREFIX)/bin/ssetbg
 	install -m 644 slim.1 $(DESTDIR)$(MANDIR)/man1
+	install -m 644 ssetbg.1 $(DESTDIR)$(MANDIR)/man1
 	test -e $(DESTDIR)$(CFGDIR)/slim.conf || \
 		install -m 644 slim.conf $(DESTDIR)$(CFGDIR)
 
 clean:
-	@rm -f slim *.o
+	@rm -f slim ssetbg *.o
 
 dist:
 	@rm -rf $(NAME)-$(VERSION)
 	@mkdir $(NAME)-$(VERSION)
 	@cp -r *.cpp *.h *.c Makefile Makefile.* COPYING ChangeLog README INSTALL TODO \
-		xinitrc.sample slim.1 THEMES themes slim.conf $(NAME)-$(VERSION)
+		xinitrc.sample slim.1 ssetbg.1 THEMES themes slim.conf $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)/themes/.svn	$(NAME)-$(VERSION)/themes/default/.svn
 	@tar cvzf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)

+ 10 - 4
Makefile.netbsd

@@ -21,35 +21,41 @@ DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
 
 OBJECTS=jpeg.o png.o main.o image.o numlock.o cfg.o switchuser.o input.o app.o panel.o
+BGOBJECTS=jpeg.o png.o image.o ssetbg.o
 
-all: slim
+all: slim ssetbg
 
 slim: $(OBJECTS) 
 	$(CXX) $(LDFLAGS) $(OBJECTS) -o $(NAME)
 
+ssetbg: $(BGOBJECTS)
+	$(CXX) $(LDFLAGS) $(BGOBJECTS) -o ssetbg
+
 .cpp.o:
 	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c $< -o $@
 
 .c.o:
 	$(CC) $(CFLAGS) $(DEFINES) $(CUSTOM) -c $< -o $@
 
-install: slim install-theme
+install: slim ssetbg install-theme
 	install -d $(DESTDIR)$(PREFIX)/bin
 	install -d $(DESTDIR)$(MANDIR)/man1
 	install -d $(DESTDIR)$(CFGDIR)
 	install -m 755 slim $(DESTDIR)$(PREFIX)/bin
+	install -m 755 ssetbg $(DESTDIR)$(PREFIX)/bin
 	install -m 644 slim.1 $(DESTDIR)$(MANDIR)/man1
+	install -m 644 ssetbg.1 $(DESTDIR)$(MANDIR)/man1
 	test -e $(DESTDIR)$(CFGDIR)/slim.conf || \
 		install -m 644 slim.conf $(DESTDIR)$(CFGDIR)
 
 clean:
-	@rm -f slim *.o
+	@rm -f slim ssetbg *.o
 
 dist:
 	@rm -rf $(NAME)-$(VERSION)
 	@mkdir $(NAME)-$(VERSION)
 	@cp -r *.cpp *.h *.c Makefile Makefile.* COPYING ChangeLog README INSTALL TODO \
-		xinitrc.sample slim.1 THEMES themes slim.conf $(NAME)-$(VERSION)
+		xinitrc.sample slim.1 ssetbg.1 THEMES themes slim.conf $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)/themes/.svn	$(NAME)-$(VERSION)/themes/default/.svn
 	@tar cvzf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)

+ 12 - 3
Makefile.openbsd

@@ -21,6 +21,7 @@ DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
 
 OBJECTS=jpeg.o png.o main.o image.o numlock.o cfg.o switchuser.o input.o app.o panel.o
+BGOBJECTS=jpeg.o png.o image.o ssetbg.o
 
 .SUFFIXES: .c.o .cpp.o
 
@@ -29,6 +30,9 @@ all: slim
 slim: $(OBJECTS) 
 	$(CXX) $(LDFLAGS) $(OBJECTS) -o $(NAME)
 
+ssetbg: $(BGOBJECTS)
+	$(CXX) $(LDFLAGS) $(BGOBJECTS) -o ssetbg
+
 main.o:
 	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c main.cpp -o $@
 
@@ -53,26 +57,31 @@ app.o:
 panel.o:
 	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c panel.cpp -o $@
 
+ssetbg.o:
+	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c ssetbg.cpp -o $@
+
 .c.o:
 	$(CC) $(CFLAGS) $(DEFINES) $(CUSTOM) -c $< -o $@
 
-install: slim install-theme
+install: slim ssetbg install-theme
 	install -d $(DESTDIR)$(PREFIX)/bin
 	install -d $(DESTDIR)$(MANDIR)/man1
 	install -d $(DESTDIR)$(CFGDIR)
 	install -m 755 slim $(DESTDIR)$(PREFIX)/bin
+	install -m 755 ssetbg $(DESTDIR)$(PREFIX)/bin
 	install -m 644 slim.1 $(DESTDIR)$(MANDIR)/man1
+	install -m 644 ssetbg.1 $(DESTDIR)$(MANDIR)/man1
 	test -e $(DESTDIR)$(CFGDIR)/slim.conf || \
 		install -m 644 slim.conf $(DESTDIR)$(CFGDIR)
 
 clean:
-	@rm -f slim *.o
+	@rm -f slim ssetbg *.o
 
 dist:
 	@rm -rf $(NAME)-$(VERSION)
 	@mkdir $(NAME)-$(VERSION)
 	@cp -r *.cpp *.h *.c Makefile Makefile.* COPYING ChangeLog README INSTALL TODO \
-		xinitrc.sample slim.1 THEMES themes slim.conf $(NAME)-$(VERSION)
+		xinitrc.sample slim.1 ssetbg.1 THEMES themes slim.conf $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)/themes/.svn	$(NAME)-$(VERSION)/themes/default/.svn
 	@tar cvzf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
 	@rm -rf $(NAME)-$(VERSION)

+ 47 - 0
ssetbg.1

@@ -0,0 +1,47 @@
+." Text automatically generated by txt2man
+.TH ssetbg  "January 18, 2007" "" ""
+.SH NAME
+\fBssetbg \fP- set X background
+\fB
+.SH SYNOPSIS
+.nf
+.fam C
+\fBssetbg\fP [\fB-c\fP \fIcolor\fP] [\fB-s\fP|\fB-t\fP|\fB-n\fP \fIfilename\fP]
+.fam T
+.fi
+.SH DESCRIPTION
+\fBssetbg\fP is a simple tool to set the bacground of the X11 root window.
+It allows setting a jpg / png image or plain \fIcolor\fP.
+.SH OPTIONS
+.TP
+.B
+\fB-c\fP \fIcolor\fP
+Set backround \fIcolor\fP. \fIcolor\fP is in hex format, ie 0066CC
+Use this option to set plain \fIcolor\fP or together with the \fB-n\fP option
+.TP
+.B
+\fB-s\fP \fIfilename\fP
+Stretch the image to fill the sreen size. This is the default option
+.TP
+.B
+\fB-t\fP \fIfilename\fP
+Tile the image
+.TP
+.B
+\fB-n\fP \fIfilename\fP
+Center the image on the screen. Can be used with an alpha-transpaent
+png image and the the \fB-c\fP option.
+.TP
+.B
+\fIfilename\fP
+is the path to a JPEG or PNG image.
+.SH EXAMPLE
+\fBssetbg\fP /some/path/image.jpg
+.PP
+\fBssetbg\fP \fB-t\fP /some/path/tile.jpg
+.PP
+\fBssetbg\fP \fB-c\fP BBBBBB
+.PP
+\fBssetbg\fP \fB-c\fP CCCCCC \fB-n\fP /some/path/logo.png
+.SH AUTHOR
+Simone Rota <sip@varlock.com>

+ 144 - 0
ssetbg.cpp

@@ -0,0 +1,144 @@
+/* SLiM - Simple Login Manager
+   Copyright (C) 1997, 1998 Per Liden
+   Copyright (C) 2004-06 Simone Rota <sip@varlock.com>
+   Copyright (C) 2004-06 Johannes Winkelmann <jw@tks6.net>
+      
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+*/
+
+/* Simple app to set the backround image of the X root window */
+
+#include <iostream>
+#include "image.h"
+
+
+#define DISPLAY         ":0.0"
+#define BG_STRETCH 1 
+#define BG_TILE 2
+#define BG_CENTER 3 
+#define BG_COLOR 4
+
+using namespace std;
+
+
+
+void setBackground(int bgstyle, char* fname, char* bgcolor) {
+    bool loaded;
+    Display* Dpy;
+    int Scr;
+    Window Root;
+   
+    string filename;
+    string bg_color;
+    
+    if (fname != NULL) {
+        filename.assign(fname);
+    }
+
+    if (bgcolor != NULL) {
+        bg_color.assign(bgcolor);
+    }
+
+
+    if((Dpy = XOpenDisplay(DISPLAY)) == 0) {
+        cerr << "could not open display" << endl;
+        exit(1);
+    }
+    
+    Scr = DefaultScreen(Dpy);
+    Root = RootWindow(Dpy, Scr);
+
+    Image* image = new Image;
+    if (bgstyle != BG_COLOR) {
+        loaded = image->Read(fname);
+        if (!loaded) {
+            cerr << "Could not load image!" << endl;
+            exit(1);
+        }
+    }
+    
+    if (bgstyle == BG_STRETCH) {
+        image->Resize(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
+    } else if (bgstyle == BG_TILE) {
+        image->Tile(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)));
+    } else if (bgstyle == BG_CENTER) {
+        image->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
+                        bg_color.c_str());
+    } else {
+        image->Center(XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)), XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)),
+                    bg_color.c_str());
+    }
+    
+    Pixmap p = image->createPixmap(Dpy, Scr, Root);
+    XSetWindowBackgroundPixmap(Dpy, Root, p);
+    XClearWindow(Dpy, Root);
+    XFlush(Dpy);
+    delete image;
+    XCloseDisplay(Dpy);
+}
+
+
+int main(int argc, char** argv) {
+    int tmp;
+    char* filename;
+    char* bg_color;
+    int bg_style;
+
+    bg_style = -1;
+    
+    while((tmp = getopt(argc, argv, "hs:t:n:c:?")) != EOF) {
+        switch (tmp) {
+        case 's':
+            filename = optarg;
+            bg_style = BG_STRETCH;
+            break;
+        case 't':
+            filename = optarg;
+            bg_style = BG_TILE;
+            break;
+        case 'n':
+            filename = optarg;
+            bg_style = BG_CENTER;
+            break;
+        case 'c':
+            bg_color = optarg;
+            bg_style = BG_COLOR;
+            break;
+        case '?':
+            cerr << endl;
+        case 'h':
+            cerr << "usage: ssetbg [-c color] [-s|-t|-n filename]" << endl
+            << "Available modes:" << endl
+            << "    -s: stretch" << endl
+            << "    -t: tiled" << endl
+            << "    -n: center" << endl
+            << "    -c: color" << endl;
+            exit(0);
+            break;
+        }
+    }
+
+    if (bg_style == -1) {
+        if (argc > 0)
+            filename = argv[1];
+        bg_style = BG_STRETCH;
+    }
+
+    if (bg_style != BG_COLOR && filename == NULL) {
+        cerr << "No filename given!" << endl;
+        exit(1);
+    }
+    if (bg_style == BG_COLOR && bg_color == NULL) {
+        cerr << "No color given!" << endl;
+        exit(1);
+    }
+
+    // if (bg_color == NULL)
+    
+    setBackground(bg_style, filename, bg_color);
+    return(0);
+}
+