mudgangster

Log | Files | Refs

commit d6bb854d83fe3c499e6852411c430b0944a0015d
parent 749779f75c4d1c8ad09ce10e99f853617a64b2d0
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue,  4 Sep 2018 12:25:44 +0300

Misc cleanup

Diffstat:
src/common.h | 19-------------------
src/textbox.h | 2+-
src/ui.h | 21++++++++++++++++++++-
src/x11.cc | 53+++++++++++++++++++----------------------------------
4 files changed, 40 insertions(+), 55 deletions(-)

diff --git a/src/common.h b/src/common.h @@ -28,22 +28,3 @@ inline To checked_cast( const From & from ) { assert( From( result ) == from ); return result; } - -// TODO: probably don't need most of these -enum Colour { - BLACK, - RED, - GREEN, - YELLOW, - BLUE, - MAGENTA, - CYAN, - WHITE, - SYSTEM, - - NUM_COLOURS, - - COLOUR_BG, - COLOUR_STATUSBG, - COLOUR_CURSOR, -}; diff --git a/src/textbox.h b/src/textbox.h @@ -1,6 +1,6 @@ #pragma once -#include "common.h" +#include "ui.h" constexpr size_t MAX_LINE_LENGTH = 2048; constexpr size_t SCROLLBACK_SIZE = 1 << 16; diff --git a/src/ui.h b/src/ui.h @@ -2,6 +2,25 @@ #include "common.h" +// TODO: probably don't need most of these +enum Colour { + BLACK, + RED, + GREEN, + YELLOW, + BLUE, + MAGENTA, + CYAN, + WHITE, + SYSTEM, + + NUM_COLOURS, + + COLOUR_BG, + COLOUR_STATUSBG, + COLOUR_CURSOR, +}; + void ui_handleXEvents(); // TODO: very x11 specific! void ui_draw_status(); @@ -24,7 +43,7 @@ void ui_dirty( int left, int top, int right, int bottom ); // TODO: x/y + w/h? void ui_get_font_size( int * fw, int * fh ); -bool ui_urgent(); +void ui_urgent(); int ui_display_fd(); // TODO: very x11 specific! diff --git a/src/x11.cc b/src/x11.cc @@ -1,5 +1,3 @@ -#include <stdio.h> -#include <stdlib.h> #include <err.h> #include <X11/Xutil.h> @@ -26,24 +24,19 @@ struct { TextBox main_text; TextBox chat_text; - int width; - int height; - int depth; + int width, height; int max_width, max_height; + int depth; - bool dirty; - int dirty_left, dirty_top, dirty_right, dirty_bottom; + // bool dirty; + // int dirty_left, dirty_top, dirty_right, dirty_bottom; bool has_focus; } UI; struct MudFont { - int ascent; - int descent; - - int height; - int width; - + int ascent, descent; + int width, height; XFontStruct * font; }; @@ -305,9 +298,8 @@ void ui_statusAdd( const char c, const Colour fg, const bool bold ) { if( ( statusLen + 1 ) * sizeof( StatusChar ) > statusCapacity ) { size_t newcapacity = statusCapacity * 2; StatusChar * newcontents = ( StatusChar * ) realloc( statusContents, newcapacity ); - if( !newcontents ) - return err( 1, "oom" ); + err( 1, "realloc" ); statusContents = newcontents; statusCapacity = newcapacity; @@ -587,22 +579,18 @@ void ui_handleXEvents() { event_handlers[ event.type ]( &event ); } - if( UI.dirty ) { - XCopyArea( UI.display, UI.back_buffer, UI.window, UI.gc, UI.dirty_left, UI.dirty_top, UI.dirty_right - UI.dirty_left, UI.dirty_bottom - UI.dirty_top, UI.dirty_left, UI.dirty_top ); - UI.dirty = false; - } + // if( UI.dirty ) { + // XCopyArea( UI.display, UI.back_buffer, UI.window, UI.gc, UI.dirty_left, UI.dirty_top, UI.dirty_right - UI.dirty_left, UI.dirty_bottom - UI.dirty_top, UI.dirty_left, UI.dirty_top ); + // UI.dirty = false; + // } } static MudFont loadFont( const char * fontStr ) { MudFont font; font.font = XLoadQueryFont( UI.display, fontStr ); - - if( !font.font ) { - printf( "could not load font %s\n", fontStr ); - - exit( 1 ); - } + if( !font.font ) + errx( 1, "XLoadQueryFont: %s", fontStr ); font.ascent = font.font->ascent; font.descent = font.font->descent; @@ -620,9 +608,10 @@ static ulong make_color( const char * hex ) { } static void initStyle() { - Style.bg = make_color( "#1a1a1a" ); - Style.status_bg = make_color( "#333333" ); - Style.cursor = make_color( "#00ff00" ); + Style.bg = make_color( "#1a1a1a" ); + Style.status_bg = make_color( "#333333" ); + Style.cursor = make_color( "#00ff00" ); + Style.Colours.system = make_color( "#ffffff" ); Style.Colours.black = make_color( "#1a1a1a" ); Style.Colours.red = make_color( "#ca4433" ); @@ -642,8 +631,6 @@ static void initStyle() { Style.Colours.lcyan = make_color( "#29fbff" ); Style.Colours.lwhite = make_color( "#cedbde" ); - Style.Colours.system = make_color( "#ffffff" ); - Style.font = loadFont( "-windows-dina-medium-r-normal--10-*-*-*-c-0-*-*" ); Style.fontBold = loadFont( "-windows-dina-bold-r-normal--10-*-*-*-c-0-*-*" ); } @@ -664,10 +651,8 @@ void ui_init() { UI.colorMap = XDefaultColormap( UI.display, UI.screen ); statusContents = ( StatusChar * ) malloc( statusCapacity * sizeof( StatusChar ) ); - - if( statusContents == NULL ) { - err( 1, "oom" ); - } + if( statusContents == NULL ) + err( 1, "malloc" ); initStyle();