+2009-11-20 Hugo Villeneuve <hugo@hugovil.com>
+ * Indentation as per Linux Kernel Coding Style
+ * Added GPL header to all source files
+ * Added seconds hand as runtime option
+ * Added small circle at center of clock
+
2006-08-22 Hugo Villeneuve <hugo@hugovil.com>
* Removed unnecessary calls to gdk-pixbuf functions and dropped
any gdk-pixbuf dependencies.
+2009-11-20: hvclock-1.0.0 has been released.
+ Cleanup of code and added seconds hand as runtime option.
+
2006-08-22: hvclock-0.2.0 has been released.
Removed gdk-pixbuf stuff.
" {&&8888888888888888888888888888888888888888888888888888888&& {&&8888888888888888888888888888888888888888888888888888888&& .@&#$@$$$.#.#&@@&+.=*..#.$*.@&........................ ................. ................. ",
" {&888888888888888888888888888888888888888888888888888888888& {&888888888888888888888888888888888888888888888888888888888& .@&.&$@$$.$&$&@@&..$$....$$.@&........................ ....+=*&&&*=+.... .....@$&&&*0..... ",
" {&888888888888888888888888888888888888888888888888888888888& {&888888888888888888888888888888888888888888888888888888888& .@&.$%.$$@&++&@@&..0%++=+$$.@&........................ ...0&&&&&&&&&@... ...+*&&&&&&&%+... ",
-" ]&88888f&&f888888888888888888888888888888888888888&&&f88888& ]&88888f&&f888888888888888888888888888888888888888&&&f88888& .@&.0*.$$+*&**0@&...=&&=.$$.@&........................ ..0&&&&&&&&&&&@.. ...%&&&&&&&&&%+.. ",
-" {&8aba8&88&888888888888888888888888888888888888888888&8aba8& {&8aba8&88&888888888888888888888888888888888888888888&8aba8& ...................................................... .+&&&&&&&&&&&&&+. ..0&&&&&&&&&&&*.. ",
-" ^&8b&b8&88&8888888888888888888888888888888888888888&&&8b&b8& ^&8b&b8&88&8888888888888888888888888888888888888888&&&8b&b8& ...................................................... .=&&&&$+.+$&&&&0. ..%&&&&@.+*&&&&+. ",
-" ]&8aba8f&&&888888888888888888888888888888888888888888&8aba8& ]&8aba8f&&&888888888888888888888888888888888888888888&8aba8& ...................................................... .*&&&*.....%&&&$. .+&&&&0...+&&&&@. ",
-" ^&88888888&888888888888888888888888888888888888888&88&88888& ^&88888888&888888888888888888888888888888888888888&88&88888& ...+@+............+@.##............................... .&&&&0.....$&&&$. .+0$$&.....&&&&@. ",
+" ]&88888f&&f888888888888888888888888888888888888888&&&f88888& ]&88888f&&f88888888888888888ab&ba88888888888888888&&&f88888& .@&.0*.$$+*&**0@&...=&&=.$$.@&........................ ..0&&&&&&&&&&&@.. ...%&&&&&&&&&%+.. ",
+" {&8aba8&88&888888888888888888888888888888888888888888&8aba8& {&8aba8&88&88888888888888888b&&&b88888888888888888888&8aba8& ...................................................... .+&&&&&&&&&&&&&+. ..0&&&&&&&&&&&*.. ",
+" ^&8b&b8&88&8888888888888888888888888888888888888888&&&8b&b8& ^&8b&b8&88&88888888888888888&&&&&888888888888888888&&&8b&b8& ...................................................... .=&&&&$+.+$&&&&0. ..%&&&&@.+*&&&&+. ",
+" ]&8aba8f&&&888888888888888888888888888888888888888888&8aba8& ]&8aba8f&&&88888888888888888b&&&b88888888888888888888&8aba8& ...................................................... .*&&&*.....%&&&$. .+&&&&0...+&&&&@. ",
+" ^&88888888&888888888888888888888888888888888888888&88&88888& ^&88888888&88888888888888888ab&ba88888888888888888&88&88888& ...+@+............+@.##............................... .&&&&0.....$&&&$. .+0$$&.....&&&&@. ",
" /&88888c&&f888888888888888888888888888888888888888f&&f88888& /&88888c&&f888888888888888888888888888888888888888f&&f88888& ...*&$............#$.$$............................... ...+@+.....$&&&$. ..........+&&&&+. ",
" /&888888888888888888888888888888888888888888888888888888888& /&888888888888888888888888888888888888888888888888888888888& ..+&$&+.+@+@+.+@#@+@.$$............................... ...........&&&&@. ..........$&&&*.. ",
" /&&8888888888888888888888888888888888888888888888888888888&& /&&8888888888888888888888888888888888888888888888888888888&& ..0&.&0.@&**&+@&*0@&.$$............................... ..........0&&&&.. .......#$&&&&%+.. ",
#define NUMBERS_DELTA_X 20
#define NUMBERS_DELTA_Y 27
-static const int number_widths[]={
- 18, /* 0 */
- 12, /* 1 */
- 17, /* 2 */
- 17, /* 3 */
- 19, /* 4 */
- 18, /* 5 */
- 18, /* 6 */
- 17, /* 7 */
- 18, /* 8 */
- 18 /* 9 */
+static const int number_widths[] = {
+ 18, /* 0 */
+ 12, /* 1 */
+ 17, /* 2 */
+ 17, /* 3 */
+ 19, /* 4 */
+ 18, /* 5 */
+ 18, /* 6 */
+ 17, /* 7 */
+ 18, /* 8 */
+ 18 /* 9 */
};
-static const int months_widths[]={
- 39, /* January */
- 43, /* February */
- 29, /* March */
- 22, /* April */
- 20, /* May */
- 23, /* June */
- 20, /* July */
- 34, /* August */
- 52, /* September */
- 39, /* October */
- 49, /* November */
- 49 /* December */
+static const int months_widths[] = {
+ 39, /* January */
+ 43, /* February */
+ 29, /* March */
+ 22, /* April */
+ 20, /* May */
+ 23, /* June */
+ 20, /* July */
+ 34, /* August */
+ 52, /* September */
+ 39, /* October */
+ 49, /* November */
+ 49 /* December */
};
-static const int days_widths[]={
- 36, /* Sunday */
- 38, /* Monday */
- 41, /* Tueday */
- 56, /* Wednesday */
- 45, /* Thursday */
- 30, /* Friday */
- 43 /* Saturday */
+static const int days_widths[] = {
+ 36, /* Sunday */
+ 38, /* Monday */
+ 41, /* Tueday */
+ 56, /* Wednesday */
+ 45, /* Thursday */
+ 30, /* Friday */
+ 43 /* Saturday */
};
-static int
-DisplayDigit(int digit, int dest_x, int dest_y)
+static int DisplayDigit(int digit, int dest_x, int dest_y)
{
- int src_x, src_y;
-
- if ((digit % 2) == 0)
- src_x = NUMBERS_SRC_X; /* First column */
- else
- src_x = NUMBERS_SRC_X + NUMBERS_DELTA_X; /* Second column */
-
- src_y = NUMBERS_SRC_Y + ((digit / 2) * NUMBERS_DELTA_Y);
-
- copyXPMArea(src_x, src_y, number_widths[digit], NUMBERS_DELTA_Y - 1,
- dest_x, dest_y);
-
- return (dest_x + number_widths[digit] + 1);
+ int src_x, src_y;
+
+ if ((digit % 2) == 0)
+ src_x = NUMBERS_SRC_X; /* First column */
+ else
+ src_x = NUMBERS_SRC_X + NUMBERS_DELTA_X; /* Second column */
+
+ src_y = NUMBERS_SRC_Y + ((digit / 2) * NUMBERS_DELTA_Y);
+
+ copyXPMArea(src_x, src_y, number_widths[digit],
+ NUMBERS_DELTA_Y - 1, dest_x, dest_y);
+
+ return dest_x + number_widths[digit] + 1;
}
-static int
-GetNumberWidth( int number )
+static int GetNumberWidth(int number)
{
- int first,second;
- int width;
-
- first = number / 10;
- second = number % 10;
-
- if( first == 0 )
- width = number_widths[second];
- else
- width = number_widths[first] + number_widths[second];
-
- return width;
+ int first, second;
+ int width;
+
+ first = number / 10;
+ second = number % 10;
+
+ if (first == 0)
+ width = number_widths[second];
+ else
+ width = number_widths[first] + number_widths[second];
+
+ return width;
}
-void
-UpdateCalendar( void )
+void UpdateCalendar(void)
{
- struct tm *time_struct;
- time_t curtime;
- int x,y;
- int day_of_month;
- int day_of_week;
- int month;
-
- curtime = time(CurrentTime);
- time_struct = localtime(&curtime);
- day_of_month = time_struct->tm_mday;
- day_of_week = time_struct->tm_wday;
- month = time_struct->tm_mon;
-
- /* Blanking the calendar area. */
- copyXPMArea( CALENDAR_BACKGROUND_SRC_X, CALENDAR_BACKGROUND_SRC_Y, 64, 64,
- 0, 0 );
-
- /* Displaying weekday. */
- x = ( 64 - days_widths[day_of_week] ) / 2;
- y = 6;
- copyXPMArea( WEEKDAYS_BASE_X,
- WEEKDAYS_BASE_Y + WEEKDAYS_DELTA_Y * day_of_week,
- days_widths[day_of_week], WEEKDAYS_HEIGHT, x, y );
-
- /* Displaying month. */
- x = ( 64 - months_widths[month] ) / 2;
- y += WEEKDAYS_DELTA_Y + 1;
- copyXPMArea( MONTHS_BASE_X, MONTHS_BASE_Y + MONTHS_DELTA_Y * month,
- months_widths[month], MONTHS_HEIGHT, x, y );
-
- /* x is the position of the first digit. */
- x = ( 64 - GetNumberWidth( day_of_month ) ) / 2;
- y += MONTHS_DELTA_Y + 2;
-
- if( ( day_of_month / 10 ) != 0 )
- x = DisplayDigit( day_of_month / 10, x, y );
-
- (void) DisplayDigit( day_of_month % 10, x, y );
-
- RedrawWindow();
+ struct tm *time_struct;
+ time_t curtime;
+ int x, y;
+ int day_of_month;
+ int day_of_week;
+ int month;
+
+ curtime = time(CurrentTime);
+ time_struct = localtime(&curtime);
+ day_of_month = time_struct->tm_mday;
+ day_of_week = time_struct->tm_wday;
+ month = time_struct->tm_mon;
+
+ /* Blanking the calendar area. */
+ copyXPMArea(CALENDAR_BACKGROUND_SRC_X, CALENDAR_BACKGROUND_SRC_Y,
+ 64, 64, 0, 0);
+
+ /* Displaying weekday. */
+ x = (64 - days_widths[day_of_week]) / 2;
+ y = 6;
+ copyXPMArea(WEEKDAYS_BASE_X,
+ WEEKDAYS_BASE_Y + WEEKDAYS_DELTA_Y * day_of_week,
+ days_widths[day_of_week], WEEKDAYS_HEIGHT, x, y);
+
+ /* Displaying month. */
+ x = (64 - months_widths[month]) / 2;
+ y += WEEKDAYS_DELTA_Y + 1;
+ copyXPMArea(MONTHS_BASE_X, MONTHS_BASE_Y + MONTHS_DELTA_Y * month,
+ months_widths[month], MONTHS_HEIGHT, x, y);
+
+ /* x is the position of the first digit. */
+ x = (64 - GetNumberWidth(day_of_month)) / 2;
+ y += MONTHS_DELTA_Y + 2;
+
+ if ((day_of_month / 10) != 0)
+ x = DisplayDigit(day_of_month / 10, x, y);
+
+ (void) DisplayDigit(day_of_month % 10, x, y);
+
+ RedrawWindow();
}
#include "dockapp.h"
#include "xevents.h"
#include "options.h"
+#include "hvclock.h"
#include "clock.h"
-
#define SIZE 64
-#define HAND_WIDTH 2
-#define HOUR_HAND_LENGTH 16
-#define MINUTE_HAND_LENGTH 25
+#define HAND_WIDTH_HOURS_MINUTES 2
+#define HAND_WIDTH_SECONDS 1
+#define HAND_LENGTH_HOURS 16
+#define HAND_LENGTH_MINUTES 25
+#define HAND_LENGTH_SECONDS HAND_LENGTH_MINUTES
+#define HAND_LENGTH_SECONDS_NEG 7
+
+static void draw_hand(double angle, int hand_length, int negative_hand_length,
+ int hand_width)
+{
+ int start_x, start_y, end_x, end_y;
+
+ XSetLineAttributes(dockapp.display, dockapp.NormalGC, hand_width,
+ LineSolid, CapRound, JoinRound);
+ start_x = SIZE / 2; /* Center of clock */
+ start_y = start_x;
+
+ end_x = start_x + (int) ((double) hand_length * sin(angle));
+ end_y = start_y - (int) ((double) hand_length * cos(angle));
+
+ if (negative_hand_length) {
+ start_x -= (int) ((double) negative_hand_length * sin(angle));
+ start_y += (int) ((double) negative_hand_length * cos(angle));
+ }
+
+ XDrawLine(dockapp.display, dockapp.xpm_icon.image,
+ dockapp.NormalGC, start_x, start_y, end_x, end_y);
+}
-void
-UpdateClock( void )
+void UpdateClock(void)
{
- static int old_hour = 0;
- static int old_minute = 0;
- static int old_second = 0;
- struct tm *time_struct;
- time_t curtime;
- double angle;
- int x, y;
-
- curtime = time(NULL);
- time_struct = localtime(&curtime);
-
- /* We should not update each second if the seconds hand is not displayed. */
- if( ( time_struct->tm_hour == old_hour ) &&
- ( time_struct->tm_min == old_minute ) &&
- ( time_struct->tm_sec == old_second ) )
- return;
-
- /* Blanking the clock area. */
- copyXPMArea( 64, 0, SIZE, SIZE, 0, 0 );
-
- XSetLineAttributes( dockapp.display, dockapp.NormalGC, HAND_WIDTH, LineSolid,
- CapRound, JoinRound );
-
- angle = (M_PI / 6.0) * (double) time_struct->tm_hour +
- (M_PI / 360.0) * (double) time_struct->tm_min;
- x = (SIZE / 2) + (int) ((double) HOUR_HAND_LENGTH * sin(angle));
- y = (SIZE / 2) - (int) ((double) HOUR_HAND_LENGTH * cos(angle));
- XDrawLine( dockapp.display, dockapp.xpm_icon.image, dockapp.NormalGC, SIZE / 2, SIZE / 2,
- x, y );
-
- angle = (M_PI / 30.0) * (double) time_struct->tm_min;
- x = (SIZE / 2) + (int) ((double) MINUTE_HAND_LENGTH * sin(angle));
- y = (SIZE / 2) - (int) ((double) MINUTE_HAND_LENGTH * cos(angle));
- XDrawLine( dockapp.display, dockapp.xpm_icon.image, dockapp.NormalGC, SIZE / 2, SIZE / 2,
- x, y );
-
- /* if (option.show_seconds) {
- angle = (M_PI / 30.0) * (double) s;
- sx = (SIZE / 2) + (int) ((double) option.second_hand_length * sin(angle));
- sy = (SIZE / 2) - (int) ((double) option.second_hand_length * cos(angle));
-
- XSetForeground(display, gc, second_hand_pixel);
- XSetLineAttributes(display, gc, option.second_hand_width, LineSolid,
- CapRound, JoinRound);
- XDrawLine(display, all_pm, gc, SIZE / 2, SIZE / 2, sx, sy);
- XSetForeground(display, gc, hand_pixel);
- }*/
-
- RedrawWindow();
-
- old_hour = time_struct->tm_hour;
- old_minute = time_struct->tm_min;
- old_second = time_struct->tm_sec;
+ static int old_hour;
+ static int old_minute;
+ static int old_second;
+ struct tm *time_struct;
+ time_t curtime;
+ double angle;
+
+ curtime = time(NULL);
+ time_struct = localtime(&curtime);
+
+ /* Do not update each second if the seconds hand is not displayed. */
+ if ((time_struct->tm_hour == old_hour) &&
+ (time_struct->tm_min == old_minute) &&
+ (time_struct->tm_sec == old_second))
+ return;
+
+ /* Blanking the clock area. */
+ copyXPMArea(64, 0, SIZE, SIZE, 0, 0);
+
+ /* Draw hours hand */
+ angle = (M_PI / 6.0) * (double) time_struct->tm_hour +
+ (M_PI / 360.0) * (double) time_struct->tm_min;
+ draw_hand(angle, HAND_LENGTH_HOURS, 0, HAND_WIDTH_HOURS_MINUTES);
+
+ /* Draw minutes hand, 60 minutes = 2PI */
+ angle = (M_PI / 30.0) * (double) time_struct->tm_min;
+ draw_hand(angle, HAND_LENGTH_MINUTES, 0, HAND_WIDTH_HOURS_MINUTES);
+
+ if (hvclock_infos.show_seconds) {
+ /* Draw seconds hand, 60 seconds = 2PI */
+ angle = (M_PI / 30.0) * (double) time_struct->tm_sec;
+ draw_hand(angle, HAND_LENGTH_SECONDS, HAND_LENGTH_SECONDS_NEG,
+ HAND_WIDTH_SECONDS);
+ }
+
+ RedrawWindow();
+
+ old_hour = time_struct->tm_hour;
+ old_minute = time_struct->tm_min;
+ old_second = time_struct->tm_sec;
}
# define EXIT_FAILURE 1
#endif
-typedef int bool;
#ifndef FALSE
# define FALSE 0
# define TRUE 1
#include "common.h"
#include "dockapp.h"
-
#define XLIB_FAILURE 0
#define XLIB_SUCCESS 1
/* Width and height in pixels of Window Maker icons. */
#define ICON_SIZE 64
-
-static void
-CreateIconFromXpmData( char *pixmap_data[] )
+static void CreateIconFromXpmData(char *pixmap_data[])
{
- int status;
-
- dockapp.xpm_icon.attributes.valuemask |=
- ( XpmReturnPixels | XpmReturnExtensions );
-
- /* Using the XPM library to read XPM data from the array in the included XPM
- file. The 'shapemask' Pixmap variable is set to an additional 1-bit deep
- pixmap that can then be used as a shape mask for the XShapeCombineMask()
- function. */
- status = XpmCreatePixmapFromData( dockapp.display, dockapp.root_win,
- pixmap_data, &dockapp.xpm_icon.image,
- &dockapp.xpm_icon.shapemask,
- &dockapp.xpm_icon.attributes );
- if( status != XpmSuccess ) {
- fprintf( stderr, "%s: XpmCreatePixmapFromData() failed\n", PACKAGE );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-}
+ int status;
+ dockapp.xpm_icon.attributes.valuemask |=
+ (XpmReturnPixels | XpmReturnExtensions);
-static Pixel
-GetColor( char *name )
-{
- int status;
- bool res;
- XColor color;
- XWindowAttributes attributes;
-
- status = XGetWindowAttributes( dockapp.display, dockapp.root_win,
- &attributes );
- if( status == XLIB_FAILURE ) {
- fprintf( stderr, "%s: XGetWindowAttributes() failed\n", PACKAGE );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- color.pixel = 0;
- res = (bool) XParseColor( dockapp.display, attributes.colormap, name,
- &color );
- if( res == FALSE ) {
- fprintf( stderr, "%s: Can't parse %s.\n", PACKAGE, name );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- res = (bool) XAllocColor( dockapp.display, attributes.colormap, &color );
- if( res == FALSE ) {
- fprintf( stderr, "%s: Can't allocate %s.\n", PACKAGE, name );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- return color.pixel;
+ /*
+ * Using the XPM library to read XPM data from the array in the included
+ * XPM file. The 'shapemask' Pixmap variable is set to an additional
+ * 1-bit deep pixmap that can then be used as a shape mask for the
+ * XShapeCombineMask() function.
+ */
+ status = XpmCreatePixmapFromData(dockapp.display, dockapp.root_win,
+ pixmap_data,
+ &dockapp.xpm_icon.image,
+ &dockapp.xpm_icon.shapemask,
+ &dockapp.xpm_icon.attributes);
+ if (status != XpmSuccess) {
+ fprintf(stderr, "%s: XpmCreatePixmapFromData() failed\n",
+ PACKAGE);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
}
-
-static void
-flush_expose( Window win )
+static Pixel GetColor(char *name)
{
- XEvent dummy;
- bool res = TRUE;
+ int status;
+ int res;
+ XColor color;
+ XWindowAttributes attributes;
- while( res != FALSE ) {
- res = (bool) XCheckTypedWindowEvent( dockapp.display, win, Expose, &dummy );
- }
-}
+ status = XGetWindowAttributes(dockapp.display, dockapp.root_win,
+ &attributes);
+ if (status == XLIB_FAILURE) {
+ fprintf(stderr, "%s: XGetWindowAttributes() failed\n",
+ PACKAGE);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
+ color.pixel = 0;
+ res =
+ (int) XParseColor(dockapp.display, attributes.colormap, name,
+ &color);
+ if (res == FALSE) {
+ fprintf(stderr, "%s: Can't parse %s.\n", PACKAGE, name);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
-void
-RedrawWindow( void )
+ res =
+ (int) XAllocColor(dockapp.display, attributes.colormap,
+ &color);
+ if (res == FALSE) {
+ fprintf(stderr, "%s: Can't allocate %s.\n", PACKAGE, name);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
+
+ return color.pixel;
+}
+
+static void flush_expose(Window win)
{
- flush_expose( dockapp.iconwin );
-
- (void) XCopyArea( dockapp.display, dockapp.xpm_icon.image, dockapp.iconwin,
- dockapp.NormalGC, 0, 0, dockapp.xpm_icon.attributes.width,
- dockapp.xpm_icon.attributes.height, 0, 0 );
-
- flush_expose( dockapp.win );
-
- (void) XCopyArea( dockapp.display, dockapp.xpm_icon.image, dockapp.win,
- dockapp.NormalGC, 0, 0, dockapp.xpm_icon.attributes.width,
- dockapp.xpm_icon.attributes.height, 0, 0 );
+ XEvent dummy;
+ int res = TRUE;
+
+ while (res != FALSE) {
+ res =
+ (int) XCheckTypedWindowEvent(dockapp.display, win,
+ Expose, &dummy);
+ }
}
+void RedrawWindow(void)
+{
+ flush_expose(dockapp.iconwin);
+
+ (void) XCopyArea(dockapp.display, dockapp.xpm_icon.image,
+ dockapp.iconwin, dockapp.NormalGC, 0, 0,
+ dockapp.xpm_icon.attributes.width,
+ dockapp.xpm_icon.attributes.height, 0, 0);
+
+ flush_expose(dockapp.win);
+
+ (void) XCopyArea(dockapp.display, dockapp.xpm_icon.image,
+ dockapp.win, dockapp.NormalGC, 0, 0,
+ dockapp.xpm_icon.attributes.width,
+ dockapp.xpm_icon.attributes.height, 0, 0);
+}
void
-copyXPMArea( int x, int y, unsigned int sx, unsigned int sy, int dx, int dy )
+copyXPMArea(int x, int y, unsigned int sx, unsigned int sy, int dx, int dy)
{
- (void) XCopyArea( dockapp.display, dockapp.xpm_icon.image,
- dockapp.xpm_icon.image, dockapp.NormalGC, x, y, sx, sy,
- dx, dy );
+ (void) XCopyArea(dockapp.display, dockapp.xpm_icon.image,
+ dockapp.xpm_icon.image, dockapp.NormalGC, x, y,
+ sx, sy, dx, dy);
}
-
/*******************************************************************************
* New window creation and initialization for a Dockable Application
******************************************************************************/
void
-InitDockAppWindow( int argc, char *argv[], char *pixmap_data[],
- char *display_arg, char *geometry_arg )
+InitDockAppWindow(int argc, char *argv[], char *pixmap_data[],
+ char *display_arg, char *geometry_arg)
{
- XGCValues gcv;
- XSizeHints size_hints;
- XWMHints wm_hints;
- int status;
- int gravity = 0; /* Used to store the gravity value returned by XWMGeometry,
- but not used. */
- char *app_name = "hvclock";
-
- /* Opening a connection to the X server. */
- dockapp.display = XOpenDisplay( display_arg );
- if( dockapp.display == NULL ) {
- fprintf( stderr, "%s: Can't open display: %s\n", PACKAGE,
- XDisplayName( display_arg ) );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- dockapp.screen = DefaultScreen( dockapp.display );
- dockapp.root_win = RootWindow( dockapp.display, dockapp.screen );
- dockapp.d_depth = DefaultDepth( dockapp.display, dockapp.screen );
-
- /* Create a window to hold the stuff */
- size_hints.flags = USSize | USPosition;
- size_hints.x = 0;
- size_hints.y = 0;
-
- /* Constructing window's geometry information. */
- /* XWMGeometry() returns an 'int', but Xlib documentation doesn't explain
- it's meaning. */
- XWMGeometry( dockapp.display, dockapp.screen, geometry_arg, NULL, BWIDTH,
- &size_hints, &size_hints.x, &size_hints.y, &size_hints.width,
- &size_hints.height, &gravity );
-
- size_hints.width = ICON_SIZE;
- size_hints.height = ICON_SIZE;
- dockapp.back_pix = GetColor("white");
- dockapp.fore_pix = GetColor("black");
-
- dockapp.win = XCreateSimpleWindow( dockapp.display, dockapp.root_win,
- size_hints.x, size_hints.y,
- (unsigned int) size_hints.width,
- (unsigned int) size_hints.height,
- BWIDTH, dockapp.fore_pix,
- dockapp.back_pix );
-
- dockapp.iconwin = XCreateSimpleWindow( dockapp.display, dockapp.win,
- size_hints.x, size_hints.y,
- (unsigned int) size_hints.width,
- (unsigned int) size_hints.height,
- BWIDTH, dockapp.fore_pix,
- dockapp.back_pix );
-
- /* Configuring Client to Window Manager Communications. */
-
- /* WM_NORMAL_HINTS property: size hints for a window in it's normal state. */
- /* Replaces the size hints for the WM_NORMAL_HINTS property on the specified
- window. */
- XSetWMNormalHints( dockapp.display, dockapp.win, &size_hints );
-
- /* Setting the WM_CLASS property. */
- {
- XClassHint wm_class;
-
- /* The res_name member contains the application name.
- The res_class member contains the application class. */
- /* The name set in this property may differ from the name set as WM_NAME.
- That is, WM_NAME specifies what should be displayed in the title bar and,
- therefore, can contain temporal information (for example, the name of a
- file currently in an editor's buffer). On the other hand, the name
- specified as part of WM_CLASS is the formal name of the application that
- should be used when retrieving the application's resources from the
- resource database. */
- wm_class.res_name = app_name;
- wm_class.res_class = app_name;
- (void) XSetClassHint( dockapp.display, dockapp.win, &wm_class );
- }
-
- /* Setting the WM_NAME property.
- This specifies what should be displayed in the title bar (usually the
- application name). */
- {
- XTextProperty text_prop;
-
- const int string_count = 1;
-
- status = XStringListToTextProperty( &app_name, string_count, &text_prop );
- if( status == 0 ) {
- fprintf( stderr, "%s: XStringListToTextProperty() failed\n", PACKAGE );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- XSetWMName( dockapp.display, dockapp.win, &text_prop );
-
- /* Freing the storage for the value field. */
- (void) XFree( text_prop.value );
- }
-
- /* WM_HINTS --> Additional hints set by the client for use by the Window
- Manager. */
- /* XWMHints wm_hints; */
-
- /* WithdrawnState, NormalState or IconicState. Must be set to WithdrawnState
- for DockApp. */
- wm_hints.flags = StateHint | IconWindowHint | IconPositionHint |
- WindowGroupHint;
- wm_hints.initial_state = WithdrawnState; /* Withdrawn, Normal */
- wm_hints.icon_window = dockapp.iconwin;
- wm_hints.icon_x = size_hints.x;
- wm_hints.icon_y = size_hints.y;
- wm_hints.window_group = dockapp.win;
- (void) XSetWMHints( dockapp.display, dockapp.win, &wm_hints );
-
- /* Sets the WM_COMMAND property. This sets the command and arguments used to
- invoke the application. */
- (void) XSetCommand( dockapp.display, dockapp.win, argv, argc );
-
- /* ... */
- (void) XSelectInput( dockapp.display, dockapp.win,
- ButtonPressMask | ExposureMask | ButtonReleaseMask |
- PointerMotionMask | StructureNotifyMask );
-
- (void) XSelectInput( dockapp.display, dockapp.iconwin,
- ButtonPressMask | ExposureMask | ButtonReleaseMask |
- PointerMotionMask | StructureNotifyMask );
-
- /* Create GC for drawing */
- gcv.foreground = dockapp.fore_pix;
- gcv.background = dockapp.back_pix;
- gcv.graphics_exposures = 0;
- dockapp.NormalGC = XCreateGC( dockapp.display, dockapp.root_win,
- GCForeground | GCBackground |
- GCGraphicsExposures, &gcv );
-
- /* Convert XPM data to XImage */
- CreateIconFromXpmData( pixmap_data );
-
- XShapeCombineMask( dockapp.display, dockapp.win, ShapeBounding, 0, 0,
- dockapp.xpm_icon.shapemask, ShapeSet );
-
- XShapeCombineMask( dockapp.display, dockapp.iconwin, ShapeBounding, 0, 0,
- dockapp.xpm_icon.shapemask, ShapeSet );
-
- /* Making the new window visible. */
- (void) XMapWindow( dockapp.display, dockapp.win );
+ XGCValues gcv;
+ XSizeHints size_hints;
+ XWMHints wm_hints;
+ int status;
+ int gravity = 0; /* Used to store the gravity value returned by
+ * XWMGeometry, but not used. */
+ char *app_name = "hvclock";
+
+ /* Opening a connection to the X server. */
+ dockapp.display = XOpenDisplay(display_arg);
+ if (dockapp.display == NULL) {
+ fprintf(stderr, "%s: Can't open display: %s\n", PACKAGE,
+ XDisplayName(display_arg));
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
+
+ dockapp.screen = DefaultScreen(dockapp.display);
+ dockapp.root_win = RootWindow(dockapp.display, dockapp.screen);
+ dockapp.d_depth = DefaultDepth(dockapp.display, dockapp.screen);
+
+ /* Create a window to hold the stuff */
+ size_hints.flags = USSize | USPosition;
+ size_hints.x = 0;
+ size_hints.y = 0;
+
+ /*
+ * Constructing window's geometry information.
+ * XWMGeometry() returns an 'int', but Xlib documentation doesn't
+ * explain it's meaning.
+ */
+ XWMGeometry(dockapp.display, dockapp.screen, geometry_arg, NULL,
+ BWIDTH, &size_hints, &size_hints.x, &size_hints.y,
+ &size_hints.width, &size_hints.height, &gravity);
+
+ size_hints.width = ICON_SIZE;
+ size_hints.height = ICON_SIZE;
+ dockapp.back_pix = GetColor("white");
+ dockapp.fore_pix = GetColor("black");
+
+ dockapp.win =
+ XCreateSimpleWindow(dockapp.display, dockapp.root_win,
+ size_hints.x, size_hints.y,
+ (unsigned int) size_hints.width,
+ (unsigned int) size_hints.height, BWIDTH,
+ dockapp.fore_pix, dockapp.back_pix);
+
+ dockapp.iconwin = XCreateSimpleWindow(dockapp.display, dockapp.win,
+ size_hints.x, size_hints.y,
+ (unsigned int) size_hints.
+ width,
+ (unsigned int) size_hints.
+ height, BWIDTH,
+ dockapp.fore_pix,
+ dockapp.back_pix);
+
+ /* Configuring Client to Window Manager Communications. */
+
+ /*
+ * WM_NORMAL_HINTS property: size hints for a window in it's normal
+ * state.
+ * Replaces the size hints for the WM_NORMAL_HINTS property on the
+ * specified window.
+ */
+ XSetWMNormalHints(dockapp.display, dockapp.win, &size_hints);
+
+ /* Setting the WM_CLASS property. */
+ {
+ XClassHint wm_class;
+
+ /*
+ * The res_name member contains the application name.
+ * The res_class member contains the application class.
+ * The name set in this property may differ from the name set as
+ * WM_NAME. That is, WM_NAME specifies what should be displayed
+ * in the title bar and, therefore, can contain temporal
+ * information (for example, the name of a file currently in an
+ * editor's buffer). On the other hand, the name specified as
+ * part of WM_CLASS is the formal name of the application that
+ * should be used when retrieving the application's resources
+ * from the resource database.
+ */
+ wm_class.res_name = app_name;
+ wm_class.res_class = app_name;
+ (void) XSetClassHint(dockapp.display, dockapp.win,
+ &wm_class);
+ }
+
+ /* Setting the WM_NAME property.
+ This specifies what should be displayed in the title bar (usually the
+ application name). */
+ {
+ XTextProperty text_prop;
+
+ const int string_count = 1;
+
+ status =
+ XStringListToTextProperty(&app_name, string_count,
+ &text_prop);
+ if (status == 0) {
+ fprintf(stderr,
+ "%s: XStringListToTextProperty() failed\n",
+ PACKAGE);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
+
+ XSetWMName(dockapp.display, dockapp.win, &text_prop);
+
+ /* Freing the storage for the value field. */
+ (void) XFree(text_prop.value);
+ }
+
+ /* WM_HINTS --> Additional hints set by the client for use by the Window
+ Manager. */
+ /* XWMHints wm_hints; */
+
+ /* WithdrawnState, NormalState or IconicState. Must be set to
+ * WithdrawnState for DockApp. */
+ wm_hints.flags = StateHint | IconWindowHint | IconPositionHint |
+ WindowGroupHint;
+ wm_hints.initial_state = WithdrawnState; /* Withdrawn, Normal */
+ wm_hints.icon_window = dockapp.iconwin;
+ wm_hints.icon_x = size_hints.x;
+ wm_hints.icon_y = size_hints.y;
+ wm_hints.window_group = dockapp.win;
+ (void) XSetWMHints(dockapp.display, dockapp.win, &wm_hints);
+
+ /* Sets the WM_COMMAND property. This sets the command and arguments
+ used to invoke the application. */
+ (void) XSetCommand(dockapp.display, dockapp.win, argv, argc);
+
+ /* ... */
+ (void) XSelectInput(dockapp.display, dockapp.win,
+ ButtonPressMask | ExposureMask |
+ ButtonReleaseMask | PointerMotionMask |
+ StructureNotifyMask);
+
+ (void) XSelectInput(dockapp.display, dockapp.iconwin,
+ ButtonPressMask | ExposureMask |
+ ButtonReleaseMask | PointerMotionMask |
+ StructureNotifyMask);
+
+ /* Create GC for drawing */
+ gcv.foreground = dockapp.fore_pix;
+ gcv.background = dockapp.back_pix;
+ gcv.graphics_exposures = 0;
+ dockapp.NormalGC = XCreateGC(dockapp.display, dockapp.root_win,
+ GCForeground | GCBackground |
+ GCGraphicsExposures, &gcv);
+
+ /* Convert XPM data to XImage */
+ CreateIconFromXpmData(pixmap_data);
+
+ XShapeCombineMask(dockapp.display, dockapp.win, ShapeBounding, 0,
+ 0, dockapp.xpm_icon.shapemask, ShapeSet);
+
+ XShapeCombineMask(dockapp.display, dockapp.iconwin, ShapeBounding,
+ 0, 0, dockapp.xpm_icon.shapemask, ShapeSet);
+
+ /* Making the new window visible. */
+ (void) XMapWindow(dockapp.display, dockapp.win);
}
#include <X11/xpm.h>
-typedef struct XpmIcon
-{
- XpmAttributes attributes;
- Pixmap shapemask;
- Pixmap image;
-} XpmIcon;
+struct xpm_icon_t {
+ XpmAttributes attributes;
+ Pixmap shapemask;
+ Pixmap image;
+};
-typedef struct dockapp_t
-{
- Display *display;
- Window root_win;
- int screen;
- int d_depth;
- Pixel back_pix;
- Pixel fore_pix;
- Window iconwin;
- Window win;
- GC NormalGC;
- XpmIcon xpm_icon;
-} dockapp_t;
+struct dockapp_t {
+ Display *display;
+ Window root_win;
+ int screen;
+ int d_depth;
+ Pixel back_pix;
+ Pixel fore_pix;
+ Window iconwin;
+ Window win;
+ GC NormalGC;
+ struct xpm_icon_t xpm_icon;
+};
void
-InitDockAppWindow( int argc, char *argv[], char *pixmap_data[],
- char *display_arg, char *geometry_arg );
+InitDockAppWindow(int argc, char *argv[], char *pixmap_data[],
+ char *display_arg, char *geometry_arg);
void
-RedrawWindow( void );
+RedrawWindow(void);
void
-copyXPMArea( int x, int y, unsigned int sx, unsigned int sy, int dx, int dy );
+copyXPMArea(int x, int y, unsigned int sx, unsigned int sy, int dx, int dy);
/* Exported variables */
#undef _SCOPE_
#define _SCOPE_ extern
#endif
-_SCOPE_ dockapp_t dockapp;
+_SCOPE_ struct dockapp_t dockapp;
#endif /* DOCKAPP_H */
#include "calendar.h"
#include "hvclock.h"
-
/* Constants */
#define CLOCK_MODE 0
#define CALENDAR_MODE 1
-
/* Thread ID */
static pthread_t timer_thread;
static int mode = CLOCK_MODE;
-
-inline void
-ErrorLocation( const char *file, int line )
+inline void ErrorLocation(const char *file, int line)
{
- fprintf( stderr, " Error in file \"%s\" at line #%d\n", file, line );
+ fprintf(stderr, " Error in file \"%s\" at line #%d\n", file,
+ line);
}
-
-void *
-xmalloc( size_t size, const char *filename, int line_number )
+void *xmalloc(size_t size, const char *filename, int line_number)
{
- void *value;
+ void *value;
- value = malloc( size );
-
- if( value == NULL ) {
- perror( PACKAGE );
- ErrorLocation( filename, line_number );
- exit( EXIT_FAILURE );
- }
+ value = malloc(size);
- return value;
-}
+ if (value == NULL) {
+ perror(PACKAGE);
+ ErrorLocation(filename, line_number);
+ exit(EXIT_FAILURE);
+ }
+ return value;
+}
-static void
-CatchTimerSignal( /*@unused@*/ int signal )
+static void CatchTimerSignal(int signal)
{
- if( hvclock_infos.debug ) {
- printf( "%s: Catching signal SIGUSR1.\n", PACKAGE );
- }
+ if (hvclock_infos.debug)
+ printf("%s: Catching signal SIGUSR1.\n", PACKAGE);
}
-
-static void
-SingleClick( void )
-{
- int status;
-
- if( hvclock_infos.debug ) {
- printf( "%s: SingleClick() Entry\n", PACKAGE );
- }
-
- /* single-click --> changing viewing mode */
- if( mode == CLOCK_MODE )
- mode = CALENDAR_MODE;
- else
- mode = CLOCK_MODE;
-
- /* Sending a signal to awake the TimerThread() thread. */
- status = pthread_kill( timer_thread, SIGUSR1 );
- if( status != EXIT_SUCCESS ) {
- fprintf( stderr, "%s: pthread_kill() error (%d)\n", PACKAGE, status );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- if( hvclock_infos.debug ) {
- printf( "%s: SingleClick() Exit\n", PACKAGE );
- }
+static void SingleClick(void)
+{
+ int status;
+
+ if (hvclock_infos.debug)
+ printf("%s: SingleClick() Entry\n", PACKAGE);
+
+ /* single-click --> changing viewing mode */
+ if (mode == CLOCK_MODE)
+ mode = CALENDAR_MODE;
+ else
+ mode = CLOCK_MODE;
+
+ /* Sending a signal to awake the TimerThread() thread. */
+ status = pthread_kill(timer_thread, SIGUSR1);
+ if (status != EXIT_SUCCESS) {
+ fprintf(stderr, "%s: pthread_kill() error (%d)\n", PACKAGE,
+ status);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
+
+ if (hvclock_infos.debug)
+ printf("%s: SingleClick() Exit\n", PACKAGE);
}
-
-static void *
-TimerThread( void *arg )
+static void *TimerThread(void *arg)
{
- unsigned int time_remaining;
- unsigned int thread_sleep_time;
-
- thread_sleep_time = 1; /* Updates done at 5 seconds interval. */
-
- /* For catching the termination signal SIGUSR1. This signal is sent by the
- main program thread when the user is issuing a single-click to switch
- modes. */
- (void) signal( SIGUSR1, CatchTimerSignal );
-
- while( TRUE ) {
- if( mode == CLOCK_MODE ) {
- UpdateClock();
- }
- else {
- UpdateCalendar();
- }
-
- /* If sleep() returns because the requested time has elapsed, the value
- returned will be 0. If sleep() returns because of premature arousal due
- to delivery of a signal, the return value will be the "unslept" amount
- (the requested time minus the time actually slept) in seconds. */
- time_remaining = sleep( thread_sleep_time );
- if( time_remaining != 0 ) {
- if( hvclock_infos.debug ) {
- printf( "%s: TimerThread() interrupted by signal\n", PACKAGE );
- }
- }
- }
-
- /* This code is never reached... */
- pthread_exit( NULL );
+ unsigned int time_remaining;
+ unsigned int thread_sleep_time;
+
+ thread_sleep_time = 1; /* Updates done at 5 seconds interval. */
+
+ /*
+ * For catching the termination signal SIGUSR1. This signal is sent by
+ * the main program thread when the user is issuing a single-click to
+ * switch modes.
+ */
+ (void) signal(SIGUSR1, CatchTimerSignal);
+
+ while (TRUE) {
+ if (mode == CLOCK_MODE)
+ UpdateClock();
+ else
+ UpdateCalendar();
+
+ /*
+ * If sleep() returns because the requested time has elapsed,
+ * the value returned will be 0. If sleep() returns because of
+ * premature arousal due to delivery of a signal, the return
+ * value will be the "unslept" amount (the requested time minus
+ * the time actually slept) in seconds.
+ */
+ time_remaining = sleep(thread_sleep_time);
+ if (time_remaining != 0) {
+ if (hvclock_infos.debug) {
+ printf("%s: TimerThread() interrupted by "
+ "signal\n",
+ PACKAGE);
+ }
+ }
+ }
+
+ /* This code is never reached... */
+ pthread_exit(NULL);
}
-
/*******************************************************************************
* Main function
******************************************************************************/
-int
-main( int argc, char *argv[] )
+int main(int argc, char *argv[])
{
- int status;
-
- /* Initialization */
- ParseCommandLineOptions( argc, argv );
-
- /* Initialize callback function pointers. */
- ProcessXlibEventsInit( SingleClick, NULL );
-
- /* Initializing and creating a DockApp window. */
- InitDockAppWindow( argc, argv, hvclock_xpm, hvclock_infos.display_arg,
- hvclock_infos.geometry_arg );
-
- /* Starting thread for periodically updating the clock. */
- status = pthread_create( &timer_thread, NULL, TimerThread, NULL );
- if( status != 0 ) {
- fprintf( stderr, "%s: Thread creation failed (%d)\n", PACKAGE, status );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- /* Main loop, processing X Events */
- ProcessXlibEvents();
-
- /* This code is never reached for now. */
- fprintf( stderr, "%s: Program exit\n", PACKAGE );
-
- exit( EXIT_SUCCESS );
+ int status;
+
+ /* Initialization */
+ ParseCommandLineOptions(argc, argv);
+
+ /* Initialize callback function pointers. */
+ ProcessXlibEventsInit(SingleClick, NULL);
+
+ /* Initializing and creating a DockApp window. */
+ InitDockAppWindow(argc, argv, hvclock_xpm,
+ hvclock_infos.display_arg,
+ hvclock_infos.geometry_arg);
+
+ /* Starting thread for periodically updating the clock. */
+ status = pthread_create(&timer_thread, NULL, TimerThread, NULL);
+ if (status != 0) {
+ fprintf(stderr, "%s: Thread creation failed (%d)\n",
+ PACKAGE, status);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Main loop, processing X Events */
+ ProcessXlibEvents();
+
+ /* This code is never reached for now. */
+ fprintf(stderr, "%s: Program exit\n", PACKAGE);
+
+ exit(EXIT_SUCCESS);
}
#ifndef HVCLOCK_H
#define HVCLOCK_H 1
-typedef struct hvclock_t
-{
- bool debug;
- char *display_arg;
- char *geometry_arg;
-} hvclock_t;
+struct hvclock_t {
+ int debug;
+ int show_seconds;
+ char *display_arg;
+ char *geometry_arg;
+};
/* Exported variables */
#undef _SCOPE_
# define _SCOPE_ extern
#endif
-_SCOPE_ hvclock_t hvclock_infos;
+_SCOPE_ struct hvclock_t hvclock_infos;
#endif /* HVCLOCK_H */
#include "hvclock.h"
#include "options.h"
-
/*******************************************************************************
* Display the help message and exit
******************************************************************************/
-static void
-DisplayUsage( void )
+static void DisplayUsage(void)
{
- printf( "Usage: %s [OPTIONS]...\n", PACKAGE );
- printf( "Dockable analog clock and calendar.\n\n" );
- printf( " -d Display debugging messages.\n" );
- printf( " -display <host:display> X display name\n" );
- printf( " -geometry +XPOS+YPOS initial window position\n" );
- printf( " -h display this help and exit\n" );
- printf( " -version display version information and exit\n");
- printf( "\n" );
+ printf("Usage: %s [OPTIONS]...\n", PACKAGE);
+ printf("Dockable analog clock and calendar.\n\n");
+ printf
+ (" -d Display debugging messages.\n");
+ printf(" -display <host:display> X display name\n");
+ printf(" -geometry +XPOS+YPOS initial window position\n");
+ printf(" -h display this help and exit\n");
+ printf(" -s display seconds hand\n");
+ printf(" -version display version information"
+ " and exit\n");
+ printf("\n");
}
-
/*******************************************************************************
* Display version information and exit
******************************************************************************/
-static void
-DisplayVersion( void )
+static void DisplayVersion(void)
{
- printf( "\n" );
- printf( " %s, version %s\n", PACKAGE, VERSION );
- printf( " Written by Hugo Villeneuve\n\n" );
+ printf("\n");
+ printf(" %s, version %s\n", PACKAGE, VERSION);
+ printf(" Written by Hugo Villeneuve\n\n");
}
-
-static void
-InvalidOption( char *message, /*@null@*/ char *string )
+static void InvalidOption(char *message, /*@null@ */ char *string)
{
- if( string == NULL )
- fprintf(stderr, "%s: %s\n", PACKAGE, message );
- else
- fprintf(stderr, "%s: %s %s\n", PACKAGE, message, string );
+ if (string == NULL)
+ fprintf(stderr, "%s: %s\n", PACKAGE, message);
+ else
+ fprintf(stderr, "%s: %s %s\n", PACKAGE, message, string);
- fprintf(stderr, "Try `%s -h' for more information.\n", PACKAGE );
+ fprintf(stderr, "Try `%s -h' for more information.\n", PACKAGE);
- exit( EXIT_FAILURE );
+ exit(EXIT_FAILURE);
}
-
/*******************************************************************************
* Initializes the different options passed as arguments on the command line.
******************************************************************************/
-void
-ParseCommandLineOptions( int argc, char *argv[] )
+void ParseCommandLineOptions(int argc, char *argv[])
{
- int i;
- char *token;
- bool display_on = FALSE;
- bool geometry_on = FALSE;
-
- /* Default values. */
- hvclock_infos.debug = FALSE;
-
- for( i = 1; i < argc; i++ ) {
- token = argv[i];
- switch( token[0] ) {
- case '-':
- /* Processing options names */
- switch( token[1] ) {
- case 'd':
- if( STREQ( "display", &token[1] ) ) {
- display_on = TRUE;
- }
- else if( strlen( &token[1] ) == 1 ) {
- hvclock_infos.debug = TRUE;
- }
- break;
- case 'g':
- if( STREQ( "geometry", &token[1] ) ) {
- geometry_on = TRUE;
- }
- break;
- case 'h':
- DisplayUsage();
- exit( EXIT_SUCCESS );
- case 'v' :
- if( STREQ( "version", &token[1] ) ) {
- DisplayVersion();
- exit( EXIT_SUCCESS );
- }
- InvalidOption( "invalid option", token );
- break;
- default:
- InvalidOption( "invalid option", token );
- break;
- } /* end switch( token[1] ) */
- break;
- default:
- /* Processing options arguments */
- if( display_on != FALSE ) {
- display_on = FALSE;
- hvclock_infos.display_arg = token;
- }
- else if( geometry_on != FALSE ) {
- geometry_on = FALSE;
- hvclock_infos.geometry_arg = token;
- }
- else {
- InvalidOption( "invalid option", token );
- }
- break;
- } /* end switch( token[0] ) */
- } /* end for */
+ int i;
+ char *token;
+ int display_on = FALSE;
+ int geometry_on = FALSE;
+
+ /* Default values. */
+ hvclock_infos.debug = FALSE;
+ hvclock_infos.show_seconds = FALSE; /* This option is fixed to FALSE */
+
+ for (i = 1; i < argc; i++) {
+ token = argv[i];
+ switch (token[0]) {
+ case '-':
+ /* Processing options names */
+ switch (token[1]) {
+ case 'd':
+ if (STREQ("display", &token[1]))
+ display_on = TRUE;
+ else if (strlen(&token[1]) == 1)
+ hvclock_infos.debug = TRUE;
+ break;
+ case 'g':
+ if (STREQ("geometry", &token[1]))
+ geometry_on = TRUE;
+ break;
+ case 'h':
+ DisplayUsage();
+ exit(EXIT_SUCCESS);
+ case 's':
+ hvclock_infos.show_seconds = TRUE;
+ break;
+ case 'v':
+ if (STREQ("version", &token[1])) {
+ DisplayVersion();
+ exit(EXIT_SUCCESS);
+ }
+ InvalidOption("invalid option", token);
+ break;
+ default:
+ InvalidOption("invalid option", token);
+ break;
+ } /* end switch( token[1] ) */
+ break;
+ default:
+ /* Processing options arguments */
+ if (display_on != FALSE) {
+ display_on = FALSE;
+ hvclock_infos.display_arg = token;
+ } else if (geometry_on != FALSE) {
+ geometry_on = FALSE;
+ hvclock_infos.geometry_arg = token;
+ } else
+ InvalidOption("invalid option", token);
+ break;
+ } /* end switch( token[0] ) */
+ } /* end for */
+
+ if (display_on != FALSE)
+ InvalidOption("missing display parameter", NULL);
+ else if (geometry_on != FALSE)
+ InvalidOption("missing geometry parameter", NULL);
- if( display_on != FALSE ) {
- InvalidOption( "missing display parameter", NULL );
- }
- else if( geometry_on != FALSE ) {
- InvalidOption( "missing geometry parameter", NULL );
- }
}
#include "dockapp.h"
#include "xevents.h"
-
/* Maximum time between mouse double-clicks, in milliseconds */
#define DOUBLE_CLICK_MAX_INTERVAL_MS 250
-
/* Function pointers to handle single and double mouse click events. */
-void (*SingleClickCallback)( void ) = NULL;
-
-void (*DoubleClickCallback)( void ) = NULL;
+void (*SingleClickCallback) (void) = NULL;
+void (*DoubleClickCallback) (void) = NULL;
/* This function must be called at the beginning of your program to initialize
the function pointers to handle single and double click mouse events. */
void
-ProcessXlibEventsInit( void (*single_click_callback)( void ),
- void (*double_click_callback)( void ) )
+ProcessXlibEventsInit(void (*single_click_callback) (void),
+ void (*double_click_callback) (void))
{
int status;
-
- /* This must be called before any other XLib functions. */
- status = XInitThreads();
- if( status == 0 ) {
- fprintf( stderr, "%s: XInitThreads() initialization failed\n", PACKAGE );
- ErrorLocation( __FILE__, __LINE__ );
- exit( EXIT_FAILURE );
- }
-
- SingleClickCallback = single_click_callback;
- DoubleClickCallback = double_click_callback;
-}
+ /* This must be called before any other XLib functions. */
+ status = XInitThreads();
+ if (status == 0) {
+ fprintf(stderr,
+ "%s: XInitThreads() initialization failed\n",
+ PACKAGE);
+ ErrorLocation(__FILE__, __LINE__);
+ exit(EXIT_FAILURE);
+ }
+
+ SingleClickCallback = single_click_callback;
+ DoubleClickCallback = double_click_callback;
+}
/* Processing of X events */
-void
-ProcessXlibEvents( void )
+void ProcessXlibEvents(void)
{
- bool quit = FALSE;
- bool button1_pressed = FALSE;
- bool check_for_double_click = FALSE;
- XEvent Event;
+ int quit = FALSE;
+ int button1_pressed = FALSE;
+ int check_for_double_click = FALSE;
+ XEvent Event;
- while( quit == FALSE ) {
- if( ( check_for_double_click != FALSE ) &&
- ( XPending( dockapp.display ) == 0 ) ) {
- /* If no other button 1 events are received after the delay, then it is a
- single-click mouse event. */
- if( SingleClickCallback != NULL ) {
- (*SingleClickCallback)();
- }
-
- check_for_double_click = FALSE;
- }
- /* XNextEvent is a blocking call: it will return only when an event is
- ready to be processed, thus freeing the CPU for other tasks when no
- events are available. */
- (void) XNextEvent( dockapp.display, &Event );
- switch( Event.type ) {
- case Expose:
- /* Window was uncovered... */
- RedrawWindow();
- break;
- case DestroyNotify:
- /* Window was killed... */
- /* Is this necessary ? */
- (void) XCloseDisplay( dockapp.display );
- quit = TRUE;
- break;
- case ClientMessage:
- /* Doesn't seem to work... */
- printf( "Client message received...\n" );
- break;
- case ButtonPress:
- if( Event.xbutton.button == Button1 ) {
- /* Mouse LEFT button pressed. */
- button1_pressed = TRUE;
- }
- break;
- case ButtonRelease:
- if( Event.xbutton.button == Button1 ) {
- /* Mouse LEFT button released. */
- if( button1_pressed != FALSE ) {
- /* We act only when the button is released */
- if( check_for_double_click != FALSE ) {
- /* Double-click */
- if( DoubleClickCallback != NULL ) {
- (*DoubleClickCallback)();
- }
- check_for_double_click = FALSE;
- }
- else {
- (void) usleep( DOUBLE_CLICK_MAX_INTERVAL_MS * 1000 );
- check_for_double_click = TRUE;
- }
- }
- }
- break;
- }
- } /* end while */
+ while (quit == FALSE) {
+ if ((check_for_double_click != FALSE) &&
+ (XPending(dockapp.display) == 0)) {
+ /*
+ * If no other button 1 events are received after the
+ * delay, then it is a single-click mouse event.
+ */
+ if (SingleClickCallback != NULL)
+ (*SingleClickCallback)();
+
+ check_for_double_click = FALSE;
+ }
+ /*
+ * XNextEvent is a blocking call: it will return only when an
+ * event is ready to be processed, thus freeing the CPU for
+ * other tasks when no events are available.
+ */
+ (void) XNextEvent(dockapp.display, &Event);
+ switch (Event.type) {
+ case Expose:
+ /* Window was uncovered... */
+ RedrawWindow();
+ break;
+ case DestroyNotify:
+ /* Window was killed... */
+ /* Is this necessary ? */
+ (void) XCloseDisplay(dockapp.display);
+ quit = TRUE;
+ break;
+ case ClientMessage:
+ /* Doesn't seem to work... */
+ printf("Client message received...\n");
+ break;
+ case ButtonPress:
+ if (Event.xbutton.button == Button1) {
+ /* Mouse LEFT button pressed. */
+ button1_pressed = TRUE;
+ }
+ break;
+ case ButtonRelease:
+ if ((Event.xbutton.button == Button1) &&
+ (button1_pressed != FALSE)) {
+ /* Mouse LEFT button released. */
+ if (check_for_double_click != FALSE) {
+ /* Double-click */
+ if (DoubleClickCallback != NULL)
+ (*DoubleClickCallback)();
+ check_for_double_click = FALSE;
+ } else {
+ (void) usleep(
+ DOUBLE_CLICK_MAX_INTERVAL_MS *
+ 1000);
+ check_for_double_click = TRUE;
+ }
+ }
+ break;
+ }
+ } /* end while */
}
#define XEVENTS_H 1
void
-ProcessXlibEventsInit(void (*single_click_callback)(void),
- void (*double_click_callback)(void));
+ProcessXlibEventsInit(void (*single_click_callback) (void),
+ void (*double_click_callback) (void));
void
ProcessXlibEvents(void);