int main(int argc, const char* argv[]) { for (int i=0; i < argc; ++i) { printf("%s\n", argv[i]); } char* url = NULL; if (argc >= 2) { url = (char*)argv[1]; } else { url = "localhost:8082"; } curl_global_init(CURL_GLOBAL_SSL); initscr(); if (!has_colors()) { puts("terminal doesn't support colors\n"); } start_color(); Colors_init(); Colors_set(Colors_Default); // init ncurses io settings cbreak(); // allow ctrl-Z, ctrl-C and other default keys noecho(); keypad(stdscr, TRUE); printw("%s fetching lists...\n", url); refresh(); struct TvShows shows; TvShows_init(&shows); TvShows_fetch(&shows, url); refresh(); bool quit = false; do { int c = getch(); if (c == 27) { quit = true; } TvShows_handleInput(&shows, c); } while (!quit); TvShows_destroyMembers(&shows); endwin(); return 0; }
/* * The following function initializes a toplevel window. * It returns 0 if the initialization was successful, * or -1 if it couldn't initialize the double buffering routine. */ int Init_top(void) { int top_x, top_y; int i; int x, y; unsigned w, h; unsigned long values; int top_flags; XGCValues xgc; XSetWindowAttributes sattr; unsigned long mask; if (topWindow) fatal("Init_top called twice"); if (Colors_init() == -1) return -1; radarDrawRectanglePtr = XFillRectangle; /* * Get toplevel geometry. */ top_flags = 0; if (geometry != NULL && geometry[0] != '\0') mask = XParseGeometry(geometry, &x, &y, &w, &h); else mask = 0; if ((mask & WidthValue) != 0) { top_width = w; top_flags |= USSize; } else { top_width = DEF_TOP_WIDTH; top_flags |= PSize; } LIMIT(top_width, MIN_TOP_WIDTH, MAX_TOP_WIDTH); if ((mask & HeightValue) != 0) { top_height = h; top_flags |= USSize; } else { top_height = DEF_TOP_HEIGHT; top_flags |= PSize; } LIMIT(top_height, MIN_TOP_HEIGHT, MAX_TOP_HEIGHT); if ((mask & XValue) != 0) { if ((mask & XNegative) != 0) top_x = DisplayWidth(dpy, DefaultScreen(dpy)) - top_width + x; else top_x = x; top_flags |= USPosition; } else { top_x = (DisplayWidth(dpy, DefaultScreen(dpy)) - top_width) /2; top_flags |= PPosition; } if ((mask & YValue) != 0) { if ((mask & YNegative) != 0) top_y = DisplayHeight(dpy, DefaultScreen(dpy)) - top_height + y; else top_y = y; top_flags |= USPosition; } else { top_y = (DisplayHeight(dpy, DefaultScreen(dpy)) - top_height) /2; top_flags |= PPosition; } if (geometry != NULL) { free(geometry); geometry = NULL; } /* * Create toplevel window (we need this first so that we can create GCs) */ mask = 0; /*old debug: sattr.background_pixel = colors[WHITE].pixel;*/ sattr.background_pixel = colors[BLACK].pixel; mask |= CWBackPixel; sattr.border_pixel = colors[WHITE].pixel; mask |= CWBorderPixel; if (colormap != 0) { sattr.colormap = colormap; mask |= CWColormap; } if (ignoreWindowManager) { sattr.override_redirect = True; mask |= CWOverrideRedirect; } topWindow = XCreateWindow(dpy, DefaultRootWindow(dpy), top_x, top_y, top_width, top_height, 0, (int)dispDepth, InputOutput, visual, mask, &sattr); XSelectInput(dpy, topWindow, KeyPressMask | KeyReleaseMask | FocusChangeMask | StructureNotifyMask); Init_disp_prop(dpy, topWindow, top_width, top_height, top_x, top_y, top_flags); if (kdpy) { int scr = DefaultScreen(kdpy); keyboardWindow = XCreateSimpleWindow(kdpy, DefaultRootWindow(kdpy), top_x, top_y, top_width, top_height, 0, 0, BlackPixel(dpy, scr)); XSelectInput(kdpy, keyboardWindow, KeyPressMask | KeyReleaseMask | FocusChangeMask); Init_disp_prop(kdpy, keyboardWindow, top_width, top_height, top_x, top_y, top_flags); } /* * Create item bitmaps */ for (i = 0; i < NUM_ITEMS; i++) itemBitmaps[i] = XCreateBitmapFromData(dpy, topWindow, (char *)itemBitmapData[i].data, ITEM_SIZE, ITEM_SIZE); /* * Creates and initializes the graphic contexts. */ xgc.line_width = 0; xgc.line_style = LineSolid; xgc.cap_style = CapButt; xgc.join_style = JoinMiter; /* I think this is fastest, is it? */ xgc.graphics_exposures = False; values = GCLineWidth|GCLineStyle|GCCapStyle|GCJoinStyle|GCGraphicsExposures; messageGC = XCreateGC(dpy, topWindow, values, &xgc); radarGC = XCreateGC(dpy, topWindow, values, &xgc); buttonGC = XCreateGC(dpy, topWindow, values, &xgc); scoreListGC = XCreateGC(dpy, topWindow, values, &xgc); textGC = XCreateGC(dpy, topWindow, values, &xgc); talkGC = XCreateGC(dpy, topWindow, values, &xgc); motdGC = XCreateGC(dpy, topWindow, values, &xgc); gameGC = XCreateGC(dpy, topWindow, values, &xgc); XSetBackground(dpy, gameGC, colors[BLACK].pixel); /* * Set fonts */ gameFont = Set_font(dpy, gameGC, gameFontName, "gameFont"); messageFont = Set_font(dpy, messageGC, messageFontName, "messageFont"); scoreListFont = Set_font(dpy, scoreListGC, scoreListFontName, "scoreListFont"); buttonFont = Set_font(dpy, buttonGC, buttonFontName, "buttonFont"); textFont = Set_font(dpy, textGC, textFontName, "textFont"); talkFont = Set_font(dpy, talkGC, talkFontName, "talkFont"); motdFont = Set_font(dpy, motdGC, motdFontName, "motdFont"); XSetState(dpy, gameGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, radarGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, messageGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, buttonGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, scoreListGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); if (dbuf_state->type == COLOR_SWITCH) XSetPlaneMask(dpy, gameGC, dbuf_state->drawing_planes); return 0; }