virtual void handle_key_event(g_key_event& e) { waitingInputLock.lock(); waitingInput.push_back(g_keyboard::fullKeyInfo(e.info)); lastInput = g_millis(); noInputAvailable = false; waitingInputLock.unlock(); }
void message_test_sender() { g_sleep(1000); klog("starting to send old messages"); for (;;) { g_message message; int c = 4000; auto start = g_millis(); for (int i = 0; i < c; i++) { g_send_msg(message_receiver_tid, &message); } klog("%i took %i ms", c, g_millis() - start); g_sleep(1000); } }
int main() { signal(SIGINT, SIG_IGN); uint32_t idles = 0; uint64_t last = 0; again: uint64_t now = g_millis(); if (now - last > 1000) { last = now; klog("%i idles per second", idles); idles = 0; } ++idles; asm("hlt"); goto again; }
virtual void handle_focus_changed(bool now_focused) { focused = now_focused; paint_uptodate = false; lastInput = g_millis(); }
void gui_screen_t::paint() { g_create_thread((void*) blinkCursorThread); int padding = 5; while (true) { auto windowBounds = window->getBounds(); canvas->setBounds(g_rectangle(0, 0, windowBounds.width, windowBounds.height)); auto cr = getGraphics(); if (cr == 0) { g_sleep(100); continue; } // clear cairo_save(cr); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_restore(cr); // relayout text g_text_layouter::getInstance()->layout(cr, output.c_str(), font, 14, g_rectangle(padding, padding, windowBounds.width - 2 * padding - 20, windowBounds.height - 2 * padding), g_text_alignment::LEFT, viewModel, true); // check which is the lowest-down-the-screen character int highesty = 0; for (g_positioned_glyph& g : viewModel->positions) { int ypos = g.position.y - g.glyph->y; if (ypos > highesty) { highesty = ypos; } } // calculate limit int yLimit = windowBounds.height - 60; int yOffset = 0; if (highesty > yLimit) { yOffset = yLimit - highesty; } // paint characters g_point last; cairo_set_source_rgba(cr, 1, 1, 1, 1); for (g_positioned_glyph& g : viewModel->positions) { last = g.position; cairo_save(cr); cairo_translate(cr, g.position.x - g.glyph->x, yOffset + g.position.y - g.glyph->y); cairo_glyph_path(cr, g.glyph, g.glyph_count); cairo_fill(cr); cairo_restore(cr); } // paint cursor if (focused) { if ((g_millis() - lastInput < 300) || cursorBlink) { cairo_save(cr); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_rectangle(cr, last.x + 10, yOffset + last.y - 12, 8, 14); cairo_fill(cr); cairo_restore(cr); } } canvas->blit(g_rectangle(0, 0, bufferSize.width, bufferSize.height)); paint_uptodate = true; g_atomic_block(&paint_uptodate); } }