// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x24f0
movl $0x20, 0x13df7(%rip)    # 0x19b58
movl $0x10, 0x13df1(%rip)    # 0x19b5c
movl $0x1, 0x13cbb(%rip)     # 0x19a30
movl $0x1, 0x13cb5(%rip)     # 0x19a34
callq 0x3490
movl $0x0, 0x184d2(%rip)     # 0x1e260
movq 0x13a63(%rip), %rdi     # 0x197f8
movl $0x3c, %esi
callq 0x20c0
movq %rax, 0x184c2(%rip)     # 0x1e268
movq 0x13a4b(%rip), %rdi     # 0x197f8
movl $0x58, %esi
callq 0x20c0
movq %rax, 0x184b2(%rip)     # 0x1e270
callq 0x3810
cmpl $0x0, %eax
je 0x5dd1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5dd3
cmpl $0x0, -0x14(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x5de5
jmp 0x618b
movq 0x13a0c(%rip), %rdi     # 0x197f8
leaq 0x1837d(%rip), %rsi     # 0x1e170
callq 0x2200
movl 0x18372(%rip), %eax     # 0x1e170
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x1e, %eax
ja 0x6186
movq -0x30(%rbp), %rax
leaq 0x12c1(%rip), %rcx      # 0x70dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x6186
movq 0x18360(%rip), %rax     # 0x1e190
cmpq 0x13b39(%rip), %rax     # 0x19970
jne 0x5e65
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x59f0
cmpl $0x0, %eax
je 0x5e5b
movl -0x18(%rbp), %eax
xorl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
callq 0x5050
jmp 0x6186
callq 0x5580
jmp 0x6186
movq 0x18324(%rip), %rax     # 0x1e190
cmpq 0x13cdd(%rip), %rax     # 0x19b50
jne 0x5ed7
cmpl $0x0, -0x18(%rbp)
je 0x5ec6
movl $0x320, 0x139b3(%rip)   # imm = 0x320
movl $0xf0, 0x139ad(%rip)    # 0x1983c
movl $0x0, 0x13997(%rip)     # 0x19830
movl 0x13969(%rip), %eax     # 0x19808
subl $0xf0, %eax
movl %eax, 0x1398a(%rip)     # 0x19834
callq 0x54b0
movl 0x1393b(%rip), %eax     # 0x197f0
xorl 0x13935(%rip), %eax     # 0x197f0
movl %eax, 0x1392f(%rip)     # 0x197f0
callq 0x41b0
movl $0x1, -0x18(%rbp)
callq 0x50a0
jmp 0x6186
movq 0x182b2(%rip), %rax     # 0x1e190
cmpq 0x13c43(%rip), %rax     # 0x19b28
jne 0x5f19
movq 0x1390a(%rip), %rdi     # 0x197f8
movq 0x13c33(%rip), %rsi     # 0x19b28
movq 0x13c0c(%rip), %rdx     # 0x19b08
callq 0x2330
movq 0x138f0(%rip), %rdi     # 0x197f8
movq 0x13c19(%rip), %rsi     # 0x19b28
callq 0x2060
jmp 0x6186
movq 0x18270(%rip), %rax     # 0x1e190
cmpq 0x13c09(%rip), %rax     # 0x19b30
jne 0x5fb8
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x59f0
cmpl $0x0, %eax
je 0x5f4d
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, 0x182f8(%rip)     # 0x1e24c
jne 0x5f7c
movq 0x1389b(%rip), %rdi     # 0x197f8
movq 0x13bcc(%rip), %rsi     # 0x19b30
movq 0x13b55(%rip), %rdx     # 0x19ac0
callq 0x2330
movl $0x1, 0x182d2(%rip)     # 0x1e24c
jmp 0x5fa0
movq 0x13875(%rip), %rdi     # 0x197f8
movq 0x13ba6(%rip), %rsi     # 0x19b30
movq 0x13b37(%rip), %rdx     # 0x19ac8
callq 0x2330
movl $0x0, 0x182ac(%rip)     # 0x1e24c
movq 0x13851(%rip), %rdi     # 0x197f8
movq 0x13b82(%rip), %rsi     # 0x19b30
callq 0x2060
jmp 0x6186
movq 0x181d1(%rip), %rax     # 0x1e190
cmpq 0x13b72(%rip), %rax     # 0x19b38
jne 0x5ff6
movl 0x181e2(%rip), %eax     # 0x1e1b0
movl %eax, -0x20(%rbp)
movl 0x181dd(%rip), %eax     # 0x1e1b4
movl %eax, -0x24(%rbp)
movl 0x13858(%rip), %edi     # 0x19838
subl $0x7d, %edi
addl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
addl $0x10, %esi
callq 0x5160
jmp 0x6186
movq 0x18193(%rip), %rax     # 0x1e190
cmpq 0x13b3c(%rip), %rax     # 0x19b40
jne 0x60b1
movq 0x137e7(%rip), %rdi     # 0x197f8
movq 0x13b28(%rip), %rsi     # 0x19b40
movq 0x13a91(%rip), %rdx     # 0x19ab0
callq 0x2330
movq 0x137cd(%rip), %rdi     # 0x197f8
movq 0x13b0e(%rip), %rsi     # 0x19b40
callq 0x2060
callq 0x58d0
movq 0x137b5(%rip), %rdi     # 0x197f8
movl -0x1c(%rbp), %ecx
movl $0x1, %esi
movl $0x3, %eax
cmpl $0x0, %ecx
cmovnel %eax, %esi
callq 0x5a40
callq 0x5960
movq 0x13791(%rip), %rdi     # 0x197f8
movl -0x1c(%rbp), %ecx
movl $0x1, %esi
movl $0x3, %eax
cmpl $0x0, %ecx
cmovnel %eax, %esi
callq 0x5bb0
movq 0x13772(%rip), %rdi     # 0x197f8
movq 0x13ab3(%rip), %rsi     # 0x19b40
movq 0x13a24(%rip), %rdx     # 0x19ab8
callq 0x2330
movq 0x13758(%rip), %rdi     # 0x197f8
movq 0x13a99(%rip), %rsi     # 0x19b40
callq 0x2060
jmp 0x6186
movq 0x180d8(%rip), %rax     # 0x1e190
cmpq 0x13a89(%rip), %rax     # 0x19b48
jne 0x60cb
callq 0x5330
jmp 0x6186
jmp 0x60cd
movq 0x180bc(%rip), %rax     # 0x1e190
cmpq 0x13a4d(%rip), %rax     # 0x19b28
jne 0x60f6
movl 0x1370d(%rip), %eax     # 0x197f0
addl $0x1, %eax
movl %eax, 0x13704(%rip)     # 0x197f0
callq 0x41b0
jmp 0x6186
callq 0x44b0
jmp 0x6186
cmpl $0x0, 0x180a1(%rip)     # 0x1e1a8
jne 0x6115
movq 0x18080(%rip), %rdi     # 0x1e190
callq 0x3bb0
jmp 0x6186
movq 0x136da(%rip), %rdi     # 0x197f8
movq 0x1384b(%rip), %rsi     # 0x19970
callq 0x2370
jmp 0x6186
jmp 0x6186
jmp 0x6186
jmp 0x6186
jmp 0x6186
jmp 0x6186
jmp 0x6186
movq 0x2eb9(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x1138(%rip), %rsi      # 0x7281
movb $0x0, %al
callq 0x21a0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x6186
leaq 0x1800e(%rip), %rdi     # 0x1e170
callq 0x2250
callq 0x3810
cmpl $0x0, %eax
je 0x617a
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq 0x137ef(%rip), %rdi     # 0x19970
callq 0x3bb0
jmp 0x5dd3
movq 0x13666(%rip), %rdi     # 0x197f8
movq 0x13877(%rip), %rsi     # 0x19a10
callq 0x2350
movq 0x13653(%rip), %rdi     # 0x197f8
movq 0x137c4(%rip), %rsi     # 0x19970
callq 0x2180
movq 0x13640(%rip), %rdi     # 0x197f8
callq 0x2380
xorl %edi, %edi
callq 0x2360