;================================================================================= ; Xlib XBM (X BitMap) example. ; ; The LSCR Project. ;================================================================================= format ELF include '../../macros.inc' include '../../../include/symbols.inc' include '../../../include/structs.inc' include '../../../include/x.inc' include '../../../include/x_structs.inc' public _start section '.text' executable _start: ccall XOpenDisplay, 0 ; connect to the X server test eax, eax je error mov [dpy], eax ccall XDefaultScreen, [dpy] ; obtain BLACK color value ccall XBlackPixel, [dpy], eax mov [color_black], eax ccall XDefaultScreen, [dpy] ; obtain WHITE color value ccall XWhitePixel, [dpy], eax mov [color_white], eax ccall XDefaultRootWindow, [dpy] ; create the window mov [root_win], eax ccall XCreateSimpleWindow, [dpy], [root_win], 0, 0, 300, 140, 0, [color_black], [color_black] mov [win], eax ; register events. ccall XSelectInput, [dpy], [win], StructureNotifyMask or ButtonPressMask ccall XMapWindow, [dpy], [win] ; display the main window ccall XCreateGC, [dpy], [win], 0, 0 ; create a Graphics Context mov [gc], eax ccall XSetForeground, [dpy], [gc], [color_white] ; set foreground to WHITE color @@: ccall XNextEvent, [dpy], event ; wait for mapping to finish cmp [event], MapNotify jne @b ; load the bitmap data ccall XReadBitmapFile, [dpy], [root_win], bmp_file, bitmap_width, bitmap_height, bitmap, hot_x, hot_y cmp eax, BitmapOpenFailed je error1 cmp eax, BitmapFileInvalid je error2 cmp eax, BitmapNoMemory je error3 ; draw the bitmap ccall XCopyPlane, [dpy], [bitmap], [win], [gc], 0, 0, bitmap_width, bitmap_height, 120, 40, 1 mov [text_items.chars], label_s ; draw a text string mov [text_items.nchars], label_s_sz ccall XDrawText, [dpy], [win], [gc], 5, 15, text_items, 1 @@: ccall XNextEvent, [dpy], event ; wait for a button click cmp [event], ButtonPress jne @b ccall XCloseDisplay, [dpy] ; close display connection ; and destroy windows exit: mov eax, SYS_EXIT xor ebx, ebx int 0x80 error: mov ecx, error_s mov edx, error_s_sz jmp errorf error1: mov ecx, error1_s mov edx, error1_s_sz jmp errorf error2: mov ecx, error2_s mov edx, error2_s_sz jmp errorf error3: mov ecx, error2_s mov edx, error2_s_sz jmp errorf errorf: mov eax, SYS_WRITE mov ebx, STDOUT int 0x80 jmp exit section '.data' writeable bmp_file db "xlogo.xbm",0 label_s db "To exit, click somewhere inside this window." label_s_sz = $-label_s error_s db "Failed to open a connection to the X server.",0xa error_s_sz = $-error_s error1_s db "Could not open 'xlogo.xbm' file.",0xa error1_s_sz = $-error1_s error2_s db "'xlogo.xbm' is not a valid bitmap file.",0xa error2_s_sz = $-error2_s error3_s db "Not enough free memory.",0xa error3_s_sz = $-error3_s root_win rd 1 bitmap_width rd 1 bitmap_height rd 1 bitmap rd 1 hot_x rd 1 hot_y rd 1 dpy rd 1 event rd sizeof.XButtonEvent ; this actually should be an XEvent union color_black rd 1 color_white rd 1 win rd 1 gc rd 1 text_items XTextItem