From 95b7adbdb6c77c80dfc59b4e370d7a1fae8e4d5e Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 13 May 2018 00:41:58 -0400 Subject: Tabify bin --- bin/gfx/cocoa.m | 196 ++++++++++++++++++++++++++++---------------------------- bin/gfx/fb.c | 76 +++++++++++----------- bin/gfx/none.c | 2 +- bin/gfx/x11.c | 158 ++++++++++++++++++++++----------------------- 4 files changed, 216 insertions(+), 216 deletions(-) (limited to 'bin/gfx') diff --git a/bin/gfx/cocoa.m b/bin/gfx/cocoa.m index 54f39e62..6c0f0d66 100644 --- a/bin/gfx/cocoa.m +++ b/bin/gfx/cocoa.m @@ -26,78 +26,78 @@ #define UNUSED __attribute__((unused)) @interface BufferView : NSView { - size_t bufSize; - uint32_t *buf; - CGColorSpaceRef colorSpace; - CGDataProviderRef dataProvider; + size_t bufSize; + uint32_t *buf; + CGColorSpaceRef colorSpace; + CGDataProviderRef dataProvider; } @end @implementation BufferView - (instancetype) initWithFrame: (NSRect) frameRect { - colorSpace = CGColorSpaceCreateDeviceRGB(); - return [super initWithFrame: frameRect]; + colorSpace = CGColorSpaceCreateDeviceRGB(); + return [super initWithFrame: frameRect]; } - (void) setWindowTitle { - [[self window] setTitle: [NSString stringWithUTF8String: status()]]; + [[self window] setTitle: [NSString stringWithUTF8String: status()]]; } - (void) draw { - draw(buf, [self frame].size.width, [self frame].size.height); - [self setNeedsDisplay: YES]; + draw(buf, [self frame].size.width, [self frame].size.height); + [self setNeedsDisplay: YES]; } - (void) setFrameSize: (NSSize) newSize { - [super setFrameSize: newSize]; - size_t newBufSize = 4 * newSize.width * newSize.height; - if (newBufSize > bufSize) { - bufSize = newBufSize; - buf = malloc(bufSize); - if (!buf) err(EX_OSERR, "malloc(%zu)", bufSize); - CGDataProviderRelease(dataProvider); - dataProvider = CGDataProviderCreateWithData(NULL, buf, bufSize, NULL); - } - [self draw]; + [super setFrameSize: newSize]; + size_t newBufSize = 4 * newSize.width * newSize.height; + if (newBufSize > bufSize) { + bufSize = newBufSize; + buf = malloc(bufSize); + if (!buf) err(EX_OSERR, "malloc(%zu)", bufSize); + CGDataProviderRelease(dataProvider); + dataProvider = CGDataProviderCreateWithData(NULL, buf, bufSize, NULL); + } + [self draw]; } - (void) drawRect: (NSRect) UNUSED dirtyRect { - NSSize size = [self frame].size; - CGContextRef ctx = [[NSGraphicsContext currentContext] CGContext]; - CGImageRef image = CGImageCreate( - size.width, size.height, - 8, 32, 4 * size.width, - colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, - dataProvider, - NULL, false, kCGRenderingIntentDefault - ); - CGContextDrawImage(ctx, [self frame], image); - CGImageRelease(image); + NSSize size = [self frame].size; + CGContextRef ctx = [[NSGraphicsContext currentContext] CGContext]; + CGImageRef image = CGImageCreate( + size.width, size.height, + 8, 32, 4 * size.width, + colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, + dataProvider, + NULL, false, kCGRenderingIntentDefault + ); + CGContextDrawImage(ctx, [self frame], image); + CGImageRelease(image); } - (BOOL) acceptsFirstResponder { - return YES; + return YES; } - (void) keyDown: (NSEvent *) event { - char in; - BOOL converted = [ - [event characters] - getBytes: &in - maxLength: 1 - usedLength: NULL - encoding: NSASCIIStringEncoding - options: 0 - range: NSMakeRange(0, 1) - remainingRange: NULL - ]; - if (converted) { - if (!input(in)) { - [NSApp terminate: self]; - } - [self draw]; - [self setWindowTitle]; - } + char in; + BOOL converted = [ + [event characters] + getBytes: &in + maxLength: 1 + usedLength: NULL + encoding: NSASCIIStringEncoding + options: 0 + range: NSMakeRange(0, 1) + remainingRange: NULL + ]; + if (converted) { + if (!input(in)) { + [NSApp terminate: self]; + } + [self draw]; + [self setWindowTitle]; + } } @end @@ -106,57 +106,57 @@ @implementation Delegate - (BOOL) applicationShouldTerminateAfterLastWindowClosed: - (NSApplication *) UNUSED sender { - return YES; + (NSApplication *) UNUSED sender { + return YES; } @end int main(int argc, char *argv[]) { - int error = init(argc, argv); - if (error) return error; - - [NSApplication sharedApplication]; - [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]; - [NSApp setDelegate: [Delegate new]]; - - NSString *name = [[NSProcessInfo processInfo] processName]; - NSMenu *menu = [NSMenu new]; - [ - menu - addItemWithTitle: @"Close Window" - action: @selector(performClose:) - keyEquivalent: @"w" - ]; - [menu addItem: [NSMenuItem separatorItem]]; - [ - menu - addItemWithTitle: [@"Quit " stringByAppendingString: name] - action: @selector(terminate:) - keyEquivalent: @"q" - ]; - NSMenuItem *menuItem = [NSMenuItem new]; - [menuItem setSubmenu: menu]; - [NSApp setMainMenu: [NSMenu new]]; - [[NSApp mainMenu] addItem: menuItem]; - - NSUInteger style = NSTitledWindowMask - | NSClosableWindowMask - | NSMiniaturizableWindowMask - | NSResizableWindowMask; - NSWindow *window = [ - [NSWindow alloc] - initWithContentRect: NSMakeRect(0, 0, 800, 600) - styleMask: style - backing: NSBackingStoreBuffered - defer: YES - ]; - [window center]; - - BufferView *view = [[BufferView alloc] initWithFrame: [window frame]]; - [window setContentView: view]; - [view setWindowTitle]; - - [window makeKeyAndOrderFront: nil]; - [NSApp activateIgnoringOtherApps: YES]; - [NSApp run]; + int error = init(argc, argv); + if (error) return error; + + [NSApplication sharedApplication]; + [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]; + [NSApp setDelegate: [Delegate new]]; + + NSString *name = [[NSProcessInfo processInfo] processName]; + NSMenu *menu = [NSMenu new]; + [ + menu + addItemWithTitle: @"Close Window" + action: @selector(performClose:) + keyEquivalent: @"w" + ]; + [menu addItem: [NSMenuItem separatorItem]]; + [ + menu + addItemWithTitle: [@"Quit " stringByAppendingString: name] + action: @selector(terminate:) + keyEquivalent: @"q" + ]; + NSMenuItem *menuItem = [NSMenuItem new]; + [menuItem setSubmenu: menu]; + [NSApp setMainMenu: [NSMenu new]]; + [[NSApp mainMenu] addItem: menuItem]; + + NSUInteger style = NSTitledWindowMask + | NSClosableWindowMask + | NSMiniaturizableWindowMask + | NSResizableWindowMask; + NSWindow *window = [ + [NSWindow alloc] + initWithContentRect: NSMakeRect(0, 0, 800, 600) + styleMask: style + backing: NSBackingStoreBuffered + defer: YES + ]; + [window center]; + + BufferView *view = [[BufferView alloc] initWithFrame: [window frame]]; + [window setContentView: view]; + [view setWindowTitle]; + + [window makeKeyAndOrderFront: nil]; + [NSApp activateIgnoringOtherApps: YES]; + [NSApp run]; } diff --git a/bin/gfx/fb.c b/bin/gfx/fb.c index 94a3245e..7ee5fea1 100644 --- a/bin/gfx/fb.c +++ b/bin/gfx/fb.c @@ -32,56 +32,56 @@ static struct termios saveTerm; static void restoreTerm(void) { - tcsetattr(STDERR_FILENO, TCSADRAIN, &saveTerm); + tcsetattr(STDERR_FILENO, TCSADRAIN, &saveTerm); } int main(int argc, char *argv[]) { - int error; + int error; - error = init(argc, argv); - if (error) return error; + error = init(argc, argv); + if (error) return error; - const char *path = getenv("FRAMEBUFFER"); - if (!path) path = "/dev/fb0"; + const char *path = getenv("FRAMEBUFFER"); + if (!path) path = "/dev/fb0"; - int fb = open(path, O_RDWR); - if (fb < 0) err(EX_OSFILE, "%s", path); + int fb = open(path, O_RDWR); + if (fb < 0) err(EX_OSFILE, "%s", path); - struct fb_var_screeninfo info; - error = ioctl(fb, FBIOGET_VSCREENINFO, &info); - if (error) err(EX_IOERR, "%s", path); + struct fb_var_screeninfo info; + error = ioctl(fb, FBIOGET_VSCREENINFO, &info); + if (error) err(EX_IOERR, "%s", path); - size_t size = 4 * info.xres * info.yres; - uint32_t *buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); - if (buf == MAP_FAILED) err(EX_IOERR, "%s", path); + size_t size = 4 * info.xres * info.yres; + uint32_t *buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); + if (buf == MAP_FAILED) err(EX_IOERR, "%s", path); - error = tcgetattr(STDERR_FILENO, &saveTerm); - if (error) err(EX_IOERR, "tcgetattr"); - atexit(restoreTerm); + error = tcgetattr(STDERR_FILENO, &saveTerm); + if (error) err(EX_IOERR, "tcgetattr"); + atexit(restoreTerm); - struct termios term = saveTerm; - term.c_lflag &= ~(ICANON | ECHO); - error = tcsetattr(STDERR_FILENO, TCSADRAIN, &term); - if (error) err(EX_IOERR, "tcsetattr"); + struct termios term = saveTerm; + term.c_lflag &= ~(ICANON | ECHO); + error = tcsetattr(STDERR_FILENO, TCSADRAIN, &term); + if (error) err(EX_IOERR, "tcsetattr"); - uint32_t saveBg = buf[0]; + uint32_t saveBg = buf[0]; - uint32_t back[info.xres * info.yres]; - for (;;) { - draw(back, info.xres, info.yres); - memcpy(buf, back, size); + uint32_t back[info.xres * info.yres]; + for (;;) { + draw(back, info.xres, info.yres); + memcpy(buf, back, size); - char in; - ssize_t len = read(STDERR_FILENO, &in, 1); - if (len < 0) err(EX_IOERR, "read"); - if (!len) return EX_DATAERR; + char in; + ssize_t len = read(STDERR_FILENO, &in, 1); + if (len < 0) err(EX_IOERR, "read"); + if (!len) return EX_DATAERR; - if (!input(in)) { - for (uint32_t i = 0; i < info.xres * info.yres; ++i) { - buf[i] = saveBg; - } - fprintf(stderr, "%s\n", status()); - return EX_OK; - } - } + if (!input(in)) { + for (uint32_t i = 0; i < info.xres * info.yres; ++i) { + buf[i] = saveBg; + } + fprintf(stderr, "%s\n", status()); + return EX_OK; + } + } } diff --git a/bin/gfx/none.c b/bin/gfx/none.c index 6decb24b..eb06d285 100644 --- a/bin/gfx/none.c +++ b/bin/gfx/none.c @@ -20,5 +20,5 @@ #include "gfx.h" int main() { - errx(EX_CONFIG, "no gfx frontend"); + errx(EX_CONFIG, "no gfx frontend"); } diff --git a/bin/gfx/x11.c b/bin/gfx/x11.c index c1e6babd..95f08949 100644 --- a/bin/gfx/x11.c +++ b/bin/gfx/x11.c @@ -40,96 +40,96 @@ static size_t pixmapHeight; static Pixmap pixmap; static void createWindow(void) { - display = XOpenDisplay(NULL); - if (!display) errx(EX_UNAVAILABLE, "XOpenDisplay: %s", XDisplayName(NULL)); + display = XOpenDisplay(NULL); + if (!display) errx(EX_UNAVAILABLE, "XOpenDisplay: %s", XDisplayName(NULL)); - Window root = DefaultRootWindow(display); - window = XCreateSimpleWindow(display, root, 0, 0, width, height, 0, 0, 0); + Window root = DefaultRootWindow(display); + window = XCreateSimpleWindow(display, root, 0, 0, width, height, 0, 0, 0); - WM_DELETE_WINDOW = XInternAtom(display, "WM_DELETE_WINDOW", false); - XSetWMProtocols(display, window, &WM_DELETE_WINDOW, 1); + WM_DELETE_WINDOW = XInternAtom(display, "WM_DELETE_WINDOW", false); + XSetWMProtocols(display, window, &WM_DELETE_WINDOW, 1); - windowGc = XCreateGC(display, window, 0, NULL); + windowGc = XCreateGC(display, window, 0, NULL); - image = XCreateImage(display, NULL, 24, ZPixmap, 0, NULL, width, height, 32, 0); + image = XCreateImage(display, NULL, 24, ZPixmap, 0, NULL, width, height, 32, 0); } static void resizePixmap(void) { - size_t newSize = 4 * width * height; - if (newSize > bufSize) { - bufSize = newSize; - free(buf); - buf = malloc(bufSize); - if (!buf) err(EX_OSERR, "malloc(%zu)", bufSize); - } - - image->data = (char *)buf; - image->width = width; - image->height = height; - image->bytes_per_line = 4 * width; - - if (width > pixmapWidth || height > pixmapHeight) { - pixmapWidth = width; - pixmapHeight = height; - if (pixmap) XFreePixmap(display, pixmap); - pixmap = XCreatePixmap(display, window, pixmapWidth, pixmapHeight, 24); - } + size_t newSize = 4 * width * height; + if (newSize > bufSize) { + bufSize = newSize; + free(buf); + buf = malloc(bufSize); + if (!buf) err(EX_OSERR, "malloc(%zu)", bufSize); + } + + image->data = (char *)buf; + image->width = width; + image->height = height; + image->bytes_per_line = 4 * width; + + if (width > pixmapWidth || height > pixmapHeight) { + pixmapWidth = width; + pixmapHeight = height; + if (pixmap) XFreePixmap(display, pixmap); + pixmap = XCreatePixmap(display, window, pixmapWidth, pixmapHeight, 24); + } } static void drawWindow(void) { - draw(buf, width, height); - XPutImage(display, pixmap, windowGc, image, 0, 0, 0, 0, width, height); - XCopyArea(display, pixmap, window, windowGc, 0, 0, width, height, 0, 0); + draw(buf, width, height); + XPutImage(display, pixmap, windowGc, image, 0, 0, 0, 0, width, height); + XCopyArea(display, pixmap, window, windowGc, 0, 0, width, height, 0, 0); } int main(int argc, char *argv[]) { - int error = init(argc, argv); - if (error) return error; - - createWindow(); - resizePixmap(); - drawWindow(); - - XStoreName(display, window, status()); - XMapWindow(display, window); - - XEvent event; - XSelectInput(display, window, ExposureMask | StructureNotifyMask | KeyPressMask); - for (;;) { - XNextEvent(display, &event); - - switch (event.type) { - case KeyPress: { - XKeyEvent key = event.xkey; - KeySym sym = XLookupKeysym(&key, key.state & ShiftMask); - if (sym > 0x80) break; - if (!input(sym)) return EX_OK; - drawWindow(); - XStoreName(display, window, status()); - } break; - - case ConfigureNotify: { - XConfigureEvent configure = event.xconfigure; - width = configure.width; - height = configure.height; - resizePixmap(); - drawWindow(); - } break; - - case Expose: { - XExposeEvent expose = event.xexpose; - XCopyArea( - display, pixmap, window, windowGc, - expose.x, expose.y, - expose.width, expose.height, - expose.x, expose.y - ); - } break; - - case ClientMessage: { - XClientMessageEvent client = event.xclient; - if ((Atom)client.data.l[0] == WM_DELETE_WINDOW) return EX_OK; - } break; - } - } + int error = init(argc, argv); + if (error) return error; + + createWindow(); + resizePixmap(); + drawWindow(); + + XStoreName(display, window, status()); + XMapWindow(display, window); + + XEvent event; + XSelectInput(display, window, ExposureMask | StructureNotifyMask | KeyPressMask); + for (;;) { + XNextEvent(display, &event); + + switch (event.type) { + case KeyPress: { + XKeyEvent key = event.xkey; + KeySym sym = XLookupKeysym(&key, key.state & ShiftMask); + if (sym > 0x80) break; + if (!input(sym)) return EX_OK; + drawWindow(); + XStoreName(display, window, status()); + } break; + + case ConfigureNotify: { + XConfigureEvent configure = event.xconfigure; + width = configure.width; + height = configure.height; + resizePixmap(); + drawWindow(); + } break; + + case Expose: { + XExposeEvent expose = event.xexpose; + XCopyArea( + display, pixmap, window, windowGc, + expose.x, expose.y, + expose.width, expose.height, + expose.x, expose.y + ); + } break; + + case ClientMessage: { + XClientMessageEvent client = event.xclient; + if ((Atom)client.data.l[0] == WM_DELETE_WINDOW) return EX_OK; + } break; + } + } } -- cgit 1.4.1