// File: /workspace/github_c_makefile_star2_O1/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, 0x13dde(%rip)    # 0x18b58
movl $0x10, 0x13dd8(%rip)    # 0x18b5c
movl $0x1, %r12d
movl %r12d, 0x13c9f(%rip)    # 0x18a30
movl %r12d, 0x13c9c(%rip)    # 0x18a34
callq 0x31cb
movl $0x0, 0x184b9(%rip)     # 0x1d260
movq 0x13a4a(%rip), %rdi     # 0x187f8
movl $0x3c, %esi
callq 0x20b0
movq %rax, 0x184a9(%rip)     # 0x1d268
movq 0x13a32(%rip), %rdi     # 0x187f8
movl $0x58, %esi
callq 0x20b0
movq %rax, 0x18499(%rip)     # 0x1d270
callq 0x33fe
testl %eax, %eax
jne 0x512c
movl %eax, %ebp
xorl %r15d, %r15d
leaq 0x18380(%rip), %rbx     # 0x1d170
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x139fb(%rip), %rdi     # 0x187f8
movq %rbx, %rsi
callq 0x21f0
movl 0x18365(%rip), %eax     # 0x1d170
cmpl $0xe, %eax
jg 0x4e3d
cmpl $0x4, %eax
je 0x4e6b
cmpl $0x5, %eax
je 0x5102
cmpl $0xc, %eax
jne 0x5124
cmpl $0x0, 0x1837a(%rip)     # 0x1d1a8
jne 0x5124
movq 0x18355(%rip), %rdi     # 0x1d190
jmp 0x4e61
cmpl $0xf, %eax
je 0x4eaa
cmpl $0x22, %eax
jne 0x4ec2
movq %rbx, %rdi
callq 0x2240
callq 0x33fe
testl %eax, %eax
cmovnel %r12d, %ebp
movq 0x13b0f(%rip), %rdi     # 0x18970
callq 0x365b
jmp 0x5124
movq 0x1831e(%rip), %rax     # 0x1d190
cmpq 0x13af7(%rip), %rax     # 0x18970
jne 0x4ef5
movq 0x18326(%rip), %rax     # 0x1d1a8
movq %rax, %rcx
subq 0x183cc(%rip), %rcx     # 0x1d258
cmpq $0x1f4, %rcx            # imm = 0x1F4
jb 0x4f4f
movq %rax, 0x183b8(%rip)     # 0x1d258
callq 0x47cd
jmp 0x5124
movq 0x13947(%rip), %rdi     # 0x187f8
movq 0x13ab8(%rip), %rsi     # 0x18970
callq 0x2370
jmp 0x5124
cmpl $0x11, %eax
jne 0x5124
movq 0x3126(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
movl $0xe, %esi
movl $0x1, %edx
leaq 0x1257(%rip), %rdi      # 0x613d
callq 0x2360
movl $0x1, %ebp
jmp 0x5124
cmpq 0x13c54(%rip), %rax     # 0x18b50
jne 0x4f5c
testl %r13d, %r13d
je 0x4f3f
movabsq $0xf000000320, %rax     # imm = 0xF000000320
movq %rax, 0x13924(%rip)     # 0x18838
movl %r15d, 0x13915(%rip)    # 0x18830
movl 0x138e7(%rip), %eax     # 0x18808
movl $0xffffff10, %ecx       # imm = 0xFFFFFF10
addl %ecx, %eax
movl %eax, 0x13906(%rip)     # 0x18834
callq 0x4766
movl %r15d, 0x138b6(%rip)    # 0x187f0
callq 0x3ace
callq 0x440e
movl $0x1, %r13d
jmp 0x5124
callq 0x43cb
xorl %r13d, %r13d
jmp 0x5124
movq 0x13bc5(%rip), %rsi     # 0x18b28
cmpq %rsi, %rax
jne 0x4f93
movq 0x13889(%rip), %rdi     # 0x187f8
movq 0x13b92(%rip), %rdx     # 0x18b08
callq 0x2320
movq 0x13876(%rip), %rdi     # 0x187f8
movq 0x13b9f(%rip), %rsi     # 0x18b28
callq 0x2060
jmp 0x5124
movq 0x13b96(%rip), %rsi     # 0x18b30
cmpq %rsi, %rax
jne 0x5026
movq 0x181fe(%rip), %rcx     # 0x1d1a8
movq %rcx, %rax
subq 0x182a4(%rip), %rax     # 0x1d258
cmpq $0x1f4, %rax            # imm = 0x1F4
jb 0x4fc3
movq %rcx, 0x18295(%rip)     # 0x1d258
xorl %ecx, %ecx
testl %r14d, %r14d
sete %cl
cmpq $0x1f4, %rax            # imm = 0x1F4
cmovbl %ecx, %r14d
xorl %r15d, %r15d
cmpl $0x0, 0x1826d(%rip)     # 0x1d24c
sete %r15b
movq 0x1380e(%rip), %rdi     # 0x187f8
leaq 0x13ad7(%rip), %rax     # 0x18ac8
leaq 0x13ac8(%rip), %rcx     # 0x18ac0
cmoveq %rcx, %rax
movq (%rax), %rdx
callq 0x2320
movl %r15d, 0x18241(%rip)    # 0x1d24c
movq 0x137e6(%rip), %rdi     # 0x187f8
movq 0x13b17(%rip), %rsi     # 0x18b30
callq 0x2060
xorl %r15d, %r15d
jmp 0x5124
cmpq 0x13b0b(%rip), %rax     # 0x18b38
jne 0x5054
movl 0x1817b(%rip), %eax     # 0x1d1b0
movl 0x18179(%rip), %esi     # 0x1d1b4
movl 0x137f7(%rip), %ecx     # 0x18838
leal (%rax,%rcx), %edi
addl $-0x7d, %edi
addl $0x10, %esi
callq 0x44a0
jmp 0x5124
movq 0x13ae5(%rip), %rsi     # 0x18b40
cmpq %rsi, %rax
jne 0x50f2
movq 0x1378d(%rip), %rdi     # 0x187f8
movq 0x13a3e(%rip), %rdx     # 0x18ab0
callq 0x2320
movq 0x1377a(%rip), %rdi     # 0x187f8
movq 0x13abb(%rip), %rsi     # 0x18b40
callq 0x2060
callq 0x4a12
movq 0x13762(%rip), %rdi     # 0x187f8
xorl %eax, %eax
testl %r14d, %r14d
setne %al
leal 0x1(,%rax,2), %r15d
movl %r15d, %esi
callq 0x4b2b
callq 0x4a8b
movq 0x1373e(%rip), %rdi     # 0x187f8
movl %r15d, %esi
xorl %r15d, %r15d
callq 0x4c47
movq 0x1372c(%rip), %rdi     # 0x187f8
movq 0x13a6d(%rip), %rsi     # 0x18b40
movq 0x139de(%rip), %rdx     # 0x18ab8
callq 0x2320
movq 0x13712(%rip), %rdi     # 0x187f8
movq 0x13a53(%rip), %rsi     # 0x18b40
jmp 0x4f89
cmpq 0x13a4f(%rip), %rax     # 0x18b48
jne 0x5102
callq 0x463b
jmp 0x5124
movq 0x18087(%rip), %rax     # 0x1d190
cmpq 0x13a18(%rip), %rax     # 0x18b28
jne 0x511f
incl 0x136d8(%rip)           # 0x187f0
callq 0x3ace
jmp 0x5124
callq 0x3c1a
testl %ebp, %ebp
je 0x4df6
movq 0x136c5(%rip), %rdi     # 0x187f8
movq 0x138d6(%rip), %rsi     # 0x18a10
callq 0x2340
movq 0x136b2(%rip), %rdi     # 0x187f8
movq 0x13823(%rip), %rsi     # 0x18970
callq 0x2170
movq 0x1369f(%rip), %rdi     # 0x187f8
callq 0x2380
xorl %edi, %edi
callq 0x2350