// File: /workspace/github_c_makefile_star2_O3/kyx0r[P]xkeyboard/xkeyboard.c
// Function: main
int main(int argc, char **argv)
{
	int done = 0;
	int keyboard_active = 0;
	int rightclick = 0;

	init_display(argc, argv);
	ox = 32; oy = 16; sn = 1; sd = 1;
	create_keys();
	closingstate = NORMAL;
	mycursor = XCreateFontCursor(dpy, XC_hand2);
	closecursor = XCreateFontCursor(dpy, XC_pirate);
	if (get_keyboard_mapping())
		done++;
	/* Main event loop */
	while (!done) {
		XNextEvent(dpy, &myevent);
		switch (myevent.type) {
			case EnterNotify:
				break;
			case ButtonPress:
				if(myevent.xbutton.window == mywindow)
				{
					if(doubleclick(500))
					{
						keyboard_active ^= keyboard_active;
						hide();
						break;
					}
					move_keys();
					break;
				}
				if (myevent.xbutton.window == closewindow) {
					if(keyboard_active)
					{
						myhint.width = 800;
						myhint.height = 240;
						myhint.x = 0;
						myhint.y = screenheight - 240;
						reset_keyspos();
						zoom ^= zoom; do_control();//set zoom to default.
					}
					keyboard_active = 1;
					show();
					break;
				}
				if (myevent.xbutton.window == zoomwin) {
					XSetWindowBackgroundPixmap(dpy,
						zoomwin,
						cpgm[NUM_CONSTPGM - 4]);
					XClearWindow(dpy, zoomwin);
					break;
				}
				if (myevent.xbutton.window == modewin) {
					if(doubleclick(500))
					{
						rightclick = !rightclick;
					}
					if(!sendkey)
					{
						XSetWindowBackgroundPixmap(dpy,
								modewin,
								cpgm[NUM_CONSTPGM - 13]);
						sendkey = 1;
					}
					else
					{
						XSetWindowBackgroundPixmap(dpy,
								modewin,
								cpgm[NUM_CONSTPGM - 12]);
						sendkey = 0;
					}
					XClearWindow(dpy, modewin);
					break;	
				}
				if (myevent.xbutton.window == movewin) {
					int mx = myevent.xbutton.x;
					int my = myevent.xbutton.y;
					movebutton((myhint.width - 125)+mx, 16 + my);
					break;
				}
				if (myevent.xbutton.window == mousewin) {
					XSetWindowBackgroundPixmap(dpy,
							mousewin,
							cpgm[NUM_CONSTPGM - 15]);
					XClearWindow(dpy, mousewin);
					wait_btn_press();
					btn_press(dpy, rightclick ? Button3 : Button1);
					wait_btn_release();
					btn_release(dpy, rightclick ? Button3 : Button1);
					XSetWindowBackgroundPixmap(dpy,
							mousewin,
							cpgm[NUM_CONSTPGM - 14]);
					XClearWindow(dpy, mousewin);
					break;
				}
				if (myevent.xbutton.window == lbcornerwin) {
				 	resize_win();	
					break;
				}
			case ButtonRelease:
				if (myevent.xbutton.window == zoomwin) {
					zoom++;
					do_control();
					break;
				}
				do_button_event();
				break;
			case Expose:
				if (!myevent.xexpose.count)
					redraw_window(myevent.xexpose.window);
				break;
			case VisibilityNotify:
				XRaiseWindow(dpy, mywindow);
				break;
			case UnmapNotify:
				break;
			case CirculateNotify:
				break;
			case ConfigureNotify:
				break;
			case CreateNotify:
				break;
			case MapNotify:
				break;
			case ReparentNotify:
				break;
			case DestroyNotify:
				fprintf(stderr, "WM Terminated\n");
				done++;
				break;
			case MappingNotify:
				XRefreshKeyboardMapping(
					(XMappingEvent *) &myevent);
				if (get_keyboard_mapping())
					done++;
				redraw_window(mywindow);
				break;
		}
	}
	XFreeGC(dpy, mygc);
	XDestroyWindow(dpy, mywindow);
	XCloseDisplay(dpy);
	exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x261c
movl $0x20, 0x13e4d(%rip)    # 0x18b58
movl $0x10, 0x13e47(%rip)    # 0x18b5c
movl $0x1, %eax
movl %eax, 0x13d10(%rip)     # 0x18a30
movl %eax, 0x13d0e(%rip)     # 0x18a34
callq 0x31cb
movl $0x0, 0x1852b(%rip)     # 0x1d260
movq 0x13abc(%rip), %rdi     # 0x187f8
movl $0x3c, %esi
callq 0x20b0
movq %rax, 0x1851b(%rip)     # 0x1d268
movq 0x13aa4(%rip), %rdi     # 0x187f8
movl $0x58, %esi
callq 0x20b0
movq %rax, 0x1850b(%rip)     # 0x1d270
callq 0x33f5
testl %eax, %eax
jne 0x50ba
xorl %r14d, %r14d
leaq 0x183f4(%rip), %rbx     # 0x1d170
movabsq $0xf000000320, %r15     # imm = 0xF000000320
movl $0xffffff10, %r12d      # imm = 0xFFFFFF10
xorl %r13d, %r13d
movl $0x0, 0x4(%rsp)
movq 0x13a5a(%rip), %rdi     # 0x187f8
movq %rbx, %rsi
callq 0x21f0
movl 0x183c4(%rip), %eax     # 0x1d170
cmpl $0xe, %eax
jg 0x4ddb
cmpl $0x4, %eax
je 0x4e11
cmpl $0x5, %eax
je 0x4e4c
cmpl $0xc, %eax
jne 0x4d97
cmpl $0x0, 0x183dd(%rip)     # 0x1d1a8
jne 0x4d97
movq 0x183bc(%rip), %rdi     # 0x1d190
callq 0x365b
jmp 0x4d97
cmpl $0xf, %eax
je 0x4e6f
cmpl $0x22, %eax
jne 0x4e91
movq %rbx, %rdi
callq 0x2240
callq 0x33f5
movl %eax, %ebp
movq 0x13b6d(%rip), %rdi     # 0x18970
callq 0x365b
testl %ebp, %ebp
je 0x4d97
jmp 0x50ba
movq 0x18378(%rip), %rsi     # 0x1d190
cmpq 0x13b51(%rip), %rsi     # 0x18970
jne 0x4e9f
movq 0x18380(%rip), %rax     # 0x1d1a8
movq %rax, %rcx
subq 0x18426(%rip), %rcx     # 0x1d258
cmpq $0x1f3, %rcx            # imm = 0x1F3
ja 0x4eeb
callq 0x4349
xorl %r13d, %r13d
jmp 0x4d97
movq 0x1833d(%rip), %rsi     # 0x1d190
movq 0x13cce(%rip), %rax     # 0x18b28
cmpq %rax, %rsi
jne 0x4e87
incl 0x1398b(%rip)           # 0x187f0
callq 0x3a5e
jmp 0x4d97
movq 0x13982(%rip), %rdi     # 0x187f8
movq 0x13af3(%rip), %rsi     # 0x18970
callq 0x2370
jmp 0x4d97
callq 0x3baa
jmp 0x4d97
cmpl $0x11, %eax
jne 0x4d97
jmp 0x509a
cmpq 0x13caa(%rip), %rsi     # 0x18b50
jne 0x4efc
testl %r13d, %r13d
je 0x4edb
movq %r15, 0x13984(%rip)     # 0x18838
movl %r14d, 0x13975(%rip)    # 0x18830
movl 0x13947(%rip), %eax     # 0x18808
addl %r12d, %eax
movl %eax, 0x1396a(%rip)     # 0x18834
callq 0x46f4
movl %r14d, 0x1391a(%rip)    # 0x187f0
callq 0x3a5e
callq 0x438c
movl $0x1, %r13d
jmp 0x4d97
movq %rax, 0x18366(%rip)     # 0x1d258
callq 0x474f
jmp 0x4d97
movq 0x13c25(%rip), %rax     # 0x18b28
cmpq %rax, %rsi
jne 0x4f33
movq 0x138e9(%rip), %rdi     # 0x187f8
movq 0x13bf2(%rip), %rdx     # 0x18b08
callq 0x2320
movq 0x138d6(%rip), %rdi     # 0x187f8
movq 0x13bff(%rip), %rsi     # 0x18b28
callq 0x2060
jmp 0x4d97
cmpq 0x13bf6(%rip), %rsi     # 0x18b30
jne 0x4f66
movq 0x18265(%rip), %rax     # 0x1d1a8
movq %rax, %rcx
subq 0x1830b(%rip), %rcx     # 0x1d258
cmpq $0x1f3, %rcx            # imm = 0x1F3
ja 0x4f94
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
sete %al
movl %eax, 0x4(%rsp)
jmp 0x4f9b
cmpq 0x13bcb(%rip), %rsi     # 0x18b38
jne 0x4fe7
movl 0x1823b(%rip), %eax     # 0x1d1b0
movl 0x18239(%rip), %esi     # 0x1d1b4
movl 0x138b7(%rip), %ecx     # 0x18838
leal (%rax,%rcx), %edi
addl $-0x7d, %edi
addl $0x10, %esi
callq 0x4418
jmp 0x4d97
movq %rax, 0x182bd(%rip)     # 0x1d258
xorl %ebp, %ebp
cmpl $0x0, 0x182a8(%rip)     # 0x1d24c
sete %bpl
movq 0x13849(%rip), %rdi     # 0x187f8
leaq 0x13b12(%rip), %rax     # 0x18ac8
leaq 0x13b03(%rip), %rcx     # 0x18ac0
cmoveq %rcx, %rax
movq (%rax), %rdx
callq 0x2320
movl %ebp, 0x1827d(%rip)     # 0x1d24c
movq 0x13822(%rip), %rdi     # 0x187f8
movq 0x13b53(%rip), %rsi     # 0x18b30
callq 0x2060
jmp 0x4d97
cmpq 0x13b52(%rip), %rsi     # 0x18b40
jne 0x5083
movq 0x137fd(%rip), %rdi     # 0x187f8
movq 0x13aae(%rip), %rdx     # 0x18ab0
callq 0x2320
movq 0x137ea(%rip), %rdi     # 0x187f8
movq 0x13b2b(%rip), %rsi     # 0x18b40
callq 0x2060
callq 0x499d
movq 0x137d2(%rip), %rdi     # 0x187f8
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
setne %al
leal 0x1(,%rax,2), %ebp
movl %ebp, %esi
callq 0x4ab6
callq 0x4a16
movq 0x137ae(%rip), %rdi     # 0x187f8
movl %ebp, %esi
callq 0x4bd5
movq 0x137a0(%rip), %rdi     # 0x187f8
movq 0x13ae1(%rip), %rsi     # 0x18b40
movq 0x13a52(%rip), %rdx     # 0x18ab8
callq 0x2320
movq 0x13786(%rip), %rdi     # 0x187f8
movq 0x13ac7(%rip), %rsi     # 0x18b40
callq 0x2060
jmp 0x4d97
cmpq 0x13abe(%rip), %rsi     # 0x18b48
jne 0x4e5a
callq 0x45bc
jmp 0x4d97
movq 0x2f57(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x1092(%rip), %rdi      # 0x613d
movl $0xe, %esi
movl $0x1, %edx
callq 0x2360
movq 0x13737(%rip), %rdi     # 0x187f8
movq 0x13948(%rip), %rsi     # 0x18a10
callq 0x2340
movq 0x13724(%rip), %rdi     # 0x187f8
movq 0x13895(%rip), %rsi     # 0x18970
callq 0x2170
movq 0x13711(%rip), %rdi     # 0x187f8
callq 0x2380
xorl %edi, %edi
callq 0x2350