summaryrefslogtreecommitdiffstats
path: root/mga-bg-res
diff options
context:
space:
mode:
Diffstat (limited to 'mga-bg-res')
-rw-r--r--mga-bg-res/Makefile27
-rw-r--r--mga-bg-res/NEWS5
-rw-r--r--mga-bg-res/VERSION1
-rw-r--r--mga-bg-res/mga-bg-res.c82
-rwxr-xr-xmga-bg-res/mga-bg-res.xinit3
5 files changed, 118 insertions, 0 deletions
diff --git a/mga-bg-res/Makefile b/mga-bg-res/Makefile
new file mode 100644
index 0000000..d533791
--- /dev/null
+++ b/mga-bg-res/Makefile
@@ -0,0 +1,27 @@
+VERSION:=$(shell cat VERSION)
+
+mga-bg-res:
+ gcc -O2 -g -Wall -o mga-bg-res mga-bg-res.c
+
+install:
+ mkdir -p $(DESTDIR)/usr/bin/
+ cp mga-bg-res $(DESTDIR)/usr/bin/
+ chmod u+s $(DESTDIR)/usr/bin/mga-bg-res
+ mkdir -p $(DESTDIR)/etc/X11/xinit.d/
+ cp mga-bg-res.xinit $(DESTDIR)/etc/X11/xinit.d/01mga-bg-res
+
+uninstall:
+ rm -f $(DESTDIR)/usr/bin/mga-bg-res
+ rm -f $(DESTDIR)/etc/X11/xinit.d/01mga-bg-res
+
+dist:
+ mkdir mga-bg-res-$(VERSION)
+ cp mga-bg-res.c mga-bg-res-$(VERSION)/
+ cp mga-bg-res.xinit mga-bg-res-$(VERSION)/
+ cp Makefile mga-bg-res-$(VERSION)/
+ cp VERSION mga-bg-res-$(VERSION)/
+ tar caf mga-bg-res-$(VERSION).tar.xz mga-bg-res-$(VERSION)
+ rm -rf mga-bg-res-$(VERSION)
+
+clean:
+ rm -f mga-bg-res
diff --git a/mga-bg-res/NEWS b/mga-bg-res/NEWS
new file mode 100644
index 0000000..11f14fa
--- /dev/null
+++ b/mga-bg-res/NEWS
@@ -0,0 +1,5 @@
+Version 0.2 (2015-02-08):
+- Bugfix: Do not ship binary instead of the source (AL13N)
+
+Version 0.1 (2015-02-08):
+- Initial version as workaround to mga#763 (AL13N)
diff --git a/mga-bg-res/VERSION b/mga-bg-res/VERSION
new file mode 100644
index 0000000..3b04cfb
--- /dev/null
+++ b/mga-bg-res/VERSION
@@ -0,0 +1 @@
+0.2
diff --git a/mga-bg-res/mga-bg-res.c b/mga-bg-res/mga-bg-res.c
new file mode 100644
index 0000000..6061587
--- /dev/null
+++ b/mga-bg-res/mga-bg-res.c
@@ -0,0 +1,82 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#define PATH "/usr/share/mga/backgrounds/"
+#define DSTLINK PATH"default.jpg"
+#define SRCLINK_PREFIX PATH"Mageia-Default-"
+#define SRCLINK_SUFFIX ".jpg"
+#define SRCLINK SRCLINK_PREFIX"%s"SRCLINK_SUFFIX
+#define RESSIZE 20
+#define SRCSIZE (RESSIZE+strlen(SRCLINK_PREFIX)+strlen(SRCLINK_SUFFIX) + 1)
+#define ALLOWCHARS "0123456789x"
+
+int main(int argc, char* argv[]) {
+ char src[SRCSIZE];
+ char res[RESSIZE];
+ int l;
+
+ // check argument
+ if (argc != 2) {
+ fprintf(stderr, "Need a resolution argument, eg: '1920x1080'.\n");
+ return 1;
+ }
+
+ // get the res (max RESSIZE)
+ l = snprintf(res, RESSIZE, argv[1]);
+ if (l < 5) {
+ fprintf(stderr, "Malformed resolution argument, eg: '1920x1080'.\n");
+ return 2;
+ }
+
+ // to be sure, set the last char as 0
+ if (l < RESSIZE)
+ res[l] = 0;
+ else
+ res[RESSIZE-1] = 0;
+
+ // check if the resolution contains acceptable chars
+ l = strspn(res, ALLOWCHARS);
+ if (l < 5) {
+ fprintf(stderr, "Malformed resolution argument, eg: '1920x1080'.\n");
+ return 2;
+ }
+
+ // to be sure, set the last char as 0
+ if (l < RESSIZE)
+ res[l] = 0;
+ else
+ res[RESSIZE-1] = 0;
+
+ // create target string
+ if (snprintf(src, SRCSIZE, SRCLINK, res) < 0) {
+ fprintf(stderr, "Unknown error determining symlink target.\n");
+ return 3;
+ }
+
+ // check if symlink target exists
+ if (access(src, F_OK) < 0) {
+ fprintf(stderr, "No image for this resolution.\n");
+ return 0;
+ }
+
+ // set symlink
+ if (symlink(src, DSTLINK) < 0) {
+ if (errno != EEXIST) {
+ fprintf(stderr, "Symlink could not be set: %s.\n", strerror(errno));
+ return 4;
+ }
+
+ // since the destination exists, remove and try again
+ if (unlink(DSTLINK) < 0) {
+ fprintf(stderr, "Symlink could not be forced: %s.\n", strerror(errno));
+ return 5;
+ }
+ if (symlink(src, DSTLINK) < 0) {
+ fprintf(stderr, "Unknown error during forced symlink: %s.\n", strerror(errno));
+ return 6;
+ }
+ }
+ return 0;
+}
diff --git a/mga-bg-res/mga-bg-res.xinit b/mga-bg-res/mga-bg-res.xinit
new file mode 100755
index 0000000..d3dd2dd
--- /dev/null
+++ b/mga-bg-res/mga-bg-res.xinit
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+/usr/bin/mga-bg-res $( xrandr | awk '/\sconnected/{i=split(substr($0,0,index($0,"+")-1),a);if($0~/\sprimary\s/){if(p==""){p=a[i]}}else{if(d==""){d=a[i]}}}END{if(p==""){print d}else{print p}}' )