[Pkg-wmaker-commits] [wmmixer] 08/24: Import Upstream version 1.5
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Sun Aug 27 13:12:52 UTC 2017
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository wmmixer.
commit 7ca18a0a90d5de02b3e8d7cd2b5b563c17ad5c3b
Author: Doug Torrance <dtorrance at piedmont.edu>
Date: Sun Aug 27 09:11:15 2017 -0400
Import Upstream version 1.5
---
CHANGES | 23 +
Makefile | 37 +-
README | 16 +-
XPM/.xvpics/norec.xpm | 5 +
XPM/.xvpics/wmmixer.xpm | Bin 0 -> 3666 bytes
XPM/.xvpics/wmmixer_new.xpm | Bin 0 -> 3666 bytes
XPM/.xvpics/wmmixer_new2.xpm | Bin 0 -> 3666 bytes
XPM/norec.xpm | 23 +-
XPM/wmmixer.xpm | 127 ++---
common.h | 30 ++
exception.cc | 53 ++
exception.h | 40 ++
home.wmmixer | 2 +-
mixctl.cc | 258 ++++++++++
mixctl.h | 230 +++------
wmmixer.1 | 5 +-
wmmixer.cc | 1099 +++++++++++++++++++-----------------------
wmmixer.h | 195 +++-----
xhandler.cc | 549 +++++++++++++++++++++
xhandler.h | 153 ++++++
20 files changed, 1856 insertions(+), 989 deletions(-)
diff --git a/CHANGES b/CHANGES
index b07bbf4..0a821ef 100644
--- a/CHANGES
+++ b/CHANGES
@@ -59,3 +59,26 @@ Release 1.1 3 Apr 2002 Adopted as obviously orhpaned:
Added manpage
Changed to GNU getopt command line parsing
Added simple Makefile, get rid of imake
+
+Release 1.2 25 May 2002 Merge Debian patches
+ Cleanup/Splitup MixCtl
+ Preparing for major rewrite...
+ Makefile updated again
+
+
+Release 1.3 26 May 2002 Change the whole thing to actual C++ code.
+ It is not yet pretty code, but it is a lot
+ better. Still, much work to do.
+
+Release 1.4 08 Jun 2002 Display only one bar for mono channels
+ (Taken from Damian Kramer's wmsmixer)
+ Split X code up into smaller pieces
+ Fix channel rotating (repeat timer)
+ Add mute button
+
+Release 1.5 25 Jun 2002 Several fixes (really open mixer device given
+ with -m, don't segfault when /dev/mixer is not
+ there, don't go to max if using scrollwheel to
+ set volume below 0)
+ Shaded LED-Bar
+ Initial Exception Handling
\ No newline at end of file
diff --git a/Makefile b/Makefile
index f2c489d..47cef3d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.0 2002/04/02 19:38:22 gordon Exp $
+# $Id: Makefile,v 1.5 2002/06/25 22:13:09 gordon Exp $
prefix = /usr/local
exec_prefix = ${prefix}
@@ -7,21 +7,39 @@ mandir = ${prefix}/share/man
DESTDIR =
-CFLAGS = -O2 -Wall -pedantic
-LIBS = -L/usr/X11R6/lib -lX11 -lXpm -lXext
+CXX = g++
+CXXFLAGS = -O -Wall
+EXTRA_LIBS = -L/usr/X11R6/lib -lX11 -lXpm -lXext
-all: wmmixer
-wmmixer: wmmixer.cc
- $(CC) $(LIBS) -o $@ $^
+LD = g++
+LDFLAGS = -o $(EXECUTABLE) $(EXTRA_LIBDIRS) $(EXTRA_LIBS) $(CXXFLAGS)
+
+EXECUTABLE = wmmixer
+OBJS = xhandler.o mixctl.o wmmixer.o exception.o
+
+INSTALL = install
+INSTALL_FILE = $(INSTALL) -D -p -o root -g root -m 644
+INSTALL_PROGRAM = $(INSTALL) -D -p -o root -g root -m 755
+
+.cc.o:
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+$(EXECUTABLE): $(OBJS)
+ $(LD) $(LDFLAGS) $(OBJS)
+
+all: $(EXECUTABLE)
+
+clean:
+ rm -f $(OBJS) $(EXECUTABLE)
install: install-bin install-doc
install-bin: wmmixer
- install -D -s -m 755 $< $(DESTDIR)$(bindir)/wmmixer
+ $(INSTALL_PROGRAM) $< $(DESTDIR)$(bindir)/wmmixer
install-doc: wmmixer.1
- install -D -m 644 $< $(DESTDIR)$(mandir)/man1/wmmixer.1
+ $(INSTALL_FILE) $< $(DESTDIR)$(mandir)/man1/wmmixer.1
uninstall: uninstall-bin uninstall-doc
@@ -31,9 +49,6 @@ uninstall-bin:
uninstall-doc:
rm -f $(DESTDIR)$(mandir)/man1/wmmixer.1
-clean:
- rm -f *.o wmmixer
-
.PHONY: all clean dist-clean install install-bin install-doc \
uninstall uninstall-bin uninstall-doc
diff --git a/README b/README
index c6b2b7d..5109cbb 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
wmmixer - A mixer designed for WindowMaker
-3 Apr 2002 Release 1.1
+25 June 2002 Release 1.5
Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
@@ -58,6 +58,20 @@ There is a also a button to set recording sources.
See the program's manpage ('man wmmixer') for detailed listings of the
available options.
+SHADED VOLUME BARS:
+===================
+As of version 1.5 wmmixer allows shading the volume bar in two colours.
+If you do not want this and prefer the traditional single-coloured
+look, you'll have to tell wmmixer to use the same colour for high and
+low colours:
+
+$ wmmixer -l green -L green
+...this will give you the traditional look.
+
+$ wmmixer -l lightgreen -L blue
+...this is an example for the new look. By default, green is used for low volume
+settings and fade to red for high volumes.
+
AFTERSTEP USERS:
================
diff --git a/XPM/.xvpics/norec.xpm b/XPM/.xvpics/norec.xpm
new file mode 100644
index 0000000..a24c8f2
--- /dev/null
+++ b/XPM/.xvpics/norec.xpm
@@ -0,0 +1,5 @@
+P7 332
+#IMGINFO:10x9 RGB (221 bytes)
+#END_OF_COMMENTS
+10 9 255
+�����������������������E(E(�����(%I$E)����(%I$E)����(%I$E)�����E(E(�����������������������
\ No newline at end of file
diff --git a/XPM/.xvpics/wmmixer.xpm b/XPM/.xvpics/wmmixer.xpm
new file mode 100644
index 0000000..7f099c5
Binary files /dev/null and b/XPM/.xvpics/wmmixer.xpm differ
diff --git a/XPM/.xvpics/wmmixer_new.xpm b/XPM/.xvpics/wmmixer_new.xpm
new file mode 100644
index 0000000..90e97ac
Binary files /dev/null and b/XPM/.xvpics/wmmixer_new.xpm differ
diff --git a/XPM/.xvpics/wmmixer_new2.xpm b/XPM/.xvpics/wmmixer_new2.xpm
new file mode 100644
index 0000000..4b98c9c
Binary files /dev/null and b/XPM/.xvpics/wmmixer_new2.xpm differ
diff --git a/XPM/norec.xpm b/XPM/norec.xpm
index 2b07db9..eaf0106 100644
--- a/XPM/norec.xpm
+++ b/XPM/norec.xpm
@@ -1,12 +1,15 @@
/* XPM */
static char * norec_xpm[] = {
-"6 7 2 1",
-" c #AEAAAE",
-". c #86828E",
-" .",
-" ... .",
-".. ...",
-". ..",
-".. ...",
-" ... .",
-" ."};
+"10 9 3 1",
+" c None",
+". c #AEAAAE",
+"+ c #353535",
+"..........",
+"..........",
+"...++++...",
+"..++++++..",
+"..++++++..",
+"..++++++..",
+"...++++...",
+"..........",
+".........."};
diff --git a/XPM/wmmixer.xpm b/XPM/wmmixer.xpm
index 537436c..d3ec49c 100644
--- a/XPM/wmmixer.xpm
+++ b/XPM/wmmixer.xpm
@@ -1,72 +1,75 @@
/* XPM */
static char * wmmixer_xpm[] = {
-"64 64 7 1",
+"64 64 10 1",
" c None",
-". c #000000000000",
-"X c #AEBAAAAAAEBA",
-"o c #28A228A228A2 s back_color",
-"O c #208120812081",
-"+ c #F7DEF3CEFFFF",
-"@ c #861782078E38",
+". c #000000",
+"+ c #AEAAAE",
+"@ c #282828",
+"# c #202020",
+"$ c #F7F3FF",
+"% c #86828E",
+"& c #FF0000",
+"* c #FA0808",
+"= c #FE0000",
" ",
" ",
" ",
" ",
-" .........................X ........................X ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .OooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" .ooooooooooooooooooooooooX .oooooooooooooooooooooooX ",
-" XXXXXXXXXXXXXXXXXXXXXXXXXX .oooooooooooooooooooooooX ",
-" .oooooooooooooooooooooooX ",
-" .oooooooooooooooooooooooX ",
-" .oooooooooooooooooooooooX ",
-" .oooooooooooooooooooooooX ",
-" .......................... .oooooooooooooooooooooooX ",
-" .+++++++++++ at +++++++++++@X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXXX.+XXXXXXXXXX.X .OooooooooooooooooooooooX ",
-" .+XXXXXX.XXX.+XXX.XXXXXX.X .OooooooooooooooooooooooX ",
-" .+XXXXX..XXX.+XXX..XXXXX.X .OooooooooooooooooooooooX ",
-" .+XXXX...XXX.+XXX...XXXX.X .oooooooooooooooooooooooX ",
-" .+XXX....XXX.+XXX....XXX.X .oooooooooooooooooooooooX ",
-" .+XXXX...XXX.+XXX...XXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXX..XXX.+XXX..XXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXX.XXX.+XXX.XXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXXX.+XXXXXXXXXX.X .oooooooooooooooooooooooX ",
-" . at ...........@...........X .oooooooooooooooooooooooX ",
-" XXXXXXXXXXXXXXXXXXXXXXXXXX .oooooooooooooooooooooooX ",
-" .oooooooooooooooooooooooX ",
-" .......................... .oooooooooooooooooooooooX ",
-" .+++++++++++++++++++++++ at X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXXXXXXXXXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXXXXXX.XXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXX...X.XXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXX..X...XXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXX.XXX..XXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXX..X...XXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXX...X.XXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXXXXXX.XXXXXXXX.X .oooooooooooooooooooooooX ",
-" .+XXXXXXXXXXXXXXXXXXXXXX.X .oooooooooooooooooooooooX ",
-" . at .......................X .oooooooooooooooooooooooX ",
-" XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX ",
+" .........................+ ........................+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .#@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@@+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" ++++++++++++++++++++++++++ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .......................... .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$$$$$$$$$$$%$$$$$$$$$$$%+ .#@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++++++.$++++++++++.+ .#@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++.+++.$+++.++++++.+ .#@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$+++++..+++.$+++..+++++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++...+++.$+++...++++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$+++....+++.$+++....+++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++...+++.$+++...++++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$+++++..+++.$+++..+++++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++.+++.$+++.++++++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++++++.$++++++++++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .%...........%...........+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" ++++++++++++++++++++++++++ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .......................... .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$$$$$$$$$$$%$$$$$$$$$$$%+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++++++.$&++++++++&.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++++++.$+&++++..&+.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$+++*&&=+++.$++&++.+.++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++**=*&=++.$++...+&.++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++*===*=++.$++.+&&+.++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++*===&=++.$++...+&.++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$+++*=&=+++.$++&++.+.++.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++++++.$+&++++..&+.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .$++++++++++.$&++++++++&.+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" .%...........%...........+ .@@@@@@@@@@@@@@@@@@@@@@@+ ",
+" ++++++++++++++++++++++++++ +++++++++++++++++++++++++ ",
" ",
" ",
" ",
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..dc3ade6
--- /dev/null
+++ b/common.h
@@ -0,0 +1,30 @@
+// common.h - Common defines and includes for wmmixer
+//
+// Release 1.5
+// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
+// This software comes with ABSOLUTELY NO WARRANTY
+// This software is free software, and you are welcome to redistribute it
+// under certain conditions
+// See the COPYING file for details.
+
+#ifndef __common_h__
+#define __common_h__
+
+// User defines - custom
+#define MIXERDEV "/dev/mixer"
+#define BACKCOLOR "#282828"
+#define LEDCOLOR "green"
+#define LEDCOLOR_HIGH "red"
+
+// User defines - standard
+#define WINDOWMAKER false
+#define USESHAPE false
+#define AFTERSTEP false
+#define NORMSIZE 64
+#define ASTEPSIZE 56
+#define NAME "wmmixer"
+#define CLASS "WMMixer"
+
+
+#endif //__common_h__
diff --git a/exception.cc b/exception.cc
new file mode 100644
index 0000000..a4fa261
--- /dev/null
+++ b/exception.cc
@@ -0,0 +1,53 @@
+// wmmixer - A mixer designed for WindowMaker
+//
+// Release 1.5
+// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
+// This software comes with ABSOLUTELY NO WARRANTY
+// This software is free software, and you are welcome to redistribute it
+// under certain conditions
+// See the COPYING file for details.
+
+#include "exception.h"
+
+
+//--------------------------------------------------------------------
+Exception::Exception()
+{
+ error_message_ = NULL;
+}
+
+//--------------------------------------------------------------------
+Exception::Exception(const Exception& exc)
+{
+ char* other_message = exc.getErrorMessage();
+
+ if(other_message != NULL)
+ {
+ error_message_ = new char[strlen(other_message)+1];
+ strcpy(error_message_, other_message);
+ }
+ else
+ error_message_ = NULL;
+}
+
+//--------------------------------------------------------------------
+Exception::~Exception()
+{
+ if(error_message_ != NULL)
+ delete[] error_message_;
+}
+
+//--------------------------------------------------------------------
+char* Exception::getErrorMessage() const
+{
+ return error_message_;
+}
+
+//--------------------------------------------------------------------
+MixerDeviceException::MixerDeviceException(char* device)
+{
+ error_message_ = new char[256];
+ strcpy(error_message_, "Unable to open mixer device ");
+ strcat(error_message_, device);
+}
diff --git a/exception.h b/exception.h
new file mode 100644
index 0000000..3923006
--- /dev/null
+++ b/exception.h
@@ -0,0 +1,40 @@
+// wmmixer - A mixer designed for WindowMaker
+//
+// Release 1.5
+// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
+// This software comes with ABSOLUTELY NO WARRANTY
+// This software is free software, and you are welcome to redistribute it
+// under certain conditions
+// See the COPYING file for details.
+
+
+#ifndef __exception_h__
+#define __exception_h__
+
+#include <stdlib.h>
+#include <string.h>
+
+//--------------------------------------------------------------------
+class Exception
+{
+ protected:
+ char* error_message_;
+
+ public:
+ Exception();
+ Exception(const Exception&);
+ virtual ~Exception();
+ char* getErrorMessage() const;
+};
+
+
+//--------------------------------------------------------------------
+class MixerDeviceException : public Exception
+{
+ public:
+ MixerDeviceException(char *);
+ // virtual ~MixerDeviceException();
+};
+
+#endif _exception_h__
diff --git a/home.wmmixer b/home.wmmixer
index c35352d..6e05f81 100644
--- a/home.wmmixer
+++ b/home.wmmixer
@@ -1,5 +1,5 @@
# wmmixer - A mixer designed for WindowMaker
-# 3 Apr 2002 Release 1.1
+# 8 Jun 2002 Release 1.4
# Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
# This software comes with ABSOLUTELY NO WARRANTY
# This software is free software, and you are welcome to redistribute it
diff --git a/mixctl.cc b/mixctl.cc
new file mode 100644
index 0000000..7cf3261
--- /dev/null
+++ b/mixctl.cc
@@ -0,0 +1,258 @@
+// mixctl.h - MixCtl class provides control of audio mixer functions
+//
+// Release 1.5
+// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
+// This software comes with ABSOLUTELY NO WARRANTY
+// This software is free software, and you are welcome to redistribute it
+// under certain conditions
+// See the COPYING file for details.
+
+
+
+#include "mixctl.h"
+
+//----------------------------------------------------------------------
+MixCtl::MixCtl(char *device_name) throw(MixerDeviceException)
+{
+ device_ = new char[strlen(device_name)+1];
+ strcpy(device_, device_name);
+
+ modify_counter = -1;
+
+ if((mixfd = open(device_,O_RDONLY | O_NONBLOCK)) != -1)
+ {
+ num_devices_ = SOUND_MIXER_NRDEVICES;
+ char *devnames[] = SOUND_DEVICE_NAMES;
+ char *devlabels[] = SOUND_DEVICE_LABELS;
+ ioctl(mixfd, SOUND_MIXER_READ_DEVMASK, &devmask);
+ ioctl(mixfd, SOUND_MIXER_READ_STEREODEVS, &stmask);
+ ioctl(mixfd, SOUND_MIXER_READ_RECMASK, &recmask);
+ ioctl(mixfd, SOUND_MIXER_READ_CAPS, &caps);
+
+ mixer_devices_ = new MixerDevice[num_devices_];
+ int mixmask = 1;
+
+ for(unsigned count=0; count<num_devices_; count++)
+ {
+ mixer_devices_[count].support = devmask & mixmask;
+ mixer_devices_[count].stereo = stmask & mixmask;
+ mixer_devices_[count].records = recmask & mixmask;
+ mixer_devices_[count].mask = mixmask;
+ mixer_devices_[count].name = devnames[count];
+ mixer_devices_[count].label = devlabels[count];
+ mixer_devices_[count].muted = 0;
+ mixmask*=2;
+ }
+ doStatus();
+ }
+ else
+ {
+ throw MixerDeviceException(device_name);
+ }
+}
+
+//----------------------------------------------------------------------
+MixCtl::~MixCtl()
+{
+ if(mixer_devices_ != NULL)
+ delete[](mixer_devices_);
+ close(mixfd);
+
+ delete[] device_;
+}
+
+//----------------------------------------------------------------------
+bool MixCtl::isMuted(int channel)
+{
+ return mixer_devices_[channel].muted;
+}
+
+//----------------------------------------------------------------------
+void MixCtl::mute(int channel)
+{
+ mixer_devices_[channel].muted = mixer_devices_[channel].value;
+ mixer_devices_[channel].value = 0;
+ writeVol(channel);
+}
+
+//----------------------------------------------------------------------
+void MixCtl::unmute(int channel)
+{
+ mixer_devices_[channel].value = mixer_devices_[channel].muted;
+ mixer_devices_[channel].muted = 0;
+ writeVol(channel);
+}
+
+//----------------------------------------------------------------------
+void MixCtl::doStatus()
+{
+ ioctl(mixfd, SOUND_MIXER_READ_RECSRC, &recsrc);
+ for(unsigned i=0;i<num_devices_;i++)
+ {
+ if(mixer_devices_[i].support)
+ {
+ ioctl(mixfd, MIXER_READ(i), &mixer_devices_[i].value);
+ }
+ mixer_devices_[i].recsrc=(recsrc & mixer_devices_[i].mask);
+ }
+}
+
+
+//----------------------------------------------------------------------
+// Return volume for a device, optionally reading it from device first.
+// Can be used as a way to avoid calling doStatus().
+int MixCtl::readVol(int dev, bool read)
+{
+ if(read)
+ {
+ ioctl(mixfd, MIXER_READ(dev), &mixer_devices_[dev].value);
+ }
+ return mixer_devices_[dev].value;
+}
+
+//----------------------------------------------------------------------
+// Return left and right componenets of volume for a device.
+// If you are lazy, you can call readVol to read from the device, then these
+// to get left and right values.
+int MixCtl::readLeft(int dev)
+{
+ return mixer_devices_[dev].value%256;
+}
+
+//----------------------------------------------------------------------
+int MixCtl::readRight(int dev)
+{
+ return mixer_devices_[dev].value/256;
+}
+
+//----------------------------------------------------------------------
+// Write volume to device. Use setVolume, setLeft and setRight first.
+void MixCtl::writeVol(int dev)
+{
+ ioctl(mixfd, MIXER_WRITE(dev), &mixer_devices_[dev].value);
+}
+
+//----------------------------------------------------------------------
+// Set volume (or left or right component) for a device. You must call writeVol to write it.
+void MixCtl::setVol(int dev, int value)
+{
+ mixer_devices_[dev].value=value;
+}
+//----------------------------------------------------------------------
+void MixCtl::setBoth(int dev, int l, int r)
+{
+ mixer_devices_[dev].value=256*r+l;
+}
+//----------------------------------------------------------------------
+void MixCtl::setLeft(int dev, int l)
+{
+ int r;
+ if(mixer_devices_[dev].stereo)
+ r=mixer_devices_[dev].value/256;
+ else
+ r=l;
+ mixer_devices_[dev].value=256*r+l;
+}
+//----------------------------------------------------------------------
+void MixCtl::setRight(int dev, int r)
+{
+ int l;
+ if(mixer_devices_[dev].stereo)
+ l=mixer_devices_[dev].value%256;
+ else
+ l=r;
+ mixer_devices_[dev].value=256*r+l;
+}
+
+//----------------------------------------------------------------------
+// Return record source value for a device, optionally reading it from device first.
+bool MixCtl::readRec(int dev, bool read)
+{
+ if(read)
+ {
+ ioctl(mixfd, SOUND_MIXER_READ_RECSRC, &recsrc);
+ mixer_devices_[dev].recsrc=(recsrc & mixer_devices_[dev].mask);
+ }
+ return mixer_devices_[dev].recsrc;
+}
+
+//----------------------------------------------------------------------
+// Write record source values to device. Use setRec first.
+void MixCtl::writeRec(){
+ ioctl(mixfd, SOUND_MIXER_WRITE_RECSRC, &recsrc);
+}
+
+//----------------------------------------------------------------------
+// Make a device (not) a record source.
+void MixCtl::setRec(int dev, bool rec)
+{
+ if(rec)
+ {
+ if(caps & SOUND_CAP_EXCL_INPUT)
+ recsrc=mixer_devices_[dev].mask;
+ else
+ recsrc|=mixer_devices_[dev].mask;
+ }
+ else
+ recsrc&=~mixer_devices_[dev].mask;
+}
+
+//----------------------------------------------------------------------
+// Return various other info
+char* MixCtl::getDevName()
+{
+ return device_;
+}
+//----------------------------------------------------------------------
+unsigned MixCtl::getNrDevices()
+{
+ return num_devices_;
+}
+//----------------------------------------------------------------------
+int MixCtl::getCapabilities()
+{
+ return caps;
+}
+//----------------------------------------------------------------------
+bool MixCtl::getSupport(int dev)
+{
+ return mixer_devices_[dev].support;
+}
+//----------------------------------------------------------------------
+bool MixCtl::getStereo(int dev)
+{
+ return mixer_devices_[dev].stereo;
+}
+//----------------------------------------------------------------------
+bool MixCtl::getRecords(int dev)
+{
+ return mixer_devices_[dev].records;
+}
+//----------------------------------------------------------------------
+char* MixCtl::getName(int dev)
+{
+ return mixer_devices_[dev].name;
+}
+//----------------------------------------------------------------------
+char* MixCtl::getLabel(int dev)
+{
+ return mixer_devices_[dev].label;
+}
+
+//----------------------------------------------------------------------
+bool MixCtl::hasChanged()
+{
+ struct mixer_info mixer_info;
+ ioctl(mixfd, SOUND_MIXER_INFO, &mixer_info);
+
+ if (mixer_info.modify_counter == modify_counter)
+ {
+ return false;
+ }
+ else
+ {
+ modify_counter = mixer_info.modify_counter;
+ return true;
+ }
+}
diff --git a/mixctl.h b/mixctl.h
index 6530460..2750693 100644
--- a/mixctl.h
+++ b/mixctl.h
@@ -1,12 +1,16 @@
// mixctl.h - MixCtl class provides control of audio mixer functions
-// 05/09/98 Release 1.0 Beta1
+//
+// Release 1.5
// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
// This software comes with ABSOLUTELY NO WARRANTY
// This software is free software, and you are welcome to redistribute it
// under certain conditions
// See the COPYING file for details.
-// Although mixctl.h is an integral part of wmmixer, it may also be distributed seperately.
+#ifndef __mixctl_h__
+#define __mixctl_h__
+
#include <stdio.h>
#include <stdlib.h>
@@ -15,6 +19,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <string.h>
#ifdef __NetBSD__
#include <soundcard.h>
#endif
@@ -25,173 +30,74 @@
#include <linux/soundcard.h>
#endif
-class MixCtl
-{
-public:
- MixCtl(char *dname){
- device=(char *)malloc(sizeof(char)*(strlen(dname)+1));
- strcpy(device,dname);
- if(mixfdopen=(mixfd=open(device,O_RDONLY | O_NONBLOCK))!=-1){
- nrdevices=SOUND_MIXER_NRDEVICES;
- char *devnames[]=SOUND_DEVICE_NAMES;
- char *devlabels[]=SOUND_DEVICE_LABELS;
- ioctl(mixfd, SOUND_MIXER_READ_DEVMASK, &devmask);
- ioctl(mixfd, SOUND_MIXER_READ_STEREODEVS, &stmask);
- ioctl(mixfd, SOUND_MIXER_READ_RECMASK, &recmask);
- ioctl(mixfd, SOUND_MIXER_READ_CAPS, &caps);
- mixdevs=(struct MixDev *)malloc(sizeof(struct MixDev)*nrdevices);
- int mixmask=1;
- for(int i=0;i<nrdevices;i++){
- mixdevs[i].support=devmask & mixmask;
- mixdevs[i].stereo=stmask & mixmask;
- mixdevs[i].records=recmask & mixmask;
- mixdevs[i].mask=mixmask;
- mixdevs[i].name=devnames[i];
- mixdevs[i].label=devlabels[i];
- mixmask*=2;
- }
- doStatus();
- }
- }
- ~MixCtl(){
- if(mixfdopen){
- if(mixdevs!=NULL)
- free(mixdevs);
- close(mixfd);
- }
- }
- bool openOK(){
- return mixfdopen;
- }
- void doStatus(){
- ioctl(mixfd, SOUND_MIXER_READ_RECSRC, &recsrc);
- for(int i=0;i<nrdevices;i++){
- if(mixdevs[i].support)
- ioctl(mixfd, MIXER_READ(i), &mixdevs[i].value);
- mixdevs[i].recsrc=(recsrc & mixdevs[i].mask);
- }
- }
+#include "exception.h"
- // Return volume for a device, optionally reading it from device first.
- // Can be used as a way to avoid calling doStatus().
- int readVol(int dev, bool read){
- if(read)
- ioctl(mixfd, MIXER_READ(dev), &mixdevs[dev].value);
- return mixdevs[dev].value;
- }
-
- // Return left and right componenets of volume for a device.
- // If you are lazy, you can call readVol to read from the device, then these
- // to get left and right values.
- int readLeft(int dev){
- return mixdevs[dev].value%256;
- }
- int readRight(int dev){
- return mixdevs[dev].value/256;
- }
+//----------------------------------------------------------------------
+struct _MixerDevice_{
+ bool support;
+ bool stereo;
+ bool recsrc;
+ bool records;
+ char *name;
+ char *label;
+ int value;
+ int mask;
+ int muted;
+};
+
+typedef struct _MixerDevice_ MixerDevice;
- // Write volume to device. Use setVolume, setLeft and setRight first.
- void writeVol(int dev){
- ioctl(mixfd, MIXER_WRITE(dev), &mixdevs[dev].value);
- }
+//----------------------------------------------------------------------
+class MixCtl
+{
+ protected:
+ int mixfd;
+ int mixfdopen;
+ char* device_;
+ int muted_;
- // Set volume (or left or right component) for a device. You must call writeVol to write it.
- void setVol(int dev, int value){
- mixdevs[dev].value=value;
- }
- void setBoth(int dev, int l, int r){
- mixdevs[dev].value=256*r+l;
- }
- void setLeft(int dev, int l){
- int r;
- if(mixdevs[dev].stereo)
- r=mixdevs[dev].value/256;
- else
- r=l;
- mixdevs[dev].value=256*r+l;
- }
- void setRight(int dev, int r){
- int l;
- if(mixdevs[dev].stereo)
- l=mixdevs[dev].value%256;
- else
- l=r;
- mixdevs[dev].value=256*r+l;
- }
+ unsigned num_devices_; // maximum number of devices
+ int devmask; // supported devices
+ int stmask; // stereo devices
+ int recmask; // devices which can be recorded from
+ int caps; // capabilities
+ int recsrc; // devices which are being recorded from
+ int modify_counter;
+ MixerDevice* mixer_devices_;
- // Return record source value for a device, optionally reading it from device first.
- bool readRec(int dev, bool read){
- if(read){
- ioctl(mixfd, SOUND_MIXER_READ_RECSRC, &recsrc);
- mixdevs[dev].recsrc=(recsrc & mixdevs[dev].mask);
- }
- return mixdevs[dev].recsrc;
- }
+ void doStatus();
+
+ public:
+ MixCtl(char *dname) throw(MixerDeviceException);
+ virtual ~MixCtl();
+ int readVol(int, bool);
+ int readLeft(int);
+ int readRight(int);
+ void writeVol(int);
- // Write record source values to device. Use setRec first.
- void writeRec(){
- ioctl(mixfd, SOUND_MIXER_WRITE_RECSRC, &recsrc);
- }
+ void setVol(int, int);
+ void setBoth(int, int, int);
+ void setLeft(int, int);
+ void setRight(int, int);
- // Make a device (not) a record source.
- void setRec(int dev, bool rec){
- if(rec){
- if(caps & SOUND_CAP_EXCL_INPUT)
- recsrc=mixdevs[dev].mask;
- else
- recsrc|=mixdevs[dev].mask;
- }
- else
- recsrc&=~mixdevs[dev].mask;
- }
+ bool readRec(int, bool);
+ void writeRec();
+ void setRec(int, bool);
- // Return various other info
- char *getDevName(){
- return device;
- }
- int getNrDevices(){
- return nrdevices;
- }
- int getCapabilities(){
- return caps;
- }
- bool getSupport(int dev){
- return mixdevs[dev].support;
- }
- bool getStereo(int dev){
- return mixdevs[dev].stereo;
- }
- bool getRecords(int dev){
- return mixdevs[dev].records;
- }
- char *getName(int dev){
- return mixdevs[dev].name;
- }
- char *getLabel(int dev){
- return mixdevs[dev].label;
- }
+ char *getDevName();
+ unsigned getNrDevices();
+ int getCapabilities();
+ bool getSupport(int);
+ bool getStereo(int);
+ bool getRecords(int);
+ char *getName(int);
+ char *getLabel(int);
+ bool hasChanged();
-private:
- int mixfd;
- int mixfdopen;
- char *device;
+ bool isMuted(int);
+ void mute(int);
+ void unmute(int);
+};
- struct MixDev{
- bool support;
- bool stereo;
- bool recsrc;
- bool records;
- char *name;
- char *label;
- int value;
- int mask;
- };
+#endif // __mixctl_h__
- int nrdevices; // maximum number of devices
- int devmask; // supported devices
- int stmask; // stereo devices
- int recmask; // devices which can be recorded from
- int caps; // capabilities
- int recsrc; // devices which are being recorded from
- struct MixDev *mixdevs;
-};
diff --git a/wmmixer.1 b/wmmixer.1
index becb2b4..4d26c51 100644
--- a/wmmixer.1
+++ b/wmmixer.1
@@ -40,7 +40,10 @@ use smaller window (for AfterStep Wharf)
shaped window
.TP
.B \-l, \-\-led\-color <\fIstring\fP>
-use the specified color for led, e.g. red, green, blue
+use the specified color for led, e.g. red, green, blue (default: green)
+.TP
+.B \-L, \-\-led\-highcolor <\fIstring\fP>
+use the specified color for led-shading, e.g. red, green, blue (default: red)
.TP
.B \-b, \-\-back\-color <\fIstring\fP>
use the specified color for backgrounds, e.g. red, green, blue
diff --git a/wmmixer.cc b/wmmixer.cc
index 5675718..3cbe4a0 100644
--- a/wmmixer.cc
+++ b/wmmixer.cc
@@ -1,325 +1,227 @@
-// wmmixer - A mixer designed for WindowMaker
-// 05/09/98 Release 1.0 Beta1
+// wmmixer.cc - A mixer designed for WindowMaker
+//
+// Release 1.5
// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
// This software comes with ABSOLUTELY NO WARRANTY
// This software is free software, and you are welcome to redistribute it
// under certain conditions
-// See the README file for a more complete notice.
-
-// 02/04/02 Gordon Fraser <gordon at debian.org>
-// * GNU getopt
-// * Mousewheel support
-// * X handling rewrite
+// See the COPYING file for details.
#include "wmmixer.h"
-// Implementation
-// --------------
+//--------------------------------------------------------------------
+WMMixer::WMMixer()
+{
+ // Initialize member variables
+ current_channel_ = 0;
+ num_channels_ = 0;
+ current_channel_left_ = 0;
+ current_channel_right_ = 0;
+ repeat_timer_ = 0;
+ wheel_scroll_ = 2;
+ current_recording_ = false;
+ current_show_recording_ = false;
+ dragging_ = false;
+
+ strcpy(mixer_device_, MIXERDEV);
+
+ xhandler_ = new XHandler();
+}
-int main(int argc, char **argv)
+//--------------------------------------------------------------------
+WMMixer::~WMMixer()
{
- scanArgs(argc, argv);
- initXWin(argc, argv);
-
- mixctl=new MixCtl(mixdev);
-
- if(!mixctl->openOK())
- fprintf(stderr,"%s : Unable to open mixer device '%s'.\n", NAME, mixdev);
- else{
- icon = new int[mixctl->getNrDevices()];
- channel = new int[mixctl->getNrDevices()];
-
- initialize_icon(mixctl->getNrDevices());
-
- for(int i=0;i<mixctl->getNrDevices();i++){
- if(mixctl->getSupport(i)){
- channel[channels]=i;
- channels++;
- }
- }
- }
+ delete[] channel_list_;
+ delete mixctl_;
+ delete xhandler_;
+}
+
+
+//--------------------------------------------------------------------
+void WMMixer::loop()
+{
+ XEvent xev;
- readFile();
-
- if(channels==0)
- fprintf(stderr,"%s : Sorry, no supported channels found.\n", NAME);
- else{
- checkVol(true);
-
- XEvent xev;
- XSelectInput(d_display, w_main, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
- XSelectInput(d_display, w_icon, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
- XMapWindow(d_display, w_main);
-
- bool done=false;
- while(!done){
- while(XPending(d_display)){
- XNextEvent(d_display, &xev);
- switch(xev.type){
- case Expose:
- repaint();
- break;
- case ButtonPress:
- pressEvent(&xev.xbutton);
- break;
- case ButtonRelease:
- releaseEvent(&xev.xbutton);
- break;
- case MotionNotify:
- motionEvent(&xev.xmotion);
- break;
- case ClientMessage:
- if(xev.xclient.data.l[0]==deleteWin)
- done=true;
- break;
+ bool done=false;
+ while(!done)
+ {
+ while(XPending(xhandler_->getDisplay()))
+ {
+ XNextEvent(xhandler_->getDisplay(), &xev);
+ switch(xev.type)
+ {
+ case Expose:
+ xhandler_->repaint();
+ break;
+ case ButtonPress:
+ pressEvent(&xev.xbutton);
+ break;
+ case ButtonRelease:
+ releaseEvent(&xev.xbutton);
+ break;
+ case MotionNotify:
+ motionEvent(&xev.xmotion);
+ break;
+ case ClientMessage:
+ if(xev.xclient.data.l[0] == (int)xhandler_->getDeleteWin())
+ done=true;
+ break;
+ }
}
- }
-
- if(btnstate & (BTNPREV | BTNNEXT)){
- rpttimer++;
- if(rpttimer>=RPTINTERVAL){
- if(btnstate & BTNNEXT)
- curchannel++;
- else
- curchannel--;
- if(curchannel<0)
- curchannel=channels-1;
- if(curchannel>=channels)
- curchannel=0;
- checkVol(true);
- rpttimer=0;
+
+ // keep a button pressed causes scrolling throught the channels
+ if(xhandler_->getButtonState() & (BTNPREV | BTNNEXT))
+ {
+ repeat_timer_++;
+ if(repeat_timer_ >= RPTINTERVAL)
+ {
+ if(xhandler_->getButtonState() & BTNNEXT)
+ {
+ current_channel_++;
+ if(current_channel_ >= num_channels_)
+ current_channel_ = 0;
+ }
+ else
+ {
+ if(current_channel_ < 1)
+ current_channel_ = num_channels_-1;
+ else
+ current_channel_--;
+ }
+
+ checkVol(true);
+ repeat_timer_ = 0;
+ }
}
- }
- else
- checkVol(false);
- XFlush(d_display);
- usleep(50000);
+ else
+ {
+ checkVol(false);
+ }
+
+ XFlush(xhandler_->getDisplay());
+ usleep(100000);
}
- }
- freeXWin();
- delete mixctl;
- return 0;
}
-void initialize_icon(int num) {
-
- int i;
-
- icon[0] = 0;
- icon[1] = 7;
- icon[2] = 8;
- icon[3] = 2;
- icon[4] = 1;
- icon[5] = 6;
- icon[6] = 4;
- icon[7] = 5;
- icon[8] = 3;
- for(i=9;i<num;i++)
- icon[i] = 9;
-}
-void initXWin(int argc, char **argv){
- int d_depth;
- int screen;
- int x_fd;
- int dummy = 0;
-
- XWMHints wmhints;
- XSizeHints shints;
- XClassHint classHint;
- XTextProperty name;
- char *wname = argv[0];
- XGCValues gcv;
- unsigned long gcm;
-
- winsize=astep ? ASTEPSIZE : NORMSIZE;
-
- if((d_display=XOpenDisplay(display))==NULL) {
- fprintf(stderr,"%s : Unable to open X display '%s'.\n", NAME, XDisplayName(display));
- exit(1);
- }
+//--------------------------------------------------------------------
+void WMMixer::init(int argc, char **argv)
+{
+ parseArgs(argc, argv);
- screen = DefaultScreen(d_display);
- w_root = RootWindow(d_display, screen);
- d_depth = DefaultDepth(d_display, screen);
- x_fd = XConnectionNumber(d_display);
-
- _XA_GNUSTEP_WM_FUNC=XInternAtom(d_display, "_GNUSTEP_WM_FUNCTION", false);
- deleteWin=XInternAtom(d_display, "WM_DELETE_WINDOW", false);
+ initMixer();
- w_root = RootWindow(d_display, screen);
+ readConfigurationFile();
- shints.x = 0;
- shints.y = 0;
- // shints.flags = USSize;
- shints.flags = 0; // Gordon
-
- back_pix = getColor("white");
- fore_pix = getColor("black");
-
- bool pos=(XWMGeometry(d_display, DefaultScreen(d_display), position, NULL, 0, &shints, &shints.x, &shints.y,
- &shints.width, &shints.height, &dummy) & (XValue | YValue));
- shints.min_width = winsize;
- shints.min_height = winsize;
- shints.max_width = winsize;
- shints.max_height = winsize;
- shints.base_width = winsize;
- shints.base_height = winsize;
- shints.width = winsize;
- shints.height = winsize;
- shints.flags=PMinSize | PMaxSize | PBaseSize; // Gordon
-
-
- w_main = XCreateSimpleWindow(d_display, w_root, shints.x, shints.y,
- shints.width, shints.height, 0, fore_pix, back_pix);
-
- w_icon = XCreateSimpleWindow(d_display, w_root, shints.x, shints.y,
- shints.width, shints.height, 0, fore_pix, back_pix);
-
- XSetWMNormalHints(d_display, w_main, &shints);
-
-
- wmhints.icon_x = shints.x;
- wmhints.icon_y = shints.y;
-
- if(wmaker || astep || pos)
- shints.flags |= USPosition;
-
- if(wmaker){
- wmhints.initial_state = WithdrawnState;
- wmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
- wmhints.icon_window = w_icon;
-
- wmhints.icon_x = shints.x;
- wmhints.icon_y = shints.y;
- wmhints.window_group = w_main;
- } else {
- wmhints.initial_state = NormalState;
- wmhints.flags = WindowGroupHint | StateHint;
- }
-
- classHint.res_name=NAME;
- classHint.res_class=CLASS;
-
- XSetClassHint(d_display, w_main, &classHint);
- XSetClassHint(d_display, w_icon, &classHint);
-
-
- if (XStringListToTextProperty(&wname, 1, &name) == 0) {
- fprintf(stderr, "%s: can't allocate window name\n", wname);
- exit(1);
- }
-
- XSetWMName(d_display, w_main, &name);
-
- gcm = GCForeground | GCBackground | GCGraphicsExposures;
- gcv.graphics_exposures = 0;
- gcv.foreground = fore_pix;
- gcv.background = back_pix;
- gc_gc=XCreateGC(d_display, w_root, gcm, &gcv);
-
- XSetWMHints(d_display, w_main, &wmhints);
-
- XSetCommand(d_display, w_main, argv, argc);
-
- XSetWMProtocols(d_display, w_main, &deleteWin, 1); // Close
-
- color[0]=mixColor(ledcolor, 0, backcolor, 100);
- color[1]=mixColor(ledcolor, 100, backcolor, 0);
- color[2]=mixColor(ledcolor, 60, backcolor, 40);
- color[3]=mixColor(ledcolor, 25, backcolor, 75);
-
- XpmAttributes xpmattr;
- XpmColorSymbol xpmcsym[4]={{"back_color", NULL, color[0]},
- {"led_color_high", NULL, color[1]},
- {"led_color_med", NULL, color[2]},
- {"led_color_low", NULL, color[3]}};
- xpmattr.numsymbols = 4;
- xpmattr.colorsymbols=xpmcsym;
- xpmattr.exactColors=false;
- xpmattr.closeness=40000;
- xpmattr.valuemask=XpmColorSymbols | XpmExactColors | XpmCloseness;
-
-
- XpmCreatePixmapFromData(d_display, w_root, wmmixer_xpm, &pm_main, &pm_mask, &xpmattr);
- XpmCreatePixmapFromData(d_display, w_root, tile_xpm, &pm_tile, NULL, &xpmattr);
- XpmCreatePixmapFromData(d_display, w_root, icons_xpm, &pm_icon, NULL, &xpmattr);
- XpmCreatePixmapFromData(d_display, w_root, norec_xpm, &pm_nrec, NULL, &xpmattr);
- pm_disp = XCreatePixmap(d_display, w_root, 64, 64, d_depth);
-
- if(wmaker || ushape || astep) {
- XShapeCombineMask(d_display, w_icon, ShapeBounding, winsize/2-32, winsize/2-32, pm_mask, ShapeSet);
- XShapeCombineMask(d_display, w_main, ShapeBounding, winsize/2-32, winsize/2-32, pm_mask, ShapeSet);
- } else {
- XCopyArea(d_display, pm_tile, pm_disp, gc_gc, 0, 0, 64, 64, 0, 0);
- }
-
-
- XSetClipMask(d_display, gc_gc, pm_mask);
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, 0, 0, 64, 64, 0, 0);
- XSetClipMask(d_display, gc_gc, None);
-
- XStoreName(d_display, w_main, NAME);
- XSetIconName(d_display, w_main, NAME);
-}
+ xhandler_->init(argc, argv, mixctl_->getNrDevices());
-void freeXWin(){
- XFreeGC(d_display, gc_gc);
- XFreePixmap(d_display, pm_main);
- XFreePixmap(d_display, pm_tile);
- XFreePixmap(d_display, pm_disp);
- XFreePixmap(d_display, pm_mask);
- XFreePixmap(d_display, pm_icon);
- XFreePixmap(d_display, pm_nrec);
-
- XDestroyWindow(d_display, w_main);
- if(wmaker)
- XDestroyWindow(d_display, w_icon);
- XCloseDisplay(d_display);
+ if(num_channels_ == 0)
+ {
+ std::cerr << NAME << " : Sorry, no supported channels found." << std::endl;
+ }
+ else
+ {
+ checkVol(true);
+ }
}
-void createWin(Window *win, int x, int y){
- XClassHint classHint;
- if((*win=XCreateSimpleWindow(d_display, w_root, x, y, winsize, winsize, 0, back_pix, fore_pix)) == 0) {
- fprintf(stderr,"Fail: XCreateSimpleWindow\n");
- exit(-1);
- }
-
-
- classHint.res_name=NAME;
- classHint.res_class=CLASS;
- XSetClassHint(d_display, *win, &classHint);
-}
+//--------------------------------------------------------------------
+void WMMixer::initMixer()
+{
+ // Initialize Mixer
+ try
+ {
+ mixctl_ = new MixCtl(mixer_device_);
+ }
+ catch(MixerDeviceException &exc)
+ {
+ std::cerr << NAME << " : " << exc.getErrorMessage() << "'." << std::endl;
+ exit(1);
+ }
-unsigned long getColor(char *colorname){
- XColor color;
- XWindowAttributes winattr;
- XGetWindowAttributes(d_display, w_root, &winattr);
- color.pixel=0;
- XParseColor(d_display, winattr.colormap, colorname, &color);
- color.flags=DoRed | DoGreen | DoBlue;
- XAllocColor(d_display, winattr.colormap, &color);
- return color.pixel;
+ channel_list_ = new unsigned[mixctl_->getNrDevices()];
+
+ for(unsigned count=0; count<mixctl_->getNrDevices(); count++)
+ {
+ if(mixctl_->getSupport(count)){
+ channel_list_[num_channels_]=count;
+ num_channels_++;
+ }
+ }
}
-unsigned long mixColor(char *colorname1, int prop1, char *colorname2, int prop2){
- XColor color, color1, color2;
- XWindowAttributes winattr;
- XGetWindowAttributes(d_display, w_root, &winattr);
- XParseColor(d_display, winattr.colormap, colorname1, &color1);
- XParseColor(d_display, winattr.colormap, colorname2, &color2);
- color.pixel=0;
- color.red=(color1.red*prop1+color2.red*prop2)/(prop1+prop2);
- color.green=(color1.green*prop1+color2.green*prop2)/(prop1+prop2);
- color.blue=(color1.blue*prop1+color2.blue*prop2)/(prop1+prop2);
- color.flags=DoRed | DoGreen | DoBlue;
- XAllocColor(d_display, winattr.colormap, &color);
- return color.pixel;
+
+//--------------------------------------------------------------------
+void WMMixer::checkVol(bool forced = true)
+{
+ if(!forced && !mixctl_->hasChanged())
+ return;
+
+ if(mixctl_->isMuted(channel_list_[current_channel_]))
+ xhandler_->setButtonState(xhandler_->getButtonState() | BTNMUTE);
+ else
+ xhandler_->setButtonState(xhandler_->getButtonState() & ~BTNMUTE);
+
+
+ mixctl_->readVol(channel_list_[current_channel_], true);
+ unsigned nl = mixctl_->readLeft(channel_list_[current_channel_]);
+ unsigned nr = mixctl_->readRight(channel_list_[current_channel_]);
+ bool nrec = mixctl_->readRec(channel_list_[current_channel_], true);
+
+ if(forced)
+ {
+ current_channel_left_ = nl;
+ current_channel_right_ = nr;
+ current_recording_ = nrec;
+ if(nrec)
+ xhandler_->setButtonState(xhandler_->getButtonState() | BTNREC);
+ else
+ xhandler_->setButtonState(xhandler_->getButtonState() & ~BTNREC);
+ current_show_recording_=mixctl_->getRecords(channel_list_[current_channel_]);
+ updateDisplay();
+ }
+ else
+ {
+ if(nl != current_channel_left_ || nr != current_channel_right_ || nrec != current_recording_)
+ {
+ if(nl!=current_channel_left_)
+ {
+ current_channel_left_=nl;
+ if(mixctl_->getStereo(channel_list_[current_channel_]))
+ xhandler_->drawLeft(current_channel_left_);
+ else
+ xhandler_->drawMono(current_channel_left_);
+ }
+ if(nr!=current_channel_right_)
+ {
+ current_channel_right_=nr;
+ if(mixctl_->getStereo(channel_list_[current_channel_]))
+ xhandler_->drawRight(current_channel_right_);
+ else
+ xhandler_->drawMono(current_channel_left_);
+ }
+ if(nrec!=current_recording_)
+ {
+ current_recording_=nrec;
+ if(nrec)
+ xhandler_->setButtonState(xhandler_->getButtonState() | BTNREC);
+ else
+ xhandler_->setButtonState(xhandler_->getButtonState() & ~BTNREC);
+ xhandler_->drawBtns(BTNREC, current_show_recording_);
+ }
+ updateDisplay();
+ }
+ }
}
-void scanArgs(int argc, char **argv){
+
+
+//--------------------------------------------------------------------
+void WMMixer::parseArgs(int argc, char **argv)
+{
static struct option long_opts[] = {
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'v'},
@@ -329,6 +231,7 @@ void scanArgs(int argc, char **argv){
{"afterstep", 0, NULL, 'a'},
{"shaped", 0, NULL, 's'},
{"led-color", 1, NULL, 'l'},
+ {"led-highcolor", 1, NULL, 'L'},
{"back-color", 1, NULL, 'b'},
{"mix-device", 1, NULL, 'm'},
{"scrollwheel",1, NULL, 'r'},
@@ -337,362 +240,342 @@ void scanArgs(int argc, char **argv){
// For backward compatibility
- for(i=1; i<argc; i++) {
- if(strcmp("-position", argv[i]) == 0) {
- sprintf(argv[i], "%s", "-g");
- } else if(strcmp("-help", argv[i]) == 0) {
- sprintf(argv[i], "%s", "-h");
- } else if(strcmp("-display", argv[i]) == 0) {
- sprintf(argv[i], "%s", "-d");
+ for(i=1; i<argc; i++)
+ {
+ if(strcmp("-position", argv[i]) == 0)
+ {
+ sprintf(argv[i], "%s", "-g");
+ }
+ else if(strcmp("-help", argv[i]) == 0)
+ {
+ sprintf(argv[i], "%s", "-h");
+ }
+ else if(strcmp("-display", argv[i]) == 0)
+ {
+ sprintf(argv[i], "%s", "-d");
+ }
}
- }
- while ((i = getopt_long(argc, argv, "hvd:g:wasl:b:m:r:", long_opts, &opt_index)) != -1) {
- switch (i) {
- case 'h':
- case ':':
- case '?':
- usage(argv[0]);
- break;
- case 'v':
- version();
- break;
- case 'd':
- sprintf(display, "%s", optarg);
- break;
- case 'g':
- sprintf(position, "%s", optarg);
- break;
- case 'w':
- wmaker = 1;
- break;
- case 'a':
- astep = 1;
- break;
- case 's':
- ushape = 1;
- break;
- case 'l':
- sprintf(ledcolor, "%s", optarg);
- break;
- case 'b':
- sprintf(backcolor, "%s", optarg);
- break;
- case 'm':
- sprintf(mixdev, "%s", optarg);
- break;
- case 'r':
- if(atoi(optarg)>0)
- wheel_scroll = atoi(optarg);
- break;
+ while ((i = getopt_long(argc, argv, "hvd:g:wasl:L:b:m:r:", long_opts, &opt_index)) != -1)
+ {
+ switch (i)
+ {
+ case 'h':
+ case ':':
+ case '?':
+ displayUsage(argv[0]);
+ break;
+ case 'v':
+ displayVersion();
+ break;
+ case 'd':
+ xhandler_->setDisplay(optarg);
+ break;
+ case 'g':
+ xhandler_->setPosition(optarg);
+ break;
+ case 'w':
+ xhandler_->setWindowMaker();
+ break;
+ case 'a':
+ xhandler_->setAfterStep();
+ break;
+ case 's':
+ xhandler_->setUnshaped();
+ break;
+ case 'l':
+ xhandler_->setLedColor(optarg);
+ break;
+ case 'L':
+ xhandler_->setLedHighColor(optarg);
+ break;
+ case 'b':
+ xhandler_->setBackColor(optarg);
+ break;
+ case 'm':
+ sprintf(mixer_device_, "%s", optarg);
+ break;
+ case 'r':
+ if(atoi(optarg)>0)
+ wheel_scroll_ = atoi(optarg);
+ break;
+ }
}
- }
-
}
-void readFile(){
+//--------------------------------------------------------------------
+void WMMixer::readConfigurationFile()
+{
FILE *rcfile;
char rcfilen[256];
char buf[256];
int done;
- int current=-1;
+ // int current=-1;
+ unsigned current = mixctl_->getNrDevices() + 1;
+
sprintf(rcfilen, "%s/.wmmixer", getenv("HOME"));
- if((rcfile=fopen(rcfilen, "r"))!=NULL){
- channels=0;
- do{
- fgets(buf, 250, rcfile);
- if((done=feof(rcfile))==0){
- buf[strlen(buf)-1]=0;
- if(strncmp(buf, "addchannel ", strlen("addchannel "))==0){
- sscanf(buf, "addchannel %i", ¤t);
- if(current>=mixctl->getNrDevices() || mixctl->getSupport(current)==false){
- fprintf(stderr,"%s : Sorry, this channel (%i) is not supported.\n", NAME, current);
- current=-1;
- }
- else{
- channel[channels]=current;
- channels++;
- }
- }
- if(strncmp(buf, "setchannel ", strlen("setchannel "))==0){
- sscanf(buf, "setchannel %i", ¤t);
- if(current>=mixctl->getNrDevices() || mixctl->getSupport(current)==false){
- fprintf(stderr,"%s : Sorry, this channel (%i) is not supported.\n", NAME, current);
- current=-1;
- }
- }
- if(strncmp(buf, "setmono ", strlen("setmono "))==0){
- if(current==-1)
+ if((rcfile=fopen(rcfilen, "r"))!=NULL)
+ {
+ num_channels_=0;
+ do
+ {
+ fgets(buf, 250, rcfile);
+ if((done=feof(rcfile))==0)
+ {
+ buf[strlen(buf)-1]=0;
+ if(strncmp(buf, "addchannel ", strlen("addchannel "))==0)
+ {
+ sscanf(buf, "addchannel %i", ¤t);
+ if(current >= mixctl_->getNrDevices() || mixctl_->getSupport(current) == false)
+ {
+ fprintf(stderr,"%s : Sorry, this channel (%i) is not supported.\n", NAME, current);
+ current = mixctl_->getNrDevices() + 1;
+ }
+ else
+ {
+ channel_list_[num_channels_] = current;
+ num_channels_++;
+ }
+ }
+ if(strncmp(buf, "setchannel ", strlen("setchannel "))==0)
+ {
+ sscanf(buf, "setchannel %i", ¤t);
+ if(current >= mixctl_->getNrDevices() || mixctl_->getSupport(current)==false)
+ {
+ fprintf(stderr,"%s : Sorry, this channel (%i) is not supported.\n", NAME, current);
+ current = mixctl_->getNrDevices() + 1;
+ }
+ }
+ if(strncmp(buf, "setmono ", strlen("setmono "))==0)
+ {
+ if(current== mixctl_->getNrDevices() + 1)
fprintf(stderr,"%s : Sorry, no current channel.\n", NAME);
- else{
+ else{
int value;
sscanf(buf, "setmono %i", &value);
- mixctl->setLeft(current, value);
- mixctl->setRight(current, value);
- mixctl->writeVol(current);
- }
- }
- if(strncmp(buf, "setleft ", strlen("setleft "))==0){
- if(current==-1)
+ mixctl_->setLeft(current, value);
+ mixctl_->setRight(current, value);
+ mixctl_->writeVol(current);
+ }
+ }
+ if(strncmp(buf, "setleft ", strlen("setleft "))==0)
+ {
+ if(current== mixctl_->getNrDevices() + 1)
fprintf(stderr, "%s : Sorry, no current channel.\n", NAME);
- else{
+ else{
int value;
sscanf(buf, "setleft %i", &value);
- mixctl->setLeft(current, value);
- mixctl->writeVol(current);
+ mixctl_->setLeft(current, value);
+ mixctl_->writeVol(current);
}
}
- if(strncmp(buf, "setright ", strlen("setright "))==0){
- if(current==-1)
+ if(strncmp(buf, "setright ", strlen("setright "))==0)
+ {
+ if(current== mixctl_->getNrDevices() + 1)
fprintf(stderr, "%s : Sorry, no current channel.\n", NAME);
- else{
- int value;
- sscanf(buf, "setleft %i", &value);
- mixctl->setRight(current, value);
- mixctl->writeVol(current);
- }
- }
- if(strncmp(buf, "setrecsrc ", strlen("setrecsrc "))==0){
- if(current==-1)
+ else
+ {
+ int value;
+ sscanf(buf, "setleft %i", &value);
+ mixctl_->setRight(current, value);
+ mixctl_->writeVol(current);
+ }
+ }
+ if(strncmp(buf, "setrecsrc ", strlen("setrecsrc "))==0)
+ {
+ if(current== mixctl_->getNrDevices() + 1)
fprintf(stderr, "%s : Sorry, no current channel.\n", NAME);
- else
- mixctl->setRec(current, (strncmp(buf+strlen("setrecsrc "), "true", strlen("true"))==0));
- }
- }
- } while(done==0);
- fclose(rcfile);
- mixctl->writeRec();
- }
+ else
+ mixctl_->setRec(current, (strncmp(buf+strlen("setrecsrc "), "true", strlen("true"))==0));
+ }
+ }
+ }
+ while(done==0);
+ fclose(rcfile);
+ mixctl_->writeRec();
+ }
}
-void checkVol(bool forced=true){
- mixctl->readVol(channel[curchannel], true);
- int nl=mixctl->readLeft(channel[curchannel]);
- int nr=mixctl->readRight(channel[curchannel]);
- bool nrec=mixctl->readRec(channel[curchannel], true);
- if(forced){
- curleft=nl;
- curright=nr;
- currec=nrec;
- if(nrec)
- btnstate |= BTNREC;
- else
- btnstate &= ~BTNREC;
- curshowrec=mixctl->getRecords(channel[curchannel]);
- update();
- repaint();
- }
- else{
- if(nl!=curleft || nr!=curright || nrec!=currec){
- if(nl!=curleft){
- curleft=nl;
- drawLeft();
- }
- if(nr!=curright){
- curright=nr;
- drawRight();
- }
- if(nrec!=currec){
- currec=nrec;
- if(nrec)
- btnstate |= BTNREC;
- else
- btnstate &= ~BTNREC;
- drawBtns(BTNREC);
- }
- repaint();
- }
- }
-}
+//--------------------------------------------------------------------
+void WMMixer::displayUsage(const char* name)
+{
+ std::cout << "Usage: " << name << "[options]" << std::endl;
+ std::cout << " -h, --help display this help screen" << std::endl;
+ std::cout << " -v, --version display program version" << std::endl;
+ std::cout << " -d, --display <string> display to use (see X manual pages)" << std::endl;
+ std::cout << " -g, --geometry +XPOS+YPOS geometry to use (see X manual pages)" << std::endl;
+ std::cout << " -w, --withdrawn run the application in withdrawn mode" << std::endl;
+ std::cout << " (for WindowMaker, etc)" << std::endl;
+ std::cout << " -a, --afterstep use smaller window (for AfterStep Wharf)" << std::endl;
+ std::cout << " -s, --shaped shaped window" << std::endl;
+ std::cout << " -l, --led-color <string> use the specified color for led display" << std::endl;
+ std::cout << " -L, --led-highcolor <string> use the specified color for led shading" << std::endl;
+ std::cout << " -b, --back-color <string> use the specified color for backgrounds" << std::endl;
+ std::cout << " -m, --mix-device use specified device (rather than /dev/mixer)" << std::endl;
+ std::cout << " -r, --scrollwheel <number> volume increase/decrease with mouse wheel (default: 2)" << std::endl;
+ std::cout << "\nFor backward compatibility the following obsolete options are still supported:" << std::endl;
+ std::cout << " -help display this help screen" << std::endl;
+ std::cout << " -position geometry to use (see X manual pages)" << std::endl;
+ std::cout << " -display display to use (see X manual pages)" << std::endl;
+ exit(0);
-void pressEvent(XButtonEvent *xev) {
- int x=xev->x-(winsize/2-32);
- int y=xev->y-(winsize/2-32);
- if(x>=5 && y>=33 && x<=16 && y<=43){
- curchannel--;
- if(curchannel<0)
- curchannel=channels-1;
- btnstate |= BTNPREV;
- rpttimer=0;
- drawBtns(BTNPREV);
- checkVol(true);
- return;
- }
- if(x>=17 && y>=33 && x<=28 && y<=43){
- curchannel++;
- if(curchannel>=channels)
- curchannel=0;
- btnstate|=BTNNEXT;
- rpttimer=0;
- drawBtns(BTNNEXT);
- checkVol(true);
- return;
- }
- if(x>=37 && x<=56 && y>=8 && y<=56) {
- int v = 0;
- if(xev->button < 4) {
- v = ((60-y)*100)/(2*25);
- dragging=true;
-
- } else if(xev->button == 4) {
- if(x>50)
- v = mixctl->readRight(channel[curchannel]) + wheel_scroll;
- else if(x<45)
- v = mixctl->readLeft(channel[curchannel]) + wheel_scroll;
- else
- v = (mixctl->readLeft(channel[curchannel]) + mixctl->readRight(channel[curchannel]))/2 + wheel_scroll;
-
- } else if(xev->button == 5) {
- if(x>50)
- v = mixctl->readRight(channel[curchannel]) - wheel_scroll;
- else if(x<45)
- v = mixctl->readLeft(channel[curchannel]) - wheel_scroll;
- else
- v = (mixctl->readLeft(channel[curchannel]) + mixctl->readRight(channel[curchannel]))/2 - wheel_scroll;
-
- }
- if(x<=50)
- mixctl->setLeft(channel[curchannel], v);
- if(x>=45)
- mixctl->setRight(channel[curchannel], v);
- mixctl->writeVol(channel[curchannel]);
- checkVol(false);
- return;
- }
- if(x>=5 && y>=47 && x<=28 && y<=57){
- mixctl->setRec(channel[curchannel], !mixctl->readRec(channel[curchannel], false));
- mixctl->writeRec();
- checkVol(false);
- }
}
-void releaseEvent(XButtonEvent *xev){
- dragging=false;
- btnstate &= ~(BTNPREV | BTNNEXT);
- drawBtns(BTNPREV | BTNNEXT);
- repaint();
+//--------------------------------------------------------------------
+void WMMixer::displayVersion()
+{
+ std::cout << "wmmixer version 1.5" << std::endl;
+ exit(0);
}
-void motionEvent(XMotionEvent *xev){
- int x=xev->x-(winsize/2-32);
- int y=xev->y-(winsize/2-32);
- if(x>=37 && x<=56 && y>=8 && dragging){
- int v=((60-y)*100)/(2*25);
- if(v<0)
- v=0;
- if(x<=50)
- mixctl->setLeft(channel[curchannel], v);
- if(x>=45)
- mixctl->setRight(channel[curchannel], v);
- mixctl->writeVol(channel[curchannel]);
- checkVol(false);
- }
-}
-void repaint() {
- flush_expose(w_icon);
- XCopyArea(d_display, pm_disp, w_icon, gc_gc, 0, 0, 64, 64, winsize/2-32, winsize/2-32);
- flush_expose(w_main);
- XCopyArea(d_display, pm_disp, w_main, gc_gc, 0, 0, 64, 64, winsize/2-32, winsize/2-32);
+//--------------------------------------------------------------------
+void WMMixer::pressEvent(XButtonEvent *xev)
+{
+ bool forced_update = true;
+ int x = xev->x-(xhandler_->getWindowSize()/2-32);
+ int y = xev->y-(xhandler_->getWindowSize()/2-32);
+
+ if(xhandler_->isLeftButton(x, y))
+ {
+ if(current_channel_ < 1)
+ current_channel_=num_channels_-1;
+ else
+ current_channel_--;
- XEvent xev;
- while(XCheckTypedEvent(d_display, Expose, &xev));
-}
+ xhandler_->setButtonState(xhandler_->getButtonState() | BTNPREV);
+ repeat_timer_ = 0;
+ xhandler_->drawBtns(BTNPREV, current_show_recording_);
+ }
-void update() {
- if(wmaker || ushape || astep) {
- XShapeCombineMask(d_display, w_icon, ShapeBounding, winsize/2-32, winsize/2-32, pm_mask, ShapeSet);
- XShapeCombineMask(d_display, w_main, ShapeBounding, winsize/2-32, winsize/2-32, pm_mask, ShapeSet);
- } else {
- XCopyArea(d_display, pm_tile, pm_disp, gc_gc, 0, 0, 64, 64, 0, 0);
- }
+ if(xhandler_->isRightButton(x, y))
+ {
+ current_channel_++;
+ if(current_channel_ >= num_channels_)
+ current_channel_=0;
- XSetClipMask(d_display, gc_gc, pm_mask);
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, 0, 0, 64, 64, 0, 0);
- XSetClipMask(d_display, gc_gc, None);
-
- XCopyArea(d_display, pm_icon, pm_disp, gc_gc, icon[channel[curchannel]]*22, 0, 22, 22, 6, 5);
- drawLeft();
- drawRight();
- drawBtns(BTNREC | BTNNEXT | BTNPREV);
-}
+ xhandler_->setButtonState(xhandler_->getButtonState() | BTNNEXT);
+ repeat_timer_ = 0;
+ xhandler_->drawBtns(BTNNEXT, current_show_recording_);
+ }
-void drawLeft() {
- XSetForeground(d_display, gc_gc, color[1]);
- for(int i=0;i<25;i++){
- if(i==(curleft*25)/100)
- XSetForeground(d_display, gc_gc, color[3]);
- XFillRectangle(d_display, pm_disp, gc_gc, 37, 55-2*i, 9, 1);
- }
-}
+ // Volume settings
+ if(xhandler_->isVolumeBar(x, y))
+ {
+ int vl = 0, vr = 0;
+
+ if(xev->button < 4)
+ {
+ vl = ((60-y)*100)/(2*25);
+ vr = vl;
+ dragging_ = true;
+ }
+ else if(xev->button == 4)
+ {
+ vr = mixctl_->readRight(channel_list_[current_channel_]) + wheel_scroll_;
+ vl = mixctl_->readLeft(channel_list_[current_channel_]) + wheel_scroll_;
+
+ }
+ else if(xev->button == 5)
+ {
+ vr = mixctl_->readRight(channel_list_[current_channel_]) - wheel_scroll_;
+ vl = mixctl_->readLeft(channel_list_[current_channel_]) - wheel_scroll_;
+ }
-void drawRight() {
- XSetForeground(d_display, gc_gc, color[1]);
- for(int i=0;i<25;i++){
- if(i==(curright*25)/100)
- XSetForeground(d_display, gc_gc, color[3]);
- XFillRectangle(d_display, pm_disp, gc_gc, 48, 55-2*i, 9, 1);
- }
+ if(vl <= 0)
+ vl = 0;
+ if(vr <= 0)
+ vr = 0;
+
+ if(x <= 50)
+ mixctl_->setLeft(channel_list_[current_channel_], vl);
+ if(x >= 45)
+ mixctl_->setRight(channel_list_[current_channel_], vr);
+ mixctl_->writeVol(channel_list_[current_channel_]);
+
+ forced_update = false;
+ }
+
+ // Toggle record
+ if(xhandler_->isRecButton(x, y))
+ {
+ mixctl_->setRec(channel_list_[current_channel_], !mixctl_->readRec(channel_list_[current_channel_], false));
+ mixctl_->writeRec();
+ forced_update = false;
+ }
+
+ // Toggle mute
+ if(xhandler_->isMuteButton(x, y))
+ {
+ if(mixctl_->isMuted(channel_list_[current_channel_]))
+ {
+ xhandler_->setButtonState(xhandler_->getButtonState() & ~BTNMUTE);
+ mixctl_->unmute(channel_list_[current_channel_]);
+ }
+ else
+ {
+ mixctl_->mute(channel_list_[current_channel_]);
+ xhandler_->setButtonState(xhandler_->getButtonState() | BTNMUTE);
+ }
+
+ xhandler_->drawBtns(BTNMUTE, current_show_recording_);
+ }
+
+ // Update volume display
+ checkVol(forced_update);
}
-void drawBtns(int btns) {
- if(btns & BTNPREV)
- drawBtn(5, 33, 12, 11, (btnstate & BTNPREV));
- if(btns & BTNNEXT)
- drawBtn(17, 33, 12, 11, (btnstate & BTNNEXT));
- if(btns & BTNREC){
- drawBtn(5, 47, 24, 11, (btnstate & BTNREC));
- if(!curshowrec)
- XCopyArea(d_display, pm_nrec, pm_disp, gc_gc, 0, 0, 6, 7, 14, 49);
- else
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, 14, 49, 6, 7, 14, 49);
- }
+//--------------------------------------------------------------------
+void WMMixer::releaseEvent(XButtonEvent *xev)
+{
+ dragging_ = false;
+ xhandler_->setButtonState(xhandler_->getButtonState() & ~(BTNPREV | BTNNEXT));
+ xhandler_->drawBtns(BTNPREV | BTNNEXT, current_show_recording_);
+ xhandler_->repaint();
}
-void drawBtn(int x, int y, int w, int h, bool down) {
- if(!down)
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, w, h, x, y);
- else {
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, 1, h-1, x+w-1, y+1);
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, x+w-1, y+1, 1, h-1, x, y);
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, w-1, 1, x+1, y+h-1);
- XCopyArea(d_display, pm_main, pm_disp, gc_gc, x+1, y+h-1, w-1, 1, x, y);
+//--------------------------------------------------------------------
+void WMMixer::motionEvent(XMotionEvent *xev)
+{
+ int x=xev->x-(xhandler_->getWindowSize()/2-32);
+ int y=xev->y-(xhandler_->getWindowSize()/2-32);
+ // if(x>=37 && x<=56 && y>=8 && dragging_){
+ if(xhandler_->isVolumeBar(x, y) && dragging_){
+ int v=((60-y)*100)/(2*25);
+ if(v<0)
+ v=0;
+ if(x<=50)
+ mixctl_->setLeft(channel_list_[current_channel_], v);
+ if(x>=45)
+ mixctl_->setRight(channel_list_[current_channel_], v);
+ mixctl_->writeVol(channel_list_[current_channel_]);
+ checkVol(false);
}
}
-void usage(const char *name) {
- printf("Usage: %s [options]\n", name);
- printf(" -h, --help display this help screen\n");
- printf(" -v, --version display program version\n");
- printf(" -d, --display <string> display to use (see X manual pages)\n");
- printf(" -g, --geometry +XPOS+YPOS geometry to use (see X manual pages)\n");
- printf(" -w, --withdrawn run the application in withdrawn mode\n");
- printf(" (for WindowMaker, etc)\n");
- printf(" -a, --afterstep use smaller window (for AfterStep Wharf)\n");
- printf(" -s, --shaped shaped window\n");
- printf(" -l, --led-color <string> use the specified color for led display\n");
- printf(" -b, --back-color <string> use the specified color for backgrounds\n");
- printf(" -m, --mix-device use specified device (rather than /dev/mixer)\n");
- printf(" -r, --scrollwheel <number> volume increase/decrease with mouse wheel (default: 2)\n");
- printf("\nFor backward compatibility the following obsolete options are still supported:\n");
- printf(" -help display this help screen\n");
- printf(" -position geometry to use (see X manual pages)\n");
- printf(" -display display to use (see X manual pages)\n");
- exit(0);
+//--------------------------------------------------------------------
+void WMMixer::updateDisplay()
+{
+ xhandler_->update(channel_list_[current_channel_]);
+ if(mixctl_->getStereo(channel_list_[current_channel_]))
+ {
+ xhandler_->drawLeft(current_channel_left_);
+ xhandler_->drawRight(current_channel_right_);
+ }
+ else
+ {
+ xhandler_->drawMono(current_channel_right_);
+ }
+ xhandler_->drawBtns(BTNREC | BTNNEXT | BTNPREV | BTNMUTE, current_show_recording_);
+ xhandler_->repaint();
}
-void version() {
- printf("wmmixer version 1.0\n");
- exit(0);
-}
-static int flush_expose(Window w) {
- XEvent dummy;
- int i=0;
-
- while (XCheckTypedWindowEvent(d_display, w, Expose, &dummy))
- i++;
-
- return i;
-}
+//====================================================================
+int main(int argc, char** argv)
+{
+ WMMixer mixer = WMMixer();
+ mixer.init(argc, argv);
+ mixer.loop();
+}
diff --git a/wmmixer.h b/wmmixer.h
index a95a2bb..2e0968e 100644
--- a/wmmixer.h
+++ b/wmmixer.h
@@ -1,158 +1,87 @@
-// wmmixer - A mixer designed for WindowMaker
-// 05/09/98 Release 1.0 Beta1
+// wmmixer.h - A mixer designed for WindowMaker
+//
+// Release 1.5
// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
// This software comes with ABSOLUTELY NO WARRANTY
// This software is free software, and you are welcome to redistribute it
// under certain conditions
-// See the README file for a more complete notice.
+// See the COPYING file for details.
-// 02/04/02 Gordon Fraser <gordon at debian.org>
-// * GNU getopt
-// * Mousewheel support
-// * X handling rewrite
+#ifndef __wmmixer_h__
+#define __wmmixer_h_
-// Defines, includes and global variables
-// --------------------------------------
-
-// User defines - standard
-#define WINDOWMAKER false
-#define USESHAPE false
-#define AFTERSTEP false
-#define NORMSIZE 64
-#define ASTEPSIZE 56
-#define NAME "wmmixer"
-#define CLASS "WMMixer"
-
-// User defines - custom
-#define MIXERDEV "/dev/mixer"
-#define BACKCOLOR "#282828"
-#define LEDCOLOR "green"
-
-// Includes - standard
+// Input/Output
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
#include <getopt.h>
-// Includes - custom
-#include "mixctl.h"
+#include <iostream>
-// X-Windows includes - standard
#include <X11/X.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xproto.h>
-#include <X11/xpm.h>
-#include <X11/extensions/shape.h>
-
-// Pixmaps - standard
-Pixmap pm_main;
-Pixmap pm_tile;
-Pixmap pm_disp;
-Pixmap pm_mask;
-
-// Pixmaps - custom
-Pixmap pm_icon;
-Pixmap pm_nrec;
-
-// Xpm images - standard
-#include "XPM/wmmixer.xpm"
-#include "XPM/tile.xpm"
-
-// Xpm images - custom
-#include "XPM/icons.xpm"
-#include "XPM/norec.xpm"
-
-// Variables for command-line arguments - standard
-bool wmaker=WINDOWMAKER;
-bool ushape=USESHAPE;
-bool astep=AFTERSTEP;
-char display[256]="";
-char position[256]="";
-int winsize;
-
-// Variables for command-line arguments - custom
-char mixdev[256]=MIXERDEV;
-char backcolor[256]=BACKCOLOR;
-char ledcolor[256]=LEDCOLOR;
-
-// X-Windows basics - standard
-Atom _XA_GNUSTEP_WM_FUNC;
-Atom deleteWin;
-Display *d_display;
-Window w_icon;
-Window w_main;
-Window w_root;
-
-// X-Windows basics - custom
-GC gc_gc;
-unsigned long color[4];
-
-
-// Misc custom global variables
-// ----------------------------
-
-// Current state information
-int curchannel=0;
-bool curshowrec;
-bool currec;
-int curleft;
-int curright;
-
-// For buttons
-int btnstate=0;
-#define BTNNEXT 1
-#define BTNPREV 2
-#define BTNREC 4
+
+// WMMixer
+#include "mixctl.h"
+#include "xhandler.h"
+#include "common.h"
+#include "exception.h"
// For repeating next and prev buttons
#define RPTINTERVAL 5
-int rpttimer=0;
-// For draggable volume control
-bool dragging=false;
-int channels=0;
-int *channel;
-int *icon;
+class WMMixer
+{
+ protected:
+
+ // Mixer
+ MixCtl *mixctl_;
+
+ char mixer_device_[256];
+ unsigned num_channels_;
+ unsigned current_channel_;
+ unsigned current_channel_left_;
+ unsigned current_channel_right_;
+ bool current_recording_;
+ bool current_show_recording_;
-MixCtl *mixctl;
+ XHandler *xhandler_;
-Pixel back_pix;
-Pixel fore_pix;
+ unsigned *channel_list_;
+ int repeat_timer_;
+
+ // For draggable volume control
+ bool dragging_;
// Default scroll amount
-int wheel_scroll = 2;
-
-
-// Procedures and functions
-// ------------------------
-
-// Procedures and functions - standard
-void initXWin(int argc, char **argv);
-void freeXWin();
-void createWin(Window *win, int x, int y);
-unsigned long getColor(char *colorname);
-unsigned long mixColor(char *colorname1, int prop1, char *colorname2, int prop2);
-
-// Procedures and functions - custom
-void scanArgs(int argc, char **argv);
-void readFile();
-void checkVol(bool forced=true);
-void pressEvent(XButtonEvent *xev);
-void releaseEvent(XButtonEvent *xev);
-void motionEvent(XMotionEvent *xev);
-void repaint();
-void update();
-void drawLeft();
-void drawRight();
-void drawBtns(int btns);
-void drawBtn(int x, int y, int w, int h, bool down);
-void initialize_icon(int num);
-static int flush_expose(Window w);
-void version(void);
-void usage(const char *);
+ int wheel_scroll_;
+
+ // Input/Output
+ void readConfigurationFile();
+ void displayVersion(void);
+ void displayUsage(const char*);
+ void checkVol(bool);
+
+ void motionEvent(XMotionEvent *xev);
+ void releaseEvent(XButtonEvent *xev);
+ void pressEvent(XButtonEvent *xev);
+ void parseArgs(int , char **);
+
+ void initMixer();
+ void initXHandler();
+
+ void updateDisplay();
+
+ public:
+ WMMixer();
+ ~WMMixer();
+
+ void init(int, char **);
+ void loop();
+};
+
+#endif //__wmmixer_h__
diff --git a/xhandler.cc b/xhandler.cc
new file mode 100644
index 0000000..652335d
--- /dev/null
+++ b/xhandler.cc
@@ -0,0 +1,549 @@
+// wmmixer - A mixer designed for WindowMaker
+//
+// Release 1.5
+// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
+// This software comes with ABSOLUTELY NO WARRANTY
+// This software is free software, and you are welcome to redistribute it
+// under certain conditions
+// See the COPYING file for details.
+
+#include "xhandler.h"
+
+//--------------------------------------------------------------------
+XHandler::XHandler()
+{
+ is_wmaker_ = WINDOWMAKER;
+ is_ushape_ = USESHAPE;
+ is_astep_ = AFTERSTEP;
+
+ strcpy(display_name_, "");
+ strcpy(position_name_, "");
+ strcpy(ledcolor_name_, LEDCOLOR);
+ strcpy(ledcolor_high_name_, LEDCOLOR_HIGH);
+ strcpy(backcolor_name_, BACKCOLOR);
+
+ button_state_ = 0;
+}
+
+//--------------------------------------------------------------------
+XHandler::~XHandler()
+{
+ XFreeGC(display_default_, graphics_context_);
+ XFreePixmap(display_default_, pixmap_main);
+ XFreePixmap(display_default_, pixmap_tile);
+ XFreePixmap(display_default_, pixmap_disp);
+ XFreePixmap(display_default_, pixmap_mask);
+ XFreePixmap(display_default_, pixmap_icon);
+ XFreePixmap(display_default_, pixmap_nrec);
+
+ XDestroyWindow(display_default_, window_main_);
+
+ if(is_wmaker_)
+ XDestroyWindow(display_default_, window_icon_);
+
+ XCloseDisplay(display_default_);
+
+ delete[] icon_list_;
+}
+
+
+//--------------------------------------------------------------------
+void XHandler::init(int argc, char** argv, int num_channels)
+{
+ int display_depth;
+
+ window_size_=is_astep_ ? ASTEPSIZE : NORMSIZE;
+
+ if((display_default_ = XOpenDisplay(display_name_))==NULL)
+ {
+ std::cerr << NAME << " : Unable to open X display '" << XDisplayName(display_name_) << "'." << std::endl;
+ exit(1);
+ }
+
+ initWindow(argc, argv);
+
+ initColors();
+
+ display_depth = DefaultDepth(display_default_, DefaultScreen(display_default_));
+ initPixmaps(display_depth);
+
+ initGraphicsContext();
+
+ initMask();
+
+ initIcons(num_channels);
+}
+
+
+//--------------------------------------------------------------------
+bool XHandler::isLeftButton(int x, int y)
+{
+ return(x>=BTN_LEFT_X && y>=BTN_LEFT_Y && x<=BTN_LEFT_X + BTN_WIDTH && y<=BTN_LEFT_Y + BTN_HEIGHT);
+}
+
+//--------------------------------------------------------------------
+bool XHandler::isRightButton(int x, int y)
+{
+ return(x>=BTN_RIGHT_X && y>=BTN_RIGHT_Y && x<=BTN_RIGHT_X + BTN_WIDTH && y<=BTN_RIGHT_Y + BTN_HEIGHT);
+}
+
+//--------------------------------------------------------------------
+bool XHandler::isMuteButton(int x, int y)
+{
+ return(x>=BTN_MUTE_X && y>=BTN_MUTE_Y && x<=BTN_MUTE_X + BTN_WIDTH && y<=BTN_MUTE_Y + BTN_HEIGHT);
+}
+
+//--------------------------------------------------------------------
+bool XHandler::isRecButton(int x, int y)
+{
+ return(x>=BTN_REC_X && y>=BTN_REC_Y && x<=BTN_REC_X + BTN_WIDTH && y<=BTN_REC_Y + BTN_HEIGHT);
+}
+
+//--------------------------------------------------------------------
+bool XHandler::isVolumeBar(int x, int y)
+{
+ return(x>=37 && x<=56 && y>=8 && y<=56);
+}
+
+//--------------------------------------------------------------------
+unsigned long XHandler::getColor(char *colorname)
+{
+ XColor color;
+ XWindowAttributes winattr;
+
+ XGetWindowAttributes(display_default_, window_root_, &winattr);
+ color.pixel=0;
+ XParseColor(display_default_, winattr.colormap, colorname, &color);
+ color.flags=DoRed | DoGreen | DoBlue;
+ XAllocColor(display_default_, winattr.colormap, &color);
+
+ return color.pixel;
+}
+
+//--------------------------------------------------------------------
+unsigned long XHandler::mixColor(char *colorname1, int prop1, char *colorname2, int prop2)
+{
+ XColor color, color1, color2;
+ XWindowAttributes winattr;
+
+ XGetWindowAttributes(display_default_, window_root_, &winattr);
+
+ XParseColor(display_default_, winattr.colormap, colorname1, &color1);
+ XParseColor(display_default_, winattr.colormap, colorname2, &color2);
+
+ color.pixel = 0;
+ color.red = (color1.red*prop1+color2.red*prop2)/(prop1+prop2);
+ color.green = (color1.green*prop1+color2.green*prop2)/(prop1+prop2);
+ color.blue = (color1.blue*prop1+color2.blue*prop2)/(prop1+prop2);
+ color.flags = DoRed | DoGreen | DoBlue;
+
+ XAllocColor(display_default_, winattr.colormap, &color);
+
+ return color.pixel;
+}
+
+//--------------------------------------------------------------------
+void XHandler::repaint()
+{
+ flush_expose(window_icon_);
+ XCopyArea(display_default_, pixmap_disp, window_icon_, graphics_context_, 0, 0, 64, 64, window_size_/2-32, window_size_/2-32);
+ flush_expose(window_main_);
+ XCopyArea(display_default_, pixmap_disp, window_main_, graphics_context_, 0, 0, 64, 64, window_size_/2-32, window_size_/2-32);
+
+ XEvent xev;
+ while(XCheckTypedEvent(display_default_, Expose, &xev));
+}
+
+//--------------------------------------------------------------------
+void XHandler::update(unsigned channel)
+{
+ if(is_wmaker_ || is_ushape_ || is_astep_)
+ {
+ XShapeCombineMask(display_default_, window_icon_, ShapeBounding, window_size_/2-32, window_size_/2-32, pixmap_mask, ShapeSet);
+ XShapeCombineMask(display_default_, window_main_, ShapeBounding, window_size_/2-32, window_size_/2-32, pixmap_mask, ShapeSet);
+ }
+ else
+ {
+ XCopyArea(display_default_, pixmap_tile, pixmap_disp, graphics_context_, 0, 0, 64, 64, 0, 0);
+ }
+
+ XSetClipMask(display_default_, graphics_context_, pixmap_mask);
+ XCopyArea(display_default_, pixmap_main, pixmap_disp, graphics_context_, 0, 0, 64, 64, 0, 0);
+ XSetClipMask(display_default_, graphics_context_, None);
+ XCopyArea(display_default_, pixmap_icon, pixmap_disp, graphics_context_, icon_list_[channel]*22, 0, 22, 22, 6, 5);
+}
+
+//--------------------------------------------------------------------
+void XHandler::drawLeft(unsigned curleft)
+{
+ XSetForeground(display_default_, graphics_context_, shade_colors_[(curleft*25)/100]);
+ for(unsigned i=0;i<25;i++)
+ {
+ if(i >= (curleft*25)/100)
+ {
+ XSetForeground(display_default_, graphics_context_, colors_[3]);
+ }
+ else
+ {
+ XSetForeground(display_default_, graphics_context_, shade_colors_[i]);
+ }
+ XFillRectangle(display_default_, pixmap_disp, graphics_context_, 37, 55-2*i, 9, 1);
+ }
+}
+
+//--------------------------------------------------------------------
+void XHandler::drawRight(unsigned curright)
+{
+ for(unsigned i=0;i<25;i++)
+ {
+ if(i >= (curright*25)/100)
+ {
+ XSetForeground(display_default_, graphics_context_, colors_[3]);
+ }
+ else
+ {
+ XSetForeground(display_default_, graphics_context_, shade_colors_[i]);
+ }
+ XFillRectangle(display_default_, pixmap_disp, graphics_context_, 48, 55-2*i, 9, 1);
+ }
+}
+
+//--------------------------------------------------------------------
+// Based on wmsmixer by Damian Kramer <psiren at hibernaculum.demon.co.uk>
+void XHandler::drawMono(unsigned curright)
+{
+ XSetForeground(display_default_, graphics_context_, colors_[1]);
+ for(unsigned i=0;i<25;i++)
+ {
+ if(i >= (curright*25)/100)
+ {
+ XSetForeground(display_default_, graphics_context_, colors_[3]);
+ }
+ else
+ {
+ XSetForeground(display_default_, graphics_context_, shade_colors_[i]);
+ }
+ XFillRectangle(display_default_, pixmap_disp, graphics_context_, 37, 55-2*i, 20, 1);
+ }
+}
+
+
+//--------------------------------------------------------------------
+void XHandler::drawBtns(int buttons, bool curshowrec)
+{
+ if(buttons & BTNPREV)
+ drawButton(BTN_LEFT_X, BTN_LEFT_Y, BTN_WIDTH, BTN_HEIGHT, (button_state_ & BTNPREV));
+
+ if(buttons & BTNNEXT)
+ drawButton(BTN_RIGHT_X, BTN_RIGHT_Y, BTN_WIDTH, BTN_HEIGHT, (button_state_ & BTNNEXT));
+
+ if(buttons & BTNMUTE)
+ drawButton(BTN_MUTE_X, BTN_MUTE_Y, BTN_WIDTH, BTN_HEIGHT, (button_state_ & BTNMUTE));
+
+ if(buttons & BTNREC){
+ drawButton(BTN_REC_X, BTN_REC_Y, BTN_WIDTH, BTN_HEIGHT, (button_state_ & BTNREC));
+
+ if(!curshowrec)
+ XCopyArea(display_default_, pixmap_nrec, pixmap_disp, graphics_context_, 0, 0, 9, 8, 6, 47);
+ else
+ XCopyArea(display_default_, pixmap_main, pixmap_disp, graphics_context_, 6, 48, 9, 8, 6, 47);
+ }
+}
+
+//--------------------------------------------------------------------
+void XHandler::drawButton(int x, int y, int w, int h, bool down)
+{
+ if(!down)
+ XCopyArea(display_default_, pixmap_main, pixmap_disp, graphics_context_, x, y, w, h, x, y);
+ else {
+ XCopyArea(display_default_, pixmap_main, pixmap_disp, graphics_context_, x, y, 1, h-1, x+w-1, y+1);
+ XCopyArea(display_default_, pixmap_main, pixmap_disp, graphics_context_, x+w-1, y+1, 1, h-1, x, y);
+ XCopyArea(display_default_, pixmap_main, pixmap_disp, graphics_context_, x, y, w-1, 1, x+1, y+h-1);
+ XCopyArea(display_default_, pixmap_main, pixmap_disp, graphics_context_, x+1, y+h-1, w-1, 1, x, y);
+ }
+}
+
+//--------------------------------------------------------------------
+int XHandler::flush_expose(Window w)
+{
+ XEvent dummy;
+ int i=0;
+
+ while (XCheckTypedWindowEvent(display_default_, w, Expose, &dummy))
+ i++;
+
+ return i;
+}
+
+
+//--------------------------------------------------------------------
+int XHandler::getWindowSize()
+{
+ return window_size_;
+}
+
+//--------------------------------------------------------------------
+// --> inline
+//Display* XHandler::getDisplay()
+//{
+// return display_default_;
+//}
+
+
+//--------------------------------------------------------------------
+int XHandler::getButtonState()
+{
+ return button_state_;
+}
+
+//--------------------------------------------------------------------
+void XHandler::setButtonState(int button_state)
+{
+ button_state_ = button_state;
+}
+
+//--------------------------------------------------------------------
+void XHandler::setDisplay(char* arg)
+{
+ sprintf(display_name_, "%s", arg);
+}
+
+//--------------------------------------------------------------------
+void XHandler::setPosition(char* arg)
+{
+ sprintf(position_name_, "%s", arg);
+}
+
+//--------------------------------------------------------------------
+void XHandler::setLedColor(char* arg)
+{
+ sprintf(ledcolor_name_, "%s", arg);
+}
+
+//--------------------------------------------------------------------
+void XHandler::setLedHighColor(char* arg)
+{
+ sprintf(ledcolor_high_name_, "%s", arg);
+}
+
+//--------------------------------------------------------------------
+void XHandler::setBackColor(char* arg)
+{
+ sprintf(backcolor_name_, "%s", arg);
+}
+
+//--------------------------------------------------------------------
+void XHandler::setUnshaped()
+{
+ is_ushape_ = 1;
+}
+
+//--------------------------------------------------------------------
+void XHandler::setWindowMaker()
+{
+ is_wmaker_ = 1;
+}
+
+//--------------------------------------------------------------------
+void XHandler::setAfterStep()
+{
+ is_astep_ = 1;
+}
+
+//--------------------------------------------------------------------
+Atom XHandler::getDeleteWin()
+{
+ return deleteWin;
+}
+
+
+//--------------------------------------------------------------------
+void XHandler::initIcons(int num)
+{
+ if(icon_list_)
+ delete[] icon_list_;
+
+ icon_list_ = new unsigned[num];
+
+ icon_list_[0] = 0;
+ icon_list_[1] = 7;
+ icon_list_[2] = 8;
+ icon_list_[3] = 2;
+ icon_list_[4] = 1;
+ icon_list_[5] = 6;
+ icon_list_[6] = 4;
+ icon_list_[7] = 5;
+ icon_list_[8] = 3;
+ for(int counter=9; counter<num; counter++)
+ icon_list_[counter] = 9;
+}
+
+//--------------------------------------------------------------------
+void XHandler::initGraphicsContext()
+{
+ XGCValues gcv;
+ unsigned long gcm;
+
+ gcm = GCForeground | GCBackground | GCGraphicsExposures;
+ gcv.graphics_exposures = 0;
+ gcv.foreground = fore_pix;
+ gcv.background = back_pix;
+ graphics_context_ = XCreateGC(display_default_, window_root_, gcm, &gcv);
+}
+
+//--------------------------------------------------------------------
+void XHandler::initPixmaps(int display_depth)
+{
+ XpmColorSymbol xpmcsym[4]={{"back_color", NULL, colors_[0]},
+ {"led_color_high", NULL, colors_[1]},
+ {"led_color_med", NULL, colors_[2]},
+ {"led_color_low", NULL, colors_[3]}};
+ XpmAttributes xpmattr;
+
+ xpmattr.numsymbols = 4;
+ xpmattr.colorsymbols = xpmcsym;
+ xpmattr.exactColors = false;
+ xpmattr.closeness = 40000;
+ xpmattr.valuemask = XpmColorSymbols | XpmExactColors | XpmCloseness;
+
+ XpmCreatePixmapFromData(display_default_, window_root_, wmmixer_xpm, &pixmap_main, &pixmap_mask, &xpmattr);
+ XpmCreatePixmapFromData(display_default_, window_root_, tile_xpm, &pixmap_tile, NULL, &xpmattr);
+ XpmCreatePixmapFromData(display_default_, window_root_, icons_xpm, &pixmap_icon, NULL, &xpmattr);
+ XpmCreatePixmapFromData(display_default_, window_root_, norec_xpm, &pixmap_nrec, NULL, &xpmattr);
+
+ pixmap_disp = XCreatePixmap(display_default_, window_root_, 64, 64, display_depth);
+}
+
+
+//--------------------------------------------------------------------
+void XHandler::initWindow(int argc, char** argv)
+{
+ char *wname = argv[0];
+ int screen, dummy = 0;
+ XWMHints wmhints;
+ XSizeHints shints;
+ XClassHint classHint;
+ XTextProperty name;
+
+ screen = DefaultScreen(display_default_);
+ _XA_GNUSTEP_WM_FUNC = XInternAtom(display_default_, "_GNUSTEP_WM_FUNCTION", false);
+ deleteWin = XInternAtom(display_default_, "WM_DELETE_WINDOW", false);
+
+
+ shints.x = 0;
+ shints.y = 0;
+ // shints.flags = USSize;
+ shints.flags = 0; // Gordon
+
+ bool pos = (XWMGeometry(display_default_, DefaultScreen(display_default_),
+ position_name_, NULL, 0, &shints, &shints.x, &shints.y,
+ &shints.width, &shints.height, &dummy)
+ & (XValue | YValue));
+ shints.min_width = window_size_;
+ shints.min_height = window_size_;
+ shints.max_width = window_size_;
+ shints.max_height = window_size_;
+ shints.base_width = window_size_;
+ shints.base_height = window_size_;
+ shints.width = window_size_;
+ shints.height = window_size_;
+ shints.flags=PMinSize | PMaxSize | PBaseSize; // Gordon
+
+
+ window_root_ = RootWindow(display_default_, screen);
+
+ back_pix = getColor("white");
+ fore_pix = getColor("black");
+
+ window_main_ = XCreateSimpleWindow(display_default_, window_root_, shints.x, shints.y,
+ shints.width, shints.height, 0, fore_pix, back_pix);
+
+ window_icon_ = XCreateSimpleWindow(display_default_, window_root_, shints.x, shints.y,
+ shints.width, shints.height, 0, fore_pix, back_pix);
+
+ XSetWMNormalHints(display_default_, window_main_, &shints);
+
+
+ wmhints.icon_x = shints.x;
+ wmhints.icon_y = shints.y;
+
+ if(is_wmaker_ || is_astep_ || pos)
+ shints.flags |= USPosition;
+
+ if(is_wmaker_)
+ {
+ wmhints.initial_state = WithdrawnState;
+ wmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
+ wmhints.icon_window = window_icon_;
+
+ wmhints.icon_x = shints.x;
+ wmhints.icon_y = shints.y;
+ wmhints.window_group = window_main_;
+ }
+ else
+ {
+ wmhints.initial_state = NormalState;
+ wmhints.flags = WindowGroupHint | StateHint;
+ }
+
+ classHint.res_name=NAME;
+ classHint.res_class=CLASS;
+
+ XSetClassHint(display_default_, window_main_, &classHint);
+ XSetClassHint(display_default_, window_icon_, &classHint);
+
+
+ if (XStringListToTextProperty(&wname, 1, &name) == 0)
+ {
+ std::cerr << wname << ": can't allocate window name" << std::endl;
+ exit(1);
+ }
+
+ XSetWMName(display_default_, window_main_, &name);
+ XSetWMHints(display_default_, window_main_, &wmhints);
+ XSetCommand(display_default_, window_main_, argv, argc);
+ XSetWMProtocols(display_default_, window_main_, &deleteWin, 1); // Close
+}
+
+
+//--------------------------------------------------------------------
+// Initialize main colors and shaded color-array for bars
+void XHandler::initColors()
+{
+ colors_[0] = mixColor(ledcolor_name_, 0, backcolor_name_, 100);
+ colors_[1] = mixColor(ledcolor_name_, 100, backcolor_name_, 0);
+ colors_[2] = mixColor(ledcolor_name_, 60, backcolor_name_, 40);
+ colors_[3] = mixColor(ledcolor_name_, 25, backcolor_name_, 75);
+
+ for(int count=0; count<25; count++)
+ {
+ shade_colors_[count] = mixColor(ledcolor_high_name_, count*2, ledcolor_name_, 100-count*4);
+ }
+}
+
+
+//--------------------------------------------------------------------
+void XHandler::initMask()
+{
+ XSetClipMask(display_default_, graphics_context_, pixmap_mask);
+ XCopyArea( display_default_, pixmap_main, pixmap_disp, graphics_context_, 0, 0, 64, 64, 0, 0);
+ XSetClipMask(display_default_, graphics_context_, None);
+ XStoreName( display_default_, window_main_, NAME);
+ XSetIconName(display_default_, window_main_, NAME);
+
+ if(is_wmaker_ || is_ushape_ || is_astep_)
+ {
+ XShapeCombineMask(display_default_, window_icon_, ShapeBounding, window_size_/2-32, window_size_/2-32, pixmap_mask, ShapeSet);
+ XShapeCombineMask(display_default_, window_main_, ShapeBounding, window_size_/2-32, window_size_/2-32, pixmap_mask, ShapeSet);
+ }
+ else
+ {
+ XCopyArea(display_default_, pixmap_tile, pixmap_disp, graphics_context_, 0, 0, 64, 64, 0, 0);
+ }
+
+ XSelectInput(display_default_, window_main_, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
+ XSelectInput(display_default_, window_icon_, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
+ XMapWindow(display_default_, window_main_);
+}
+
diff --git a/xhandler.h b/xhandler.h
new file mode 100644
index 0000000..68ecbf8
--- /dev/null
+++ b/xhandler.h
@@ -0,0 +1,153 @@
+// wmmixer - A mixer designed for WindowMaker
+//
+// Release 1.5
+// Copyright (C) 1998 Sam Hawker <shawkie at geocities.com>
+// Copyright (C) 2002 Gordon Fraser <gordon at debian.org>
+// This software comes with ABSOLUTELY NO WARRANTY
+// This software is free software, and you are welcome to redistribute it
+// under certain conditions
+// See the COPYING file for details.
+
+
+#ifndef __xhandler_h__
+#define __xhandler_h__
+
+//--------------------------------------------------------------------
+
+// X-Windows includes - standard
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xproto.h>
+#include <X11/xpm.h>
+#include <X11/extensions/shape.h>
+
+#include <iostream>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "common.h"
+
+// Xpm images - standard
+#include "XPM/wmmixer.xpm"
+#include "XPM/tile.xpm"
+
+// Xpm images - custom
+#include "XPM/icons.xpm"
+#include "XPM/norec.xpm"
+
+//--------------------------------------------------------------------
+#define BTN_LEFT_X 5
+#define BTN_LEFT_Y 34
+
+#define BTN_RIGHT_X 17
+#define BTN_RIGHT_Y 34
+
+#define BTN_MUTE_X 17
+#define BTN_MUTE_Y 47
+
+#define BTN_REC_X 5
+#define BTN_REC_Y 47
+
+#define BTN_WIDTH 12
+#define BTN_HEIGHT 11
+
+#define BTNNEXT 1
+#define BTNPREV 2
+#define BTNREC 4
+#define BTNMUTE 8
+
+
+//--------------------------------------------------------------------
+class XHandler
+{
+ protected:
+ int button_state_;
+ int window_size_;
+
+ bool is_wmaker_;
+ bool is_ushape_;
+ bool is_astep_;
+
+ unsigned *icon_list_;
+
+ Display *display_default_;
+ Window window_icon_;
+ Window window_main_;
+ Window window_root_;
+
+ GC graphics_context_;
+ unsigned long colors_[4];
+ unsigned long shade_colors_[25];
+
+ char display_name_[256];
+ char position_name_[256];
+ char ledcolor_name_[256];
+ char ledcolor_high_name_[256];
+ char backcolor_name_[256];
+
+ Pixel back_pix;
+ Pixel fore_pix;
+
+ // Pixmaps - standard
+ Pixmap pixmap_main;
+ Pixmap pixmap_tile;
+ Pixmap pixmap_disp;
+ Pixmap pixmap_mask;
+
+ // Pixmaps - custom
+ Pixmap pixmap_icon;
+ Pixmap pixmap_nrec;
+
+ // X-Windows basics - standard
+ Atom _XA_GNUSTEP_WM_FUNC;
+ Atom deleteWin;
+
+
+ unsigned long getColor(char*);
+ unsigned long mixColor(char*, int, char*, int);
+ void drawButton(int, int, int, int, bool);
+ void initPixmaps(int);
+ void initWindow(int, char**);
+ void initGraphicsContext();
+ void initMask();
+ void initColors();
+ void initIcons(int);
+
+ int flush_expose(Window);
+
+ public:
+ XHandler();
+ virtual ~XHandler();
+ void init(int, char**, int);
+
+ void repaint();
+ void update(unsigned);
+ void drawLeft(unsigned);
+ void drawRight(unsigned);
+ void drawBtns(int, bool);
+ void drawMono(unsigned);
+
+ bool isLeftButton(int, int);
+ bool isRightButton(int, int);
+ bool isMuteButton(int, int);
+ bool isRecButton(int, int);
+ bool isVolumeBar(int, int);
+
+ Display* getDisplay() {return display_default_;}
+ int getButtonState();
+ void setButtonState(int);
+ void setDisplay(char* arg);
+ void setPosition(char* arg);
+ void setLedColor(char* arg);
+ void setLedHighColor(char* arg);
+ void setBackColor(char* arg);
+ void setUnshaped();
+ void setWindowMaker();
+ void setAfterStep();
+ int getWindowSize();
+ Atom getDeleteWin();
+
+};
+
+#endif //__xhandler_h__
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmmixer.git
More information about the Pkg-wmaker-commits
mailing list