summaryrefslogtreecommitdiffhomepage
path: root/src/debug/ptyc_dbg_event.c
blob: e04a0c3eb4de0dbfe7a721963be22fe96524424c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*********************************************************/
/*  ptycon: a pty-console bridge                         */
/*  Copyright (C) 2016--2017  SysDeer Technologies, LLC  */
/*  Released under GPLv2 and GPLv3; see COPYING.PTYCON.  */
/*********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntcon/ntcon.h>
#include <ntapi/ntapi.h>
#include <gdi/gdi.h>

#include <ptycon/ptycon.h>
#include "ptycon_driver_impl.h"

static int ptyc_dbg_input_record(void * hout, nt_input_record * rec)
{
	char *		ch;
	uintptr_t	buffer[512/sizeof(uintptr_t)];
	uint32_t	nwritten;

	ntapi->tt_aligned_block_memset(
		buffer,0,sizeof(buffer));

	ch = (char *)buffer;

	switch (rec->event_type) {
		case NT_KEY_EVENT:
			ntapi->snprintf(ch,sizeof(buffer),
					"key event. "
					"key down: %d; "
					"repeat count: %d; "
					"virtual key code: 0x%04x; "
					"virtual scan code: 0x%04x; "
					"unicode char: 0x%04x; "
					"control key: 0x%04x.\n",
					rec->key_event.key_down,
					rec->key_event.repeat_count,
					rec->key_event.virtual_key_code,
					rec->key_event.virtual_scan_code,
					rec->key_event.unicode_char,
					rec->key_event.control_key_state);
			break;

		case NT_MOUSE_EVENT:
			ntapi->snprintf(ch,sizeof(buffer),
					"mouse event. "
					"pos.x: %d; "
					"pos.y: %d; "
					"button state: 0x%04x; "
					"ctrl key state: 0x%04x; "
					"event flags: 0x%04x.\n",
					rec->mouse_event.mouse_position.x,
					rec->mouse_event.mouse_position.y,
					rec->mouse_event.button_state,
					rec->mouse_event.control_key_state,
					rec->mouse_event.event_flags);
			break;

		case NT_WINDOW_BUFFER_SIZE_EVENT:
			ntapi->snprintf(ch,sizeof(buffer),
					"window event. "
					"size.x: %d; "
					"size.y: %d.\n",
					rec->window_event.size.x,
					rec->window_event.size.y);

			break;

		case NT_MENU_EVENT:
			ntapi->snprintf(ch,sizeof(buffer),
					"menu event. "
					"command id: %d.\n",
					rec->menu_event.command_id);
			break;

		case NT_FOCUS_EVENT:
			ntapi->snprintf(ch,sizeof(buffer),
					"focus event. "
					"set focus: %d.\n",
					rec->focus_event.set_focus);
			break;

		default:
			return NT_STATUS_INTERNAL_ERROR;
	}

	return ntcon->write_console_ansi(
		hout,ch,
		(uint32_t)ntapi->tt_string_null_offset_multibyte(ch),
		&nwritten,0);
}


int __stdcall ptyc_dbg_event(struct ptyc_driver_ctx_impl * ictx)
{
	nt_input_record	conevt[64];
	uint32_t	nread;
	unsigned	i;

	do {
		if (!(ntcon->read_console_input_utf16(
				ictx->tctx.hin,
				conevt,64,
				&nread)))
			return -1;

		for (i=0; i<nread; i++)
			if (!(ptyc_dbg_input_record(
					ictx->tctx.hout,
					&conevt[i])))
				return -2;
	} while (1);

	return -3;
}