18db30ca8Sthorpej/* x11-ssh-askpass.h:  A generic X11-based password dialog for OpenSSH.
2c056561aSmbalmer * created 1999-Nov-17 03:40 Jim Knoble <jmknoble@jmknoble.cx>
3c056561aSmbalmer * autodate: 2001-Feb-14 04:00
48db30ca8Sthorpej *
5c056561aSmbalmer * by Jim Knoble <jmknoble@jmknoble.cx>
6c056561aSmbalmer * Copyright (C) 1999,2000,2001 Jim Knoble
78db30ca8Sthorpej *
88db30ca8Sthorpej * Disclaimer:
98db30ca8Sthorpej *
108db30ca8Sthorpej * The software is provided "as is", without warranty of any kind,
118db30ca8Sthorpej * express or implied, including but not limited to the warranties of
128db30ca8Sthorpej * merchantability, fitness for a particular purpose and
138db30ca8Sthorpej * noninfringement. In no event shall the author(s) be liable for any
148db30ca8Sthorpej * claim, damages or other liability, whether in an action of
158db30ca8Sthorpej * contract, tort or otherwise, arising from, out of or in connection
168db30ca8Sthorpej * with the software or the use or other dealings in the software.
178db30ca8Sthorpej *
188db30ca8Sthorpej * Portions of this code are distantly derived from code in xscreensaver
198db30ca8Sthorpej * by Jamie Zawinski <jwz@jwz.org>.  That code says:
208db30ca8Sthorpej *
218db30ca8Sthorpej * --------8<------------------------------------------------8<--------
228db30ca8Sthorpej * xscreensaver, Copyright (c) 1991-1999 Jamie Zawinski <jwz@jwz.org>
238db30ca8Sthorpej *
248db30ca8Sthorpej * Permission to use, copy, modify, distribute, and sell this software and its
258db30ca8Sthorpej * documentation for any purpose is hereby granted without fee, provided that
268db30ca8Sthorpej * the above copyright notice appear in all copies and that both that
278db30ca8Sthorpej * copyright notice and this permission notice appear in supporting
288db30ca8Sthorpej * documentation.  No representations are made about the suitability of this
298db30ca8Sthorpej * software for any purpose.  It is provided "as is" without express or
308db30ca8Sthorpej * implied warranty.
318db30ca8Sthorpej * --------8<------------------------------------------------8<--------
328db30ca8Sthorpej *
338db30ca8Sthorpej * The remainder of this code falls under the same permissions and
348db30ca8Sthorpej * provisions as those of the xscreensaver code.
358db30ca8Sthorpej */
368db30ca8Sthorpej
378db30ca8Sthorpej#ifndef H_X11_SSH_ASKPASS
388db30ca8Sthorpej#define H_X11_SSH_ASKPASS
398db30ca8Sthorpej
408db30ca8Sthorpej#include <X11/Xlib.h>
418db30ca8Sthorpej#include <X11/Intrinsic.h>
428db30ca8Sthorpej#include <X11/Shell.h>
438db30ca8Sthorpej
448db30ca8Sthorpej#define EXIT_STATUS_ACCEPT	0
458db30ca8Sthorpej#define EXIT_STATUS_CANCEL	1
468db30ca8Sthorpej#define EXIT_STATUS_NO_MEMORY	2
478db30ca8Sthorpej#define EXIT_STATUS_ERROR	3
48c056561aSmbalmer#define EXIT_STATUS_TIMEOUT	4
498db30ca8Sthorpej#define EXIT_STATUS_ANOMALY	127
508db30ca8Sthorpej
518db30ca8Sthorpejtypedef struct
528db30ca8Sthorpej{
538db30ca8Sthorpej   Pixel foreground;
548db30ca8Sthorpej   Pixel background;
558db30ca8Sthorpej   Dimension width;
568db30ca8Sthorpej   Dimension height;
578db30ca8Sthorpej   Position x;
588db30ca8Sthorpej   Position y;
598db30ca8Sthorpej} WidgetInfo;
608db30ca8Sthorpej
618db30ca8Sthorpejtypedef struct
628db30ca8Sthorpej{
638db30ca8Sthorpej   WidgetInfo w;
648db30ca8Sthorpej   Pixel topShadowColor;
658db30ca8Sthorpej   Pixel bottomShadowColor;
668db30ca8Sthorpej   Dimension shadowThickness;
678db30ca8Sthorpej   Pixel borderColor;
688db30ca8Sthorpej   Dimension borderWidth;
698db30ca8Sthorpej   Dimension interiorWidth;
708db30ca8Sthorpej   Dimension interiorHeight;
718db30ca8Sthorpej   Dimension horizontalSpacing;
728db30ca8Sthorpej   Dimension verticalSpacing;
738db30ca8Sthorpej} Widget3dInfo;
748db30ca8Sthorpej
75c056561aSmbalmertypedef struct TextObjectStruct
768db30ca8Sthorpej{
778db30ca8Sthorpej   char *text;
788db30ca8Sthorpej   int textLength;
798db30ca8Sthorpej   int direction;
808db30ca8Sthorpej   int ascent;
818db30ca8Sthorpej   int descent;
828db30ca8Sthorpej   XCharStruct overall;
83c056561aSmbalmer   struct TextObjectStruct *next;
84c056561aSmbalmer} TextObject;
85c056561aSmbalmer
86c056561aSmbalmertypedef struct
87c056561aSmbalmer{
88c056561aSmbalmer   char *fullText;
89c056561aSmbalmer   XFontStruct *font;
90c056561aSmbalmer   XFontStruct *fixedFont;
91c056561aSmbalmer   TextObject *multiText;
928db30ca8Sthorpej   WidgetInfo w;
938db30ca8Sthorpej} LabelInfo;
948db30ca8Sthorpej
958db30ca8Sthorpejtypedef struct
968db30ca8Sthorpej{
978db30ca8Sthorpej   Widget3dInfo w3;
988db30ca8Sthorpej   LabelInfo label;
998db30ca8Sthorpej   Bool pressed;
1008db30ca8Sthorpej} ButtonInfo;
1018db30ca8Sthorpej
1028db30ca8Sthorpejtypedef struct
1038db30ca8Sthorpej{
1048db30ca8Sthorpej   Widget3dInfo w3;
1058db30ca8Sthorpej   int count;
1068db30ca8Sthorpej   int current;
1078db30ca8Sthorpej   int minimumCount;
1088db30ca8Sthorpej   int maximumCount;
1098db30ca8Sthorpej} MasterIndicatorInfo;
1108db30ca8Sthorpej
1118db30ca8Sthorpejtypedef struct
1128db30ca8Sthorpej{
1138db30ca8Sthorpej   MasterIndicatorInfo *parent;
1148db30ca8Sthorpej   WidgetInfo w;
1158db30ca8Sthorpej   Bool isLit;
1168db30ca8Sthorpej} IndicatorElement;
1178db30ca8Sthorpej
1188db30ca8Sthorpejtypedef struct
1198db30ca8Sthorpej{
1208db30ca8Sthorpej   Window dialogWindow;
1218db30ca8Sthorpej
1228db30ca8Sthorpej   XSizeHints *sizeHints;
1238db30ca8Sthorpej   XWMHints *wmHints;
1248db30ca8Sthorpej   XClassHint *classHints;
1258db30ca8Sthorpej   XTextProperty windowName;
1268db30ca8Sthorpej
1278db30ca8Sthorpej   char *title;
1288db30ca8Sthorpej   Widget3dInfo w3;
1298db30ca8Sthorpej
1308db30ca8Sthorpej   LabelInfo label;
1318db30ca8Sthorpej
1328db30ca8Sthorpej   MasterIndicatorInfo indicator;
1338db30ca8Sthorpej   IndicatorElement *indicators;
1348db30ca8Sthorpej
1358db30ca8Sthorpej   ButtonInfo okButton;
1368db30ca8Sthorpej   ButtonInfo cancelButton;
1378db30ca8Sthorpej
1388db30ca8Sthorpej   int pressedButton;
1398db30ca8Sthorpej} DialogInfo;
1408db30ca8Sthorpej
1418db30ca8Sthorpej#define NO_BUTTON	0
1428db30ca8Sthorpej#define OK_BUTTON	1
1438db30ca8Sthorpej#define CANCEL_BUTTON	2
1448db30ca8Sthorpej
1458db30ca8Sthorpejtypedef struct
1468db30ca8Sthorpej{
1478db30ca8Sthorpej   char *appName;
1488db30ca8Sthorpej   char *appClass;
1498db30ca8Sthorpej
1508db30ca8Sthorpej   int argc;
1518db30ca8Sthorpej   char **argv;
1528db30ca8Sthorpej
153c056561aSmbalmer   pid_t pid;
154c056561aSmbalmer
1558db30ca8Sthorpej   char *buf;
1568db30ca8Sthorpej   int bufSize;
1578db30ca8Sthorpej   int bufIndex;
1588db30ca8Sthorpej
1598db30ca8Sthorpej   Display *dpy;
1608db30ca8Sthorpej   Screen *screen;
161c056561aSmbalmer   long screen_width;
162c056561aSmbalmer   long screen_height;
1638db30ca8Sthorpej   Window rootWindow;
1648db30ca8Sthorpej   Pixel black;
1658db30ca8Sthorpej   Pixel white;
1668db30ca8Sthorpej   Colormap colormap;
167c056561aSmbalmer
168c056561aSmbalmer   /* Resolution measurements are normalized to dots/meter. */
169c056561aSmbalmer   long xResolution;
170c056561aSmbalmer   long yResolution;
171c056561aSmbalmer   long defaultXResolution;
172c056561aSmbalmer   long defaultYResolution;
173c056561aSmbalmer   long xFuzz;
174c056561aSmbalmer   long yFuzz;
1758db30ca8Sthorpej
1768db30ca8Sthorpej   XtAppContext appContext;
1778db30ca8Sthorpej   Widget toplevelShell;
1788db30ca8Sthorpej   XrmDatabase resourceDb;
1798db30ca8Sthorpej
1808db30ca8Sthorpej   Atom wmDeleteWindowAtom;
1818db30ca8Sthorpej
1828db30ca8Sthorpej   GC fillGC;
1838db30ca8Sthorpej   GC borderGC;
1848db30ca8Sthorpej   GC textGC;
1858db30ca8Sthorpej   GC brightGC;
1868db30ca8Sthorpej   GC dimGC;
1878db30ca8Sthorpej
188c056561aSmbalmer   long eventMask;
189c056561aSmbalmer
1908db30ca8Sthorpej   Bool grabKeyboard;
1918db30ca8Sthorpej   Bool grabPointer;
1928db30ca8Sthorpej   Bool grabServer;
1938db30ca8Sthorpej   Bool isKeyboardGrabbed;
1948db30ca8Sthorpej   Bool isPointerGrabbed;
1958db30ca8Sthorpej   Bool isServerGrabbed;
196c056561aSmbalmer   unsigned int grabFailTimeout;
197c056561aSmbalmer   unsigned int grabRetryInterval;
198c056561aSmbalmer
199c056561aSmbalmer   unsigned long inputTimeout;
200c056561aSmbalmer   XtIntervalId inputTimeoutTimerId;
201c056561aSmbalmer   Bool inputTimeoutActive;
2028db30ca8Sthorpej
2038db30ca8Sthorpej   DialogInfo *dialog;
2048db30ca8Sthorpej} AppInfo;
2058db30ca8Sthorpej
2068db30ca8Sthorpejvoid outOfMemory(AppInfo *app, int line);
2078db30ca8Sthorpejvoid freeIf(void *p);
2088db30ca8Sthorpejvoid freeFontIf(AppInfo *app, XFontStruct *f);
2098db30ca8Sthorpej
2108db30ca8SthorpejXFontStruct *getFontResource(AppInfo *app, char *instanceName, char *className);
2118db30ca8Sthorpejchar *getStringResourceWithDefault(char *instanceName, char *className,
2128db30ca8Sthorpej				   char *defaultText);
213c056561aSmbalmerunsigned int getUnsignedIntegerResource(AppInfo *app, char *instanceName,
214c056561aSmbalmer					char *className,
215c056561aSmbalmer					unsigned int defaultValue);
216c056561aSmbalmerlong getResolutionResource(AppInfo *app, char *instanceName, char *className,
217c056561aSmbalmer			   char *defaultResolutionSpec);
2188db30ca8Sthorpej
2198db30ca8Sthorpejvoid calcLabelTextExtents(LabelInfo *label);
2208db30ca8Sthorpejvoid calcTotalButtonExtents(ButtonInfo *button);
2218db30ca8Sthorpejvoid calcButtonExtents(ButtonInfo *button);
2228db30ca8Sthorpejvoid balanceButtonExtents(ButtonInfo *button1, ButtonInfo *button2);
2238db30ca8Sthorpejvoid calcButtonLabelPosition(ButtonInfo *button);
2248db30ca8Sthorpej
225c056561aSmbalmerDimension scaleXDimension(AppInfo *app, Dimension unscaled);
226c056561aSmbalmerDimension scaleYDimension(AppInfo *app, Dimension unscaled);
227c056561aSmbalmer
2288db30ca8Sthorpejvoid createDialog(AppInfo *app);
2298db30ca8Sthorpejvoid destroyDialog(AppInfo *app);
2308db30ca8Sthorpejvoid createDialogWindow(AppInfo *app);
2318db30ca8Sthorpejvoid createGCs(AppInfo *app);
2328db30ca8Sthorpejvoid destroyGCs(AppInfo *app);
2338db30ca8Sthorpej
2348db30ca8Sthorpejvoid paintLabel(AppInfo *app, Drawable draw, LabelInfo label);
2358db30ca8Sthorpejvoid paintButton(AppInfo *app, Drawable draw, ButtonInfo button);
2368db30ca8Sthorpejvoid paintIndicator(AppInfo *app, Drawable draw, IndicatorElement indicator);
2378db30ca8Sthorpejvoid updateIndicatorElement(AppInfo *app, int i);
2388db30ca8Sthorpejvoid updateIndicators(AppInfo *app, int condition);
2398db30ca8Sthorpejvoid paintDialog(AppInfo *app);
2408db30ca8Sthorpej
241c056561aSmbalmer#define GRAB_KEYBOARD	0
242c056561aSmbalmer#define GRAB_POINTER	1
243c056561aSmbalmervoid performGrab(AppInfo *app, int grabType, char *grabTypeName,
244c056561aSmbalmer		 Bool shouldGrab, Bool *isGrabbed);
245c056561aSmbalmer
2468db30ca8Sthorpejvoid grabKeyboard(AppInfo *app);
2478db30ca8Sthorpejvoid ungrabKeyboard(AppInfo *app);
2488db30ca8Sthorpejvoid grabPointer(AppInfo *app);
2498db30ca8Sthorpejvoid ungrabPointer(AppInfo *app);
2508db30ca8Sthorpejvoid grabServer(AppInfo *app);
2518db30ca8Sthorpejvoid ungrabServer(AppInfo *app);
2528db30ca8Sthorpej
2538db30ca8Sthorpejvoid cleanUp(AppInfo *app);
2548db30ca8Sthorpejvoid exitApp(AppInfo *app, int exitCode);
2558db30ca8Sthorpej
2568db30ca8Sthorpejvoid acceptAction(AppInfo *app);
2578db30ca8Sthorpejvoid cancelAction(AppInfo *app);
2588db30ca8Sthorpej
2598db30ca8Sthorpejvoid backspacePassphrase(AppInfo *app);
2608db30ca8Sthorpejvoid erasePassphrase(AppInfo *app);
2618db30ca8Sthorpejvoid addToPassphrase(AppInfo *app, char c);
2628db30ca8Sthorpej
263c056561aSmbalmervoid handleKeyPress(AppInfo *app, XEvent *event);
264c056561aSmbalmerBool eventIsInsideButton(AppInfo *app, XEvent *event, ButtonInfo button);
265c056561aSmbalmervoid handleButtonPress(AppInfo *app, XEvent *event);
266c056561aSmbalmervoid handlePointerMotion(AppInfo *app, XEvent *event);
267c056561aSmbalmer
268c056561aSmbalmervoid handleInputTimeout(XtPointer data, XtIntervalId *timerId);
269c056561aSmbalmervoid cancelInputTimeout(AppInfo *app);
2708db30ca8Sthorpej
2718db30ca8Sthorpej#endif /* H_X11_SSH_ASKPASS */
272