Package: hotkeys
Version: 0.5.7.4-0.1
Severity: normal
Tags: patch

This patch adds support to hotkeys for controlling LCD backlights using
the RandR extension. The code is copied from xbacklight, so it does the
same fancy fading between brightness levels.

This patch assumes you've applied my alsa patch first. Like in the alsa
patch, I've added -lXrandr -lXrender -lX11 to the link line directly,
as I don't feel like messing around with autoconf.

BTW, the copyright file probably needs to be updated to mention Keith
Packard's copyright, as well as the amixer copyright stuff from the alsa
patch. xbacklight is BSD licensed.

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.21-2-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages hotkeys depends on:
ii  libasound2                 1.0.14a-2     ALSA library
ii  libatk1.0-0                1.18.0-2      The ATK accessibility toolkit
ii  libc6                      2.6-2         GNU C Library: Shared libraries
ii  libcairo2                  1.4.10-1      The Cairo 2D vector graphics libra
ii  libdb4.5                   4.5.20-5      Berkeley v4.5 Database Libraries [
ii  libfontconfig1             2.4.2-1.2     generic font configuration library
ii  libglib2.0-0               2.12.13-1     The GLib library of C routines
ii  libgtk2.0-0                2.10.13-1     The GTK+ graphical user interface 
ii  libpango1.0-0              1.16.4-3      Layout and rendering of internatio
ii  libx11-6                   2:1.0.3-7     X11 client-side library
ii  libxcursor1                1:1.1.8-2     X cursor management library
ii  libxext6                   1:1.0.3-2     X11 miscellaneous extension librar
ii  libxfixes3                 1:4.0.3-2     X11 miscellaneous 'fixes' extensio
ii  libxi6                     2:1.1.1-1     X11 Input extension library
ii  libxinerama1               1:1.0.2-1     X11 Xinerama extension library
ii  libxml2                    2.6.29.dfsg-1 GNOME XML library
ii  libxmu6                    1:1.0.3-1     X11 miscellaneous utility library
ii  libxosd2                   2.2.14-1.3    X On-Screen Display library - runt
ii  libxrandr2                 2:1.2.1-1     X11 RandR extension library
ii  libxrender1                1:0.9.2-1     X Rendering Extension client libra

hotkeys recommends no packages.

-- no debconf information

-- 
see shy jo
diff --new-file -ur old/hotkeys-0.5.7.4/debian/control hotkeys-0.5.7.4/debian/control
--- old/hotkeys-0.5.7.4/debian/control	2007-07-20 10:04:33.000000000 -0400
+++ hotkeys-0.5.7.4/debian/control	2007-07-28 15:39:49.000000000 -0400
@@ -13,8 +13,9 @@
  This program sits at the back and listens for the "special" hotkeys
  that you won't normally use on your Internet/Multimedia keyboards.
  The buttons perform their intended behaviors, such as volume up and
- down, mute the speaker, launch applications, etc. It has On-screen
- display (OSD) to show the volume, program that's being started, etc.
+ down, mute the speaker, control the backlight, launch applications, etc.
+ It has On-screen display (OSD) to show the volume, program that's being
+ started, etc.
  .
  It features an XML-based keycode configuration file format, which
  makes it possible to define the hotkeys to launch any programs you
diff --new-file -ur old/hotkeys-0.5.7.4/def/sample.xml hotkeys-0.5.7.4/def/sample.xml
--- old/hotkeys-0.5.7.4/def/sample.xml	2006-01-19 01:41:23.000000000 -0500
+++ hotkeys-0.5.7.4/def/sample.xml	2007-07-28 15:46:31.000000000 -0400
@@ -20,6 +20,8 @@
       VolUp
       VolDown
       Mute
+      BacklightUp
+      BacklightDown
       WebBrowser
       Email
       Help
diff --new-file -ur old/hotkeys-0.5.7.4/src/Makefile.am hotkeys-0.5.7.4/src/Makefile.am
--- old/hotkeys-0.5.7.4/src/Makefile.am	2007-07-28 16:02:02.000000000 -0400
+++ hotkeys-0.5.7.4/src/Makefile.am	2007-07-28 15:30:38.000000000 -0400
@@ -1,13 +1,13 @@
 bin_PROGRAMS    = hotkeys
 hotkeys_SOURCES = hotkeys.c kbddef.c conf.c fixVMware.c apmlib.c xmalloc.c \
-                  splash.c amixer.c \
+                  splash.c amixer.c xbacklight.c \
                   XF86keysym.h apm.h common.h conf.h hotkeys.h kbddef.h \
-                  xmalloc.h splash.h amixer.h
+                  xmalloc.h splash.h amixer.h xbacklight.h
 sysconf_DATA    = hotkeys.conf
 man_MANS        = hotkeys.1
 
 CFLAGS      = @CFLAGS@ @X_CFLAGS@ @XML_CFLAGS@ @LIBXOSD_CFLAGS@ @GTK_CFLAGS@ -I.. # -DDEBUG 
-LIBS        = @LIBS@ @X_LIBS@ @XML_LIBS@ @LIBXOSD_LIBS@ @GTK_LIBS@ -lasound
+LIBS        = @LIBS@ @X_LIBS@ @XML_LIBS@ @LIBXOSD_LIBS@ @GTK_LIBS@ -lasound  -lXrandr -lXrender -lX11
 DEFS        = @DEFS@ -DSHAREDIR=\"@datadir@/@[EMAIL PROTECTED]" \
               -DCONFDIR=\"@[EMAIL PROTECTED]" -DCONFIG_NAME=\"@[EMAIL PROTECTED]"
 
diff --new-file -ur old/hotkeys-0.5.7.4/src/Makefile.in hotkeys-0.5.7.4/src/Makefile.in
--- old/hotkeys-0.5.7.4/src/Makefile.in	2007-07-28 16:02:02.000000000 -0400
+++ hotkeys-0.5.7.4/src/Makefile.in	2007-07-28 15:30:30.000000000 -0400
@@ -96,13 +96,13 @@
 l = @l@
 
 bin_PROGRAMS = hotkeys
-hotkeys_SOURCES = hotkeys.c kbddef.c conf.c fixVMware.c apmlib.c xmalloc.c                   splash.c amixer.c                   XF86keysym.h apm.h common.h conf.h hotkeys.h kbddef.h                   xmalloc.h splash.h amixer.h
+hotkeys_SOURCES = hotkeys.c kbddef.c conf.c fixVMware.c apmlib.c xmalloc.c                   splash.c amixer.c xbacklight.c                   XF86keysym.h apm.h common.h conf.h hotkeys.h kbddef.h                   xmalloc.h splash.h amixer.h xbacklight.h
 
 sysconf_DATA = hotkeys.conf
 man_MANS = hotkeys.1
 
 CFLAGS = @CFLAGS@ @X_CFLAGS@ @XML_CFLAGS@ @LIBXOSD_CFLAGS@ @GTK_CFLAGS@ -I.. # -DDEBUG 
-LIBS = @LIBS@ @X_LIBS@ @XML_LIBS@ @LIBXOSD_LIBS@ @GTK_LIBS@ -lasound
+LIBS = @LIBS@ @X_LIBS@ @XML_LIBS@ @LIBXOSD_LIBS@ @GTK_LIBS@ -lasound  -lXrandr -lXrender -lX11
 DEFS = @DEFS@ -DSHAREDIR=\"@datadir@/@[EMAIL PROTECTED]"               -DCONFDIR=\"@[EMAIL PROTECTED]" -DCONFIG_NAME=\"@[EMAIL PROTECTED]"
 
 
@@ -121,7 +121,7 @@
 X_EXTRA_LIBS = @X_EXTRA_LIBS@
 X_PRE_LIBS = @X_PRE_LIBS@
 hotkeys_OBJECTS =  hotkeys.o kbddef.o conf.o fixVMware.o apmlib.o \
-xmalloc.o splash.o amixer.o
+xmalloc.o splash.o amixer.o xbacklight.o
 hotkeys_LDADD = $(LDADD)
 hotkeys_DEPENDENCIES = 
 hotkeys_LDFLAGS = 
diff --new-file -ur old/hotkeys-0.5.7.4/src/XF86keysym.h hotkeys-0.5.7.4/src/XF86keysym.h
--- old/hotkeys-0.5.7.4/src/XF86keysym.h	2001-03-16 08:55:02.000000000 -0500
+++ hotkeys-0.5.7.4/src/XF86keysym.h	2007-07-28 15:51:41.000000000 -0400
@@ -70,5 +70,6 @@
 #define XF86XK_VendorHome	0x1008FF34
 #define XF86XK_LightBulb	0x1008FF35
 #define XF86XK_Shop		0x1008FF36
-
+#define XF86XK_BacklightUp	0x1008FF37
+#define XF86XK_BacklightDown	0x1008FF38
 
diff --new-file -ur old/hotkeys-0.5.7.4/src/hotkeys.1 hotkeys-0.5.7.4/src/hotkeys.1
--- old/hotkeys-0.5.7.4/src/hotkeys.1	2007-07-28 16:02:02.000000000 -0400
+++ hotkeys-0.5.7.4/src/hotkeys.1	2007-07-28 15:39:28.000000000 -0400
@@ -8,7 +8,7 @@
 This program sits at the back and listens for the "special" hotkeys
 that you won't normally use on your Internet/Multimedia keyboards.
 The buttons perform their intended behaviors, such as volume up and
-down, mute the speaker, launch applications, etc.
+down, mute the speaker, control the backlight, launch applications, etc.
 The functions are completely programmable.
 
 It has On-screen display (OSD) to show the volume, program that's
diff --new-file -ur old/hotkeys-0.5.7.4/src/hotkeys.c hotkeys-0.5.7.4/src/hotkeys.c
--- old/hotkeys-0.5.7.4/src/hotkeys.c	2007-07-28 16:02:02.000000000 -0400
+++ hotkeys-0.5.7.4/src/hotkeys.c	2007-07-28 16:00:56.000000000 -0400
@@ -76,6 +76,7 @@
 #include "hotkeys.h"
 #include "conf.h"
 #include "amixer.h"
+#include "xbacklight.h"
 
 #include <X11/Xmu/Error.h>
 
@@ -114,6 +115,8 @@
 
 int             volUpAdj      = 2;
 int             volDownAdj    = -2;
+int		backlightUpAdj		= 2;
+int		backlightDownAdj	= -2;
 
 /***====================================================================***/
 
@@ -577,6 +580,50 @@
     exit(1);
 }
 
+/*
+ * adj is a percentage, can be +ve or -ve for brighter and dimmer resp.
+ */
+static int
+adjustBacklight(int adj)
+{
+    static struct timeval last_time;
+    struct timeval this_time;
+    static int  multiplier = 0;   /* if 0 then it's first time to come in this func */
+
+    int sign = adj > 0 ? 1 : -1;
+
+    if ( adj == 0 )
+        return;
+
+    if ( multiplier == 0 )
+    {
+        gettimeofday(&last_time, NULL);
+        multiplier = sign;
+    }
+    else
+    {
+        gettimeofday(&this_time, NULL);
+        if ( (( adj > 0 && multiplier > 0 ) || ( adj < 0 && multiplier < 0 )) &&
+             ( (this_time.tv_sec - last_time.tv_sec) * 1000000 +
+             this_time.tv_usec - last_time.tv_usec < 500000 ) )
+        {
+            multiplier += sign;
+            adj *= abs(multiplier);
+            if ( adj > 10 )     /* should be a MAX value defined somewhere else FIXME */
+                adj = 10;
+            else if ( adj < -10 )
+                adj = -10;
+        }
+        else
+        {
+            multiplier = sign;
+        }
+        last_time.tv_sec = this_time.tv_sec;
+        last_time.tv_usec = this_time.tv_usec;
+    }
+
+    return xbacklight(dpy, adj);
+}
 
 /*
  * adj is a percentage, can be +ve or -ve for louder and softer resp.
@@ -1618,6 +1665,12 @@
             if ( ev.message.keycode == (kbd.defCmds)[muteKey].key ) {
                 doMute();
             } else
+            if ( ev.message.keycode == (kbd.defCmds)[backlightUpKey].key ) {
+                adjustBacklight(backlightUpAdj);
+            } else 
+            if ( ev.message.keycode == (kbd.defCmds)[backlightDownKey].key ) {
+                adjustBacklight(backlightDownAdj);
+            } else 
             /* APM stuffs */
             if ( ev.message.keycode == (kbd.defCmds)[sleepKey].key ||
                  ev.message.keycode == (kbd.defCmds)[wakeupKey].key ) {
diff --new-file -ur old/hotkeys-0.5.7.4/src/hotkeys.h hotkeys-0.5.7.4/src/hotkeys.h
--- old/hotkeys-0.5.7.4/src/hotkeys.h	2002-11-27 14:33:50.000000000 -0500
+++ hotkeys-0.5.7.4/src/hotkeys.h	2007-07-28 15:52:31.000000000 -0400
@@ -60,6 +60,8 @@
 extern  int             loglevel;
 extern  int             volUpAdj;
 extern  int             volDownAdj;
+extern  int             backlightUpAdj;
+extern  int             backlightDownAdj;
 
 #ifdef HAVE_XOSD
 extern  xosd*           osd;
diff --new-file -ur old/hotkeys-0.5.7.4/src/kbddef.c hotkeys-0.5.7.4/src/kbddef.c
--- old/hotkeys-0.5.7.4/src/kbddef.c	2004-12-24 15:40:50.000000000 -0500
+++ hotkeys-0.5.7.4/src/kbddef.c	2007-07-28 15:48:34.000000000 -0400
@@ -83,6 +83,8 @@
     { "VolUp",                  volUpKey,           XF86XK_AudioRaiseVolume },
     { "VolDown",                volDownKey,         XF86XK_AudioLowerVolume },
     { "Mute",                   muteKey,            XF86XK_AudioMute },
+    { "BacklightUp",            backlightUpKey,     XF86XK_BacklightUp },
+    { "BacklightDown",          backlightDownKey,   XF86XK_BacklightDown },
     { "WakeUp",                 wakeupKey,          XF86XK_WakeUp },
     { "PowerDown",              powerDownKey,       XF86XK_PowerOff },
     { "Sleep",                  sleepKey,           XF86XK_Standby },   /* either this is the Standby key or the next one... */
@@ -166,6 +168,29 @@
 }
 
 
+/*
+ *  upOrDown - 1 for up, -1 for down
+ */
+static void
+getBacklightAdj(int upOrDown, xmlNodePtr cur)
+{
+    char* tc;
+
+    tc = xmlGetProp( cur, "adj" );
+    if ( tc != NULL )
+    {
+        int v = atoi(tc);
+        if ( v > 0 && v < 100 )
+        {
+            if ( upOrDown == 1 )
+                backlightUpAdj = v;
+            else if ( upOrDown == -1 )
+                backlightDownAdj = -v;
+        }
+    }
+}
+
+
 static void
 parseStd(xmlDocPtr doc, xmlNodePtr cur)
 {
@@ -195,6 +220,11 @@
                     getVolAdj( 1, cur );
                 else if ( strncmp( defStr[i].name, "VolDown", 7 ) == 0 )
                     getVolAdj( -1, cur );
+                /* Get the backlight adjustment if the tag is BacklightUp or BacklightDown */
+                if ( strncmp( defStr[i].name, "BacklightUp", 11 ) == 0 )
+                    getBacklightAdj( 1, cur );
+                else if ( strncmp( defStr[i].name, "BacklightDown", 13 ) == 0 )
+                    getBacklightAdj( -1, cur );
 
                 return;     /* leave as nothing to be done */
             }       
diff --new-file -ur old/hotkeys-0.5.7.4/src/kbddef.h hotkeys-0.5.7.4/src/kbddef.h
--- old/hotkeys-0.5.7.4/src/kbddef.h	2004-12-24 15:42:03.000000000 -0500
+++ hotkeys-0.5.7.4/src/kbddef.h	2007-07-28 15:50:06.000000000 -0400
@@ -69,6 +69,8 @@
     volUpKey,
     volDownKey,
     muteKey,
+    backlightUpKey,
+    backlightDownKey,
     wakeupKey,
     powerDownKey,
     sleepKey,
diff --new-file -ur old/hotkeys-0.5.7.4/src/xbacklight.c hotkeys-0.5.7.4/src/xbacklight.c
--- old/hotkeys-0.5.7.4/src/xbacklight.c	1969-12-31 19:00:00.000000000 -0500
+++ hotkeys-0.5.7.4/src/xbacklight.c	2007-07-28 15:59:39.000000000 -0400
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2007 Keith Packard
+ * Modified by Joey Hess for hotkeys.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/Xrandr.h>
+
+#include "hotkeys.h"
+
+static Atom backlight;
+
+static long
+backlight_get (Display *dpy, RROutput output)
+{
+    unsigned long   nitems;
+    unsigned long   bytes_after;
+    unsigned char   *prop;
+    Atom	    actual_type;
+    int		    actual_format;
+    long	    value;
+    
+    if (XRRGetOutputProperty (dpy, output, backlight,
+			      0, 4, False, False, None,
+			      &actual_type, &actual_format,
+			      &nitems, &bytes_after, &prop) != Success)
+	return -1;
+    if (actual_type != XA_INTEGER || nitems != 1 || actual_format != 32)
+	value = -1;
+    else
+	value = *((long *) prop);
+    XFree (prop);
+    return value;
+}
+
+static void
+backlight_set (Display *dpy, RROutput output, long value)
+{
+    XRRChangeOutputProperty (dpy, output, backlight, XA_INTEGER, 32,
+			     PropModeReplace, (unsigned char *) &value, 1);
+}
+
+int
+xbacklight (Display *dpy, int change)
+{
+    int	    screen;
+    int	    major, minor;
+    int	    value = 0;
+    int	    i;
+    int	    total_time = 20;	/* ms */
+    int	    steps = 2;
+
+    if (!XRRQueryVersion (dpy, &major, &minor))
+    {
+	uError("RandR extension missing");
+	return -1;
+    }
+    if (major < 1 || (major == 1 && minor < 2))
+    {
+	uError("RandR version %d.%d too old", major, minor);
+	return -1;
+    }
+    backlight = XInternAtom (dpy, "BACKLIGHT", True);
+    if (backlight == None)
+    {
+	uError("No outputs have backlight property");
+	return -1;
+    }
+    for (screen = 0; screen < ScreenCount (dpy); screen++)
+    {
+	Window		    root = RootWindow (dpy, screen);
+	XRRScreenResources  *resources = XRRGetScreenResources (dpy, root);
+	int		    o;
+	
+	if (!resources) continue;
+	for (o = 0; o < resources->noutput; o++)
+	{
+	    RROutput	output = resources->outputs[o];
+	    XRRPropertyInfo *info;
+	    double    	cur, new, step;
+	    double	min, max;
+	    double	set;
+
+	    cur = backlight_get (dpy, output);
+	    if (cur != -1)
+	    {
+		info = XRRQueryOutputProperty (dpy, output, backlight);
+		if (info)
+		{
+		    if (info->range && info->num_values == 2)
+		    {
+			min = info->values[0];
+			max = info->values[1];
+			
+			set = value * (max - min) / 100;
+			new = cur + change;
+			
+			if (new > max) new = max;
+			if (new < min) new = min;
+			step = (new - cur) / steps;
+			for (i = 0; i < steps && step != 0; i++)
+			{
+				if (i == steps - 1)
+				    cur = new;
+				else
+				    cur += step;
+				backlight_set (dpy, output, (long) cur);
+				XFlush (dpy);
+				usleep (total_time * 1000 / steps);
+			}
+		    }
+		    XFree (info);
+		}
+	    }
+	}
+							   
+	XRRFreeScreenResources (resources);
+    }
+    XSync (dpy, False);
+
+    return 0;
+}
diff --new-file -ur old/hotkeys-0.5.7.4/src/xbacklight.h hotkeys-0.5.7.4/src/xbacklight.h
--- old/hotkeys-0.5.7.4/src/xbacklight.h	1969-12-31 19:00:00.000000000 -0500
+++ hotkeys-0.5.7.4/src/xbacklight.h	2007-07-28 15:38:45.000000000 -0400
@@ -0,0 +1 @@
+int xbacklight (Display *dpy, int change);

Attachment: signature.asc
Description: Digital signature

Reply via email to