📄 xautolock.c
字号:
//----------------------------------------------------------------------------//// KDE screensavers//// This module is a heavily modified xautolock.// The orignal copyright notice follows///***************************************************************************** * * xautolock * ========= * * Authors : S. De Troch (SDT) + M. Eyckmans (MCE) * * Date : 22/07/90 * * --------------------------------------------------------------------------- * * Copyright 1990, 1992-1995 by S. De Troch and MCE. * * Permission to use, copy, modify and distribute this software and the * supporting documentation without fee is hereby granted, provided that * * 1 : Both the above copyright notice and this permission notice * appear in all copies of both the software and the supporting * documentation. * 2 : No financial profit is made out of it. * * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO * EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. * *****************************************************************************//* * Have a guess what this does... * ============================== * * Warning for swm & tvtwm users : xautolock should *not* be compiled * with vroot.h, because it needs to know the real root window. */#ifdef HAVE_CONFIG_H#include <config.h>#endif#if defined(hpux) || defined (__hpux)#ifndef _HPUX_SOURCE#define _HPUX_SOURCE#endif /* _HPUX_SOURCE */#endif /* hpux || __hpux */#include <stdio.h>#include <string.h>#include <ctype.h>#ifdef VMS#include <ssdef.h> #include <processes.h> /* really needed? */#endif /* VMS */#include <X11/Xlib.h>#include <X11/Xatom.h>#include <X11/Xresource.h>#include <time.h>#include <signal.h>#include <sys/wait.h>#include <sys/types.h>#ifdef HAVE_SYS_M_WAIT_H#include <sys/m_wait.h>#endif #ifdef HAVE_MALLOC_H#include <malloc.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <stdlib.h>#undef TrueColor#include <qapp.h>#include "xautolock.h"/* * Usefull macros and customization stuff * ====================================== */#define PP(x) x#ifdef VMS#define ALL_OK 1 /* for use by exit () */#define PROBLEMS SS$_ABORT /* for use by exit () */#else /* VMS */#define ALL_OK 0 /* for use by exit () */#define PROBLEMS 1 /* for use by exit () */#endif /* VMS */#define FALSE 0 /* as it says */#define TRUE 1 /* as it says */#define MINUTES 10 /* default ... */#define CREATION_DELAY 30 /* should be > 10 and < min (45,(MIN_MINUTES*30)) */#define CORNER_SIZE 10 /* size in pixels of the force-lock areas */#define CORNER_DELAY 5 /* number of seconds to wait before forcing a lock */#define TIME_CHANGE_LIMIT 120 /* if the time changes by more than x secs then we will assume someone has changed date or machine has suspended */#ifndef HasVFork#define vfork fork#endif /* HasVFork */#define Error0(str) fprintf (stderr, str)#define SetTrigger(delta) trigger = time ((time_t*) NULL) + deltastatic caddr_t ch_ptr; /* this is dirty */#define Skeleton(t,s) (ch_ptr = (Caddrt) malloc ((Unsigned) s), \ (ch_ptr == (Caddrt) NULL) \ ? (Error0 ("Out of memory.\n"), \ exit (PROBLEMS), \ /*NOTREACHED*/ (t*) NULL \ ) \ : (t*) ch_ptr \ ) \#define New(tp) Skeleton (tp, sizeof (tp))/* * New types * ========= */#if defined (apollo) || defined (news1800) typedef int (*XErrorHandler) PP((Display*, XErrorEvent*));#endif /* apollo || news1800 */#if defined (news1800) || defined (sun386) typedef int pid_t;#endif /* news1800 || sun386*/#ifdef VMStypedef long pid_t;#endif /* VMS */#define Void void /* no typedef because of VAX */typedef int Int;typedef char Char;typedef char* String;typedef int Boolean;typedef caddr_t Caddrt;typedef unsigned int Unsigned;typedef unsigned long Huge;typedef struct QueueItem_ { Window window; /* as it says */ time_t creationtime; /* as it says */ struct QueueItem_* next; /* as it says */ struct QueueItem_* prev; /* as it says */ } aQueueItem, *QueueItem;typedef struct Queue_ { struct QueueItem_* head; /* as it says */ struct QueueItem_* tail; /* as it says */ } aQueue, *Queue;/* * Function declarations * ===================== */#if defined(news1800) extern Void* malloc PP((Unsigned));#endif /* news1800 */ static int EvaluateCounter PP((Display*));static int QueryPointer PP((Display*));static Void ProcessEvents PP((Display*, Queue));static Queue NewQueue PP((Void));static Void AddToQueue PP((Queue, Window));static Void ProcessQueue PP((Queue, Display*, time_t));static Void SelectEvents PP((Display*, Window, Boolean));/* * Global variables * ================ */static time_t trigger = 0; /* as it says */static time_t time_limit = MINUTES; /* as it says */static Int corner_size = CORNER_SIZE; /* as it says */static time_t corner_delay = CORNER_DELAY; /* as it says */static CornerAction corners[4] = { IGNORE, IGNORE, IGNORE, IGNORE }; /* default CornerActions *//* * Functions related to the window queue * ===================================== * * Function for creating a new queue * --------------------------------- */static Queue NewQueue (){ Queue queue; /* return value */ queue = New (aQueue); queue->tail = New (aQueueItem); queue->head = New (aQueueItem); queue->tail->next = queue->head; queue->head->prev = queue->tail; queue->tail->prev = queue->head->next = (QueueItem) NULL; return queue;}/* * Function for adding an item to a queue * -------------------------------------- */static Void AddToQueue (Queue queue, Window window){ QueueItem newq; /* new item */ newq = New (aQueueItem); newq->window = window; newq->creationtime = time ((time_t*) NULL); newq->next = queue->tail->next; newq->prev = queue->tail; queue->tail->next->prev = newq; queue->tail->next = newq;}/* * Function for processing those entries that are old enough * --------------------------------------------------------- */static Void ProcessQueue (Queue queue, Display *d, time_t age){ QueueItem current; /* as it says */ time_t now; /* as it says */ time (&now); current = queue->head->prev; while ( current->prev && current->creationtime + age < now ) { SelectEvents (d, current->window, False); current = current->prev; free (current->next); } current->next = queue->head; queue->head->prev = current;}static Void FreeQueue( Queue queue ){ QueueItem current; /* as it says */ current = queue->head->prev; while ( current->prev ) { current = current->prev; free(current->next); } free(current); free(queue);}/* * Functions related to (the lack of) user activity * ================================================ * * Function for processing the event queue * --------------------------------------- */static Void ProcessEvents (Display *d, Queue queue){ XEvent event; /* as it says */ /* * Read whatever is available for reading. */ while (XPending (d)) { if (XCheckMaskEvent (d, SubstructureNotifyMask, &event)) { if (event.type == CreateNotify) { AddToQueue (queue, event.xcreatewindow.window); } } else { XNextEvent (d, &event); } /* * Reset the counter if and only if the event is a KeyPress * event *and* was not generated by XSendEvent (). */ if ( event.type == KeyPress && !event.xany.send_event ) { SetTrigger (time_limit); } } /* * Check the window queue for entries that are older than * CREATION_DELAY seconds. */ ProcessQueue (queue, d, (time_t) CREATION_DELAY);}/* * Function for monitoring pointer movements * ----------------------------------------- */static int QueryPointer (Display *d){ Window dummy_w; /* as it says */ Int dummy_c; /* as it says */ Unsigned mask; /* modifier mask */ Int root_x; /* as it says */ Int root_y; /* as it says */ time_t now; /* as it says */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -