Skip to content

Commit b82f44e

Browse files
uli42sunweaver
authored andcommitted
nxagent: Add keystroke for dumping the current clipboard state
1 parent 89de77c commit b82f44e

File tree

8 files changed

+31
-26
lines changed

8 files changed

+31
-26
lines changed

doc/nxagent/README.keystrokes

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ reread_keystrokes
129129
autograb
130130
Toggles autograb mode
131131

132+
dump_clipboard
133+
print the current internal clipboard state (for debugging) to the
134+
log.
135+
132136
force_synchronization
133137
Forces immediate drawing of elements to be synchronized which can
134138
fix some visual bugs.

etc/keystrokes.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525
<keystroke action="viewport_scroll_down" Control="1" AltMeta="1" key="KP_Down" />
2626
<keystroke action="reread_keystrokes" Control="1" AltMeta="1" key="k" />
2727
<keystroke action="autograb" Control="1" AltMeta="1" key="g" />
28+
<keystroke action="dump_clipboard" Control="1" Shift="1" AltMeta="1" key="c" />
2829
</keystrokes>

nx-X11/programs/Xserver/hw/nxagent/Clipboard.c

+9-25
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ extern Selection *CurrentSelections;
6868
int nxagentLastClipboardClient = -1;
6969

7070
static int agentClipboardInitialized = False;
71-
#ifdef DEBUG
7271
static int clientAccum;
73-
#endif
7472

7573
XlibAtom serverTransToAgentProperty;
7674
Atom clientCutProperty;
@@ -156,19 +154,16 @@ static char szAgentCLIPBOARD[] = "CLIPBOARD";
156154
/* number of milliseconds to wait for a conversion from the real X server. */
157155
#define CONVERSION_TIMEOUT 5000
158156

159-
#ifdef DEBUG
160157
/*
161158
* Time window (milliseconds) within to detect multiple conversion
162159
* calls of the same client.
163160
*/
164161
#define ACCUM_TIME 5000
165-
#endif
166162

167163
/*
168164
* some helpers for debugging output
169165
*/
170166

171-
#ifdef DEBUG
172167
static const char * getClientSelectionStageString(int stage)
173168
{
174169
switch(stage)
@@ -181,15 +176,18 @@ static const char * getClientSelectionStageString(int stage)
181176
default: return("UNKNOWN!"); break;;
182177
}
183178
}
179+
180+
#ifdef DEBUG
184181
#define setClientSelectionStage(stage) do {fprintf(stderr, "%s: Changing selection stage from [%s] to [%s]\n", __func__, getClientSelectionStageString(lastClientStage), getClientSelectionStageString(SelectionStage##stage)); lastClientStage = SelectionStage##stage;} while (0)
185182
#define printClientSelectionStage() do {fprintf(stderr, "%s: Current selection stage [%s]\n", __func__, getClientSelectionStageString(lastClientStage));} while (0)
186-
#define WINDOWID(ptr) (ptr) ? (ptr->drawable.id) : 0
187-
#define CLINDEX(clientptr) (clientptr) ? (clientptr->index) : -1
188183
#else
189184
#define setClientSelectionStage(stage) do {lastClientStage = SelectionStage##stage;} while (0)
190185
#define printClientSelectionStage()
191186
#endif
192187

188+
#define WINDOWID(ptr) (ptr) ? (ptr->drawable.id) : 0
189+
#define CLINDEX(clientptr) (clientptr) ? (clientptr->index) : -1
190+
193191
#ifdef DEBUG
194192
/*
195193
* see also nx-X11/lib/src/ErrDes.c
@@ -267,7 +265,6 @@ void nxagentPrintClipboardStat(char *);
267265
extern unsigned long startTime;
268266
#endif
269267

270-
#ifdef DEBUG
271268
static void printSelectionStat(int sel)
272269
{
273270
SelectionOwner lOwner = lastSelectionOwner[sel];
@@ -313,14 +310,12 @@ static void printSelectionStat(int sel)
313310
fprintf(stderr, " CurrentSelections[].window [0x%x]\n", curSel.window);
314311
return;
315312
}
316-
#endif
317313

318-
void nxagentPrintClipboardStat(char *header)
314+
void nxagentDumpClipboardStat(void)
319315
{
320-
#ifdef DEBUG
321316
char *s = NULL;
322317

323-
fprintf(stderr, "/----- Clipboard internal status - %s -----\n", header);
318+
fprintf(stderr, "/----- Clipboard internal status -----\n");
324319

325320
fprintf(stderr, " current time (Time) [%u]\n", GetTimeInMillis());
326321
fprintf(stderr, " agentClipboardInitialized (Bool) [%s]\n", agentClipboardInitialized ? "True" : "False");
@@ -399,7 +394,6 @@ void nxagentPrintClipboardStat(char *header)
399394
fprintf(stderr, "\\------------------------------------------------------------------------------\n");
400395

401396
SAFE_XFree(s);
402-
#endif
403397
}
404398

405399
/*
@@ -581,8 +575,6 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
581575
(void *) pClient, CLINDEX(pClient), (void *) pWindow, WINDOWID(pWindow));
582576
#endif
583577

584-
nxagentPrintClipboardStat("before nxagentClearClipboard");
585-
586578
/*
587579
* Only for PRIMARY and CLIPBOARD selections.
588580
*/
@@ -610,8 +602,6 @@ void nxagentClearClipboard(ClientPtr pClient, WindowPtr pWindow)
610602
lastClientWindowPtr = NULL;
611603
setClientSelectionStage(None);
612604
}
613-
614-
nxagentPrintClipboardStat("after nxagentClearClipboard");
615605
}
616606

617607
/*
@@ -655,8 +645,6 @@ void nxagentHandleSelectionClearFromXServer(XEvent *X)
655645
fprintf(stderr, "%s: SelectionClear event for selection [%lu].\n", __func__, X->xselectionclear.selection);
656646
#endif
657647

658-
nxagentPrintClipboardStat("before nxagentHandleSelectionClearFromXServer");
659-
660648
if (!agentClipboardInitialized)
661649
{
662650
#ifdef DEBUG
@@ -701,7 +689,6 @@ void nxagentHandleSelectionClearFromXServer(XEvent *X)
701689

702690
lastClientWindowPtr = NULL;
703691
setClientSelectionStage(None);
704-
nxagentPrintClipboardStat("after nxagentHandleSelectionClearFromXServer");
705692
}
706693

707694
/*
@@ -760,8 +747,6 @@ void nxagentHandleSelectionRequestFromXServer(XEvent *X)
760747
}
761748
#endif
762749

763-
nxagentPrintClipboardStat("before nxagentHandleSelectionRequestFromXServer");
764-
765750
if (!agentClipboardInitialized)
766751
{
767752
#ifdef DEBUG
@@ -984,7 +969,6 @@ void nxagentHandleSelectionRequestFromXServer(XEvent *X)
984969
}
985970
}
986971
}
987-
nxagentPrintClipboardStat("after nxagentHandleSelectionRequestFromXServer");
988972
}
989973

990974
/*
@@ -1887,7 +1871,6 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
18871871
}
18881872
}
18891873

1890-
#ifdef DEBUG
18911874
if (lastClientClientPtr == client && (GetTimeInMillis() - lastClientReqTime < ACCUM_TIME))
18921875
{
18931876
/*
@@ -1897,9 +1880,11 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
18971880
* client requesting PRIMARY and CLIPBOARD would match here, too
18981881
*/
18991882

1883+
#ifdef DEBUG
19001884
fprintf(stderr, "%s: Consecutives request from client [%p] selection [%u] "
19011885
"elapsed time [%u] clientAccum [%d]\n", __func__, (void *) client, selection,
19021886
GetTimeInMillis() - lastClientReqTime, clientAccum);
1887+
#endif
19031888

19041889
clientAccum++;
19051890
}
@@ -1911,7 +1896,6 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
19111896
clientAccum = 0;
19121897
}
19131898
}
1914-
#endif
19151899

19161900
if (target == clientTEXT ||
19171901
target == XA_STRING ||

nx-X11/programs/Xserver/hw/nxagent/Clipboard.h

+2
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ extern WindowPtr nxagentGetClipboardWindow(Atom property);
7878

7979
extern int nxagentSendNotify(xEvent *event);
8080

81+
extern void nxagentDumpClipboardStat(void);
82+
8183
#endif /* __Clipboard_H__ */

nx-X11/programs/Xserver/hw/nxagent/Events.c

+5
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,11 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
10701070
nxagentToggleAutoGrab();
10711071
break;
10721072
}
1073+
case doDumpClipboard:
1074+
{
1075+
nxagentDumpClipboardStat();
1076+
break;
1077+
}
10731078
default:
10741079
{
10751080
FatalError("nxagentDispatchEvent: handleKeyPress returned unknown value\n");

nx-X11/programs/Xserver/hw/nxagent/Events.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum HandleEventResult
5252
doSwitchResizeMode,
5353
doSwitchDeferMode,
5454
doAutoGrab,
55+
doDumpClipboard
5556
};
5657

5758
extern CARD32 nxagentLastEventTime;

nx-X11/programs/Xserver/hw/nxagent/Keystroke.c

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ char * nxagentSpecialKeystrokeNames[] = {
102102

103103
"autograb",
104104

105+
"dump_clipboard",
106+
105107
NULL,
106108
};
107109

@@ -142,6 +144,7 @@ struct nxagentSpecialKeystrokeMap default_map[] = {
142144
{KEYSTROKE_VIEWPORT_SCROLL_DOWN, ControlMask, True, XK_KP_Down},
143145
{KEYSTROKE_REREAD_KEYSTROKES, ControlMask, True, XK_k},
144146
{KEYSTROKE_AUTOGRAB, ControlMask, True, XK_g},
147+
{KEYSTROKE_DUMP_CLIPBOARD, ControlMask | ShiftMask, True, XK_c},
145148
{KEYSTROKE_END_MARKER, 0, False, NoSymbol},
146149
};
147150
struct nxagentSpecialKeystrokeMap *map = default_map;
@@ -715,6 +718,9 @@ Bool nxagentCheckSpecialKeystroke(XKeyEvent *X, enum HandleEventResult *result)
715718
case KEYSTROKE_AUTOGRAB:
716719
*result = doAutoGrab;
717720
break;
721+
case KEYSTROKE_DUMP_CLIPBOARD:
722+
*result = doDumpClipboard;
723+
break;
718724
case KEYSTROKE_NOTHING: /* do nothing. difference to KEYSTROKE_IGNORE is the return value */
719725
case KEYSTROKE_END_MARKER: /* just to make gcc STFU */
720726
case KEYSTROKE_MAX:

nx-X11/programs/Xserver/hw/nxagent/Keystroke.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ enum nxagentSpecialKeystroke {
7878

7979
KEYSTROKE_AUTOGRAB,
8080

81-
KEYSTROKE_NOTHING,
81+
KEYSTROKE_DUMP_CLIPBOARD,
8282

8383
/* insert more here and in the string translation */
8484

85+
KEYSTROKE_NOTHING,
86+
8587
KEYSTROKE_MAX,
8688
};
8789

0 commit comments

Comments
 (0)