// File: /workspace/github_c_makefile_star2_O2/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 0x24ec
movl $0x20, 0x13000(%rip)    # 0x17b58
movl $0x10, 0x12ffa(%rip)    # 0x17b5c
pushq $0x1
popq %r12
movl %r12d, 0x12ec3(%rip)    # 0x17a30
movl %r12d, 0x12ec0(%rip)    # 0x17a34
callq 0x3109
andl $0x0, 0x176e0(%rip)     # 0x1c260
movq 0x12c71(%rip), %rdi     # 0x177f8
pushq $0x3c
popq %rsi
callq 0x20b0
movq %rax, 0x176d2(%rip)     # 0x1c268
movq 0x12c5b(%rip), %rdi     # 0x177f8
pushq $0x58
popq %rsi
callq 0x20b0
movq %rax, 0x176c4(%rip)     # 0x1c270
movl $0x0, 0x4(%rsp)
callq 0x334c
movl %eax, %ebp
leaq 0x175ae(%rip), %rbx     # 0x1c170
movabsq $0xf000000320, %r13     # imm = 0xF000000320
movl $0xffffff10, %r15d      # imm = 0xFFFFFF10
xorl %r14d, %r14d
movq 0x12c1c(%rip), %rdi     # 0x177f8
testl %ebp, %ebp
jne 0x4f10
movq %rbx, %rsi
callq 0x21f0
xorl %ebp, %ebp
movl 0x1757c(%rip), %eax     # 0x1c170
cmpl $0x4, %eax
je 0x4cb8
cmpl $0x5, %eax
je 0x4c3b
cmpl $0xc, %eax
je 0x4c82
cmpl $0xf, %eax
je 0x4ca0
cmpl $0x22, %eax
je 0x4c62
cmpl $0x11, %eax
jne 0x4bd5
movq 0x23d7(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x512(%rip), %rdi       # 0x513d
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2360
movl %r12d, %ebp
jmp 0x4bd5
movq 0x1754e(%rip), %rsi     # 0x1c190
movq 0x12edf(%rip), %rax     # 0x17b28
cmpq %rax, %rsi
jne 0x4cf1
incl 0x12b98(%rip)           # 0x177f0
callq 0x39c3
jmp 0x4bd5
movq %rbx, %rdi
callq 0x2240
callq 0x334c
movl %eax, %ebp
movq 0x12cf8(%rip), %rdi     # 0x17970
callq 0x35ba
jmp 0x4bd5
cmpl $0x0, 0x1751f(%rip)     # 0x1c1a8
jne 0x4bd5
movq 0x174fa(%rip), %rdi     # 0x1c190
callq 0x35ba
jmp 0x4bd5
movq 0x12b51(%rip), %rdi     # 0x177f8
movq 0x12cc2(%rip), %rsi     # 0x17970
callq 0x2370
jmp 0x4bd5
movq 0x174d1(%rip), %rsi     # 0x1c190
cmpq 0x12caa(%rip), %rsi     # 0x17970
jne 0x4cfb
movq 0x174d9(%rip), %rax     # 0x1c1a8
movq %rax, %rcx
subq 0x1757f(%rip), %rcx     # 0x1c258
cmpq $0x1f3, %rcx            # imm = 0x1F3
ja 0x4d44
callq 0x4234
xorl %r14d, %r14d
xorl %ebp, %ebp
jmp 0x4bd5
callq 0x3ae8
jmp 0x4bd5
cmpq 0x12e4e(%rip), %rsi     # 0x17b50
jne 0x4d55
testl %r14d, %r14d
je 0x4d37
movq %r13, 0x12b28(%rip)     # 0x17838
andl $0x0, 0x12b19(%rip)     # 0x17830
movl 0x12aeb(%rip), %eax     # 0x17808
addl %r15d, %eax
movl %eax, 0x12b0e(%rip)     # 0x17834
callq 0x4570
andl $0x0, 0x12abe(%rip)     # 0x177f0
callq 0x39c3
callq 0x4272
movl %r12d, %r14d
jmp 0x4bd5
movq %rax, 0x1750d(%rip)     # 0x1c258
callq 0x45cb
jmp 0x4bd5
movq 0x12dcc(%rip), %rax     # 0x17b28
cmpq %rax, %rsi
jne 0x4d8c
movq 0x12a90(%rip), %rdi     # 0x177f8
movq 0x12d99(%rip), %rdx     # 0x17b08
callq 0x2320
movq 0x12a7d(%rip), %rdi     # 0x177f8
movq 0x12da6(%rip), %rsi     # 0x17b28
callq 0x2060
jmp 0x4bd5
cmpq 0x12d9d(%rip), %rsi     # 0x17b30
jne 0x4dbf
movq 0x1740c(%rip), %rax     # 0x1c1a8
movq %rax, %rcx
subq 0x174b2(%rip), %rcx     # 0x1c258
cmpq $0x1f3, %rcx            # imm = 0x1F3
ja 0x4df1
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
sete %al
movl %eax, 0x4(%rsp)
jmp 0x4df8
cmpq 0x12d72(%rip), %rsi     # 0x17b38
jne 0x4e50
movl 0x173de(%rip), %eax     # 0x1c1b0
movl 0x173dc(%rip), %esi     # 0x1c1b4
movl 0x12a5a(%rip), %ecx     # 0x17838
leal (%rax,%rcx), %edi
addl $-0x7d, %edi
addl $0x10, %esi
callq 0x42fe
jmp 0x4bd5
movq %rax, 0x17460(%rip)     # 0x1c258
xorl %r13d, %r13d
cmpl $0x0, 0x1744a(%rip)     # 0x1c24c
sete %r13b
movq 0x129eb(%rip), %rdi     # 0x177f8
leaq 0x12cb4(%rip), %rax     # 0x17ac8
leaq 0x12ca5(%rip), %rcx     # 0x17ac0
cmoveq %rcx, %rax
movq (%rax), %rdx
callq 0x2320
movl %r13d, 0x1741e(%rip)    # 0x1c24c
movq 0x129c3(%rip), %rdi     # 0x177f8
movq 0x12cf4(%rip), %rsi     # 0x17b30
callq 0x2060
movabsq $0xf000000320, %r13     # imm = 0xF000000320
jmp 0x4bd5
cmpq 0x12ce9(%rip), %rsi     # 0x17b40
jne 0x4ef9
movq 0x12994(%rip), %rdi     # 0x177f8
movq 0x12c45(%rip), %rdx     # 0x17ab0
callq 0x2320
movq 0x12981(%rip), %rdi     # 0x177f8
movq 0x12cc2(%rip), %rsi     # 0x17b40
callq 0x2060
callq 0x47df
movq 0x12969(%rip), %rdi     # 0x177f8
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
setne %al
leal 0x1(,%rax,2), %r13d
movl %r13d, %esi
callq 0x48e3
callq 0x484e
movq 0x12943(%rip), %rdi     # 0x177f8
movl %r13d, %esi
movabsq $0xf000000320, %r13     # imm = 0xF000000320
callq 0x4a11
movq 0x1292a(%rip), %rdi     # 0x177f8
movq 0x12c6b(%rip), %rsi     # 0x17b40
movq 0x12bdc(%rip), %rdx     # 0x17ab8
callq 0x2320
movq 0x12910(%rip), %rdi     # 0x177f8
movq 0x12c51(%rip), %rsi     # 0x17b40
callq 0x2060
jmp 0x4bd5
cmpq 0x12c48(%rip), %rsi     # 0x17b48
jne 0x4c49
callq 0x4472
jmp 0x4bd5
movq 0x12af9(%rip), %rsi     # 0x17a10
callq 0x2340
movq 0x128d5(%rip), %rdi     # 0x177f8
movq 0x12a46(%rip), %rsi     # 0x17970
callq 0x2170
movq 0x128c2(%rip), %rdi     # 0x177f8
callq 0x2380
xorl %edi, %edi
callq 0x2350