c/main: Tidy target code [NFC]

This commit is contained in:
Jakob Bornecrantz 2024-01-07 12:24:35 +00:00 committed by Simon Zeni
parent 7e7e011b1b
commit 4a2eebdc69
4 changed files with 60 additions and 18 deletions

View file

@ -144,18 +144,31 @@ append_nvidia_entry_on_match(struct comp_window_direct_nvidia *w,
{
unsigned long wl_entry_length = strlen(wl_entry);
unsigned long disp_entry_length = strlen(disp->displayName);
if (disp_entry_length < wl_entry_length)
return false;
if (strncmp(wl_entry, disp->displayName, wl_entry_length) != 0)
// If the entry is shorter then it will never match.
if (disp_entry_length < wl_entry_length) {
return false;
}
// we have a match with this allowlist entry.
// We only check the first part of the string, extra characters ignored.
if (strncmp(wl_entry, disp->displayName, wl_entry_length) != 0) {
return false;
}
/*
* We have a match with this allow list entry.
*/
// Make the compositor use this size.
w->base.base.c->settings.preferred.width = disp->physicalResolution.width;
w->base.base.c->settings.preferred.height = disp->physicalResolution.height;
struct comp_window_direct_nvidia_display d = {.name = U_TYPED_ARRAY_CALLOC(char, disp_entry_length + 1),
.display_properties = *disp,
.display = disp->display};
// Create the entry.
struct comp_window_direct_nvidia_display d = {
.name = U_TYPED_ARRAY_CALLOC(char, disp_entry_length + 1),
.display_properties = *disp,
.display = disp->display,
};
memcpy(d.name, disp->displayName, disp_entry_length);
d.name[disp_entry_length] = '\0';

View file

@ -149,8 +149,9 @@ comp_window_direct_randr_destroy(struct comp_target *ct)
free(d->name);
}
if (w_direct->displays != NULL)
if (w_direct->displays != NULL) {
free(w_direct->displays);
}
if (w_direct->dpy) {
XCloseDisplay(w_direct->dpy);
@ -220,6 +221,8 @@ comp_window_direct_randr_init(struct comp_target *ct)
}
struct comp_window_direct_randr_display *d = comp_window_direct_randr_current_display(w_direct);
// Make the compositor use this size.
ct->c->settings.preferred.width = d->primary_mode.width;
ct->c->settings.preferred.height = d->primary_mode.height;
@ -230,11 +233,13 @@ static struct comp_window_direct_randr_display *
comp_window_direct_randr_current_display(struct comp_window_direct_randr *w)
{
int index = w->base.base.c->settings.display;
if (index == -1)
if (index == -1) {
index = 0;
}
if (w->display_count <= (uint32_t)index)
if (w->display_count <= (uint32_t)index) {
return NULL;
}
return &w->displays[index];
}
@ -315,12 +320,15 @@ append_randr_display(struct comp_window_direct_randr *w,
int n = xcb_randr_get_screen_resources_modes_length(resources_reply);
xcb_randr_mode_info_t *mode_info = NULL;
for (int i = 0; i < n; i++)
if (mode_infos[i].id == output_modes[0])
for (int i = 0; i < n; i++) {
if (mode_infos[i].id == output_modes[0]) {
mode_info = &mode_infos[i];
}
}
if (mode_info == NULL)
if (mode_info == NULL) {
COMP_ERROR(w->base.base.c, "No mode with id %d found??", output_modes[0]);
}
struct comp_window_direct_randr_display d = {

View file

@ -117,8 +117,9 @@ comp_window_vk_display_destroy(struct comp_target *ct)
d->display = VK_NULL_HANDLE;
}
if (w_direct->displays != NULL)
if (w_direct->displays != NULL) {
free(w_direct->displays);
}
free(ct);
}
@ -126,9 +127,15 @@ comp_window_vk_display_destroy(struct comp_target *ct)
static bool
append_vk_display_entry(struct comp_window_vk_display *w, struct VkDisplayPropertiesKHR *disp)
{
// Make the compositor use this size.
w->base.base.c->settings.preferred.width = disp->physicalResolution.width;
w->base.base.c->settings.preferred.height = disp->physicalResolution.height;
struct vk_display d = {.display_properties = *disp, .display = disp->display};
// Create the entry.
struct vk_display d = {
.display_properties = *disp,
.display = disp->display,
};
w->display_count += 1;

View file

@ -246,12 +246,14 @@ comp_window_xcb_init(struct comp_target *ct)
}
}
// We can now create the window.
comp_window_xcb_create_window(w_xcb, ct->c->settings.preferred.width, ct->c->settings.preferred.height);
comp_window_xcb_connect_delete_event(w_xcb);
if (ct->c->settings.fullscreen)
if (ct->c->settings.fullscreen) {
comp_window_xcb_set_full_screen(w_xcb);
}
xcb_map_window(w_xcb->connection, w_xcb->window);
@ -306,8 +308,20 @@ comp_window_xcb_create_window(struct comp_window_xcb *w, uint32_t width, uint32_
uint32_t value_list = XCB_EVENT_MASK_STRUCTURE_NOTIFY;
xcb_create_window(w->connection, XCB_COPY_FROM_PARENT, w->window, w->screen->root, x, y, width, height, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, w->screen->root_visual, XCB_CW_EVENT_MASK, &value_list);
xcb_create_window( //
w->connection, // conn
XCB_COPY_FROM_PARENT, // depth
w->window, // wid
w->screen->root, // parent
x, // x
y, // y
width, // width
height, // height
0, // border_width
XCB_WINDOW_CLASS_INPUT_OUTPUT, // _class
w->screen->root_visual, // visual
XCB_CW_EVENT_MASK, // value_mask
&value_list); // value_list
}
static void