Skip to content

Commit

Permalink
Merge branch 'update_api'
Browse files Browse the repository at this point in the history
  • Loading branch information
esnosy committed Oct 3, 2023
2 parents 39401b6 + 3d54873 commit d8ad68a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
2 changes: 2 additions & 0 deletions include/minimal_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ bool minimal_window_process_events();

void minimal_window_draw_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b);

void minimal_window_request_update();

#endif // MINIMAL_WINDOW_H
7 changes: 7 additions & 0 deletions wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,10 @@ bool minimal_window_process_events() {
return false;
}
}

void minimal_window_request_update() {
wl_surface_frame(global_client_state.wl_surface);
wl_surface_attach(global_client_state.wl_surface, global_wl_buffer, 0, 0);
wl_surface_damage_buffer(global_client_state.wl_surface, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_commit(global_client_state.wl_surface);
}
49 changes: 26 additions & 23 deletions win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
static BITMAPINFO bitmap_info;
static int global_width, global_height;
static void *bitmap_memory;
static HWND global_hwnd;

static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

Expand Down Expand Up @@ -50,22 +51,22 @@ void minimal_window_create_fixed_size_window(int width, int height) {
// Create the window
RECT window_rect = {0, 0, width, height};
AdjustWindowRect(&window_rect, FIXED_SIZE_WINDOW_STYLE, FALSE);
HWND hwnd = CreateWindowEx(0, // Optional window styles.
CLASS_NAME, // Window class
L"Minimal Window", // Window text
FIXED_SIZE_WINDOW_STYLE, // Window style

// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top,

NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
global_hwnd = CreateWindowEx(0, // Optional window styles.
CLASS_NAME, // Window class
L"Minimal Window", // Window text
FIXED_SIZE_WINDOW_STYLE, // Window style

// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top,

NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);

if (hwnd == NULL) {
if (global_hwnd == NULL) {
return;
}

Expand All @@ -83,7 +84,7 @@ void minimal_window_create_fixed_size_window(int width, int height) {
bitmap_info.bmiHeader.biBitCount = 32;
bitmap_info.bmiHeader.biCompression = BI_RGB;

ShowWindow(hwnd, SW_NORMAL);
ShowWindow(global_hwnd, SW_NORMAL);
}

bool minimal_window_process_events() {
Expand All @@ -103,17 +104,19 @@ static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
PostQuitMessage(0);
return 0;

case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// All painting occurs here, between BeginPaint and EndPaint
StretchDIBits(hdc, 0, 0, global_width, global_height, 0, 0, global_width, global_height, bitmap_memory,
&bitmap_info, DIB_RGB_COLORS, SRCCOPY);
EndPaint(hwnd, &ps);
}
case WM_PAINT:
// We must handle WM_PAINT like this, otherwise drawing outside event handler will not work
// TODO: is this bad? :/
return 0;

default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}

void minimal_window_request_update() {
HDC hdc = GetDC(global_hwnd);
StretchDIBits(hdc, 0, 0, global_width, global_height, 0, 0, global_width, global_height, bitmap_memory, &bitmap_info,
DIB_RGB_COLORS, SRCCOPY);
ReleaseDC(global_hwnd, hdc);
}
12 changes: 8 additions & 4 deletions x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ bool minimal_window_process_events() {
return false;

case Expose:
/* draw the window */
// XFillRectangle(display, window, DefaultGC(display, screen), 0, 0, global_width, global_height);
XPutImage(display, window, DefaultGC(display, screen), image, 0, 0, 0, 0, global_width, global_height);

/* NO DEFAULT */
return true;
}

return true;
}

void minimal_window_request_update() {
XEvent event;
event.type = Expose;
event.xexpose.window = window;
XSendEvent(display, window, False, ExposureMask, &event);
}

0 comments on commit d8ad68a

Please sign in to comment.