diff --git a/client/X11/keyboard_x11.c b/client/X11/keyboard_x11.c index 73e11aa64..86a6f076e 100644 --- a/client/X11/keyboard_x11.c +++ b/client/X11/keyboard_x11.c @@ -27,6 +27,7 @@ #include "xf_debug.h" #include "keyboard_x11.h" #include "xkb_layout_ids.h" +#include "xf_utils.h" static BOOL parse_xkb_rule_names(char* xkb_rule, unsigned long num_bytes, char** layout, char** variant) @@ -84,7 +85,8 @@ static BOOL parse_xkb_rule_names(char* xkb_rule, unsigned long num_bytes, char** return TRUE; } -static DWORD kbd_layout_id_from_x_property(Display* display, Window root, char* property_name) +static DWORD kbd_layout_id_from_x_property(wLog* log, Display* display, Window root, + char* property_name) { char* layout = NULL; char* variant = NULL; @@ -99,8 +101,9 @@ static DWORD kbd_layout_id_from_x_property(Display* display, Window root, char* if (property == None) return 0; - if (XGetWindowProperty(display, root, property, 0, 1024, False, XA_STRING, &type, &item_size, - &items, &unread_items, (unsigned char**)&rule) != Success) + if (LogDynAndXGetWindowProperty(log, display, root, property, 0, 1024, False, XA_STRING, &type, + &item_size, &items, &unread_items, + (unsigned char**)&rule) != Success) return 0; if (type != XA_STRING || item_size != 8 || unread_items != 0) @@ -119,7 +122,7 @@ static DWORD kbd_layout_id_from_x_property(Display* display, Window root, char* return layout_id; } -int xf_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId) +int xf_detect_keyboard_layout_from_xkb(wLog* log, DWORD* keyboardLayoutId) { Display* display = XOpenDisplay(NULL); @@ -131,14 +134,14 @@ int xf_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId) return 0; /* We start by looking for _XKB_RULES_NAMES_BACKUP which appears to be used by libxklavier */ - DWORD id = kbd_layout_id_from_x_property(display, root, "_XKB_RULES_NAMES_BACKUP"); + DWORD id = kbd_layout_id_from_x_property(log, display, root, "_XKB_RULES_NAMES_BACKUP"); if (0 == id) - id = kbd_layout_id_from_x_property(display, root, "_XKB_RULES_NAMES"); + id = kbd_layout_id_from_x_property(log, display, root, "_XKB_RULES_NAMES"); if (0 != id) *keyboardLayoutId = id; - XCloseDisplay(display); + LogDynAndXCloseDisplay(log, display); return (int)id; } diff --git a/client/X11/keyboard_x11.h b/client/X11/keyboard_x11.h index 1666404d3..1b0a65e9b 100644 --- a/client/X11/keyboard_x11.h +++ b/client/X11/keyboard_x11.h @@ -19,6 +19,7 @@ #pragma once +#include #include -int xf_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId); +int xf_detect_keyboard_layout_from_xkb(wLog* log, DWORD* keyboardLayoutId); diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index dc3e436aa..2a56d0196 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -204,8 +204,8 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) const double yScalingFactor = 1.0 * freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) / (double)xfc->scaledHeight; - XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, 0); + LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid); + LogDynAndXSetForeground(xfc->log, xfc->display, xfc->gc, 0); /* Black out possible space between desktop and window borders */ { XRectangle box1 = { 0, 0, WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->width), @@ -221,11 +221,11 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) if (XSubtractRegion(reg1, reg2, reg1) && !XEmptyRegion(reg1)) { - XSetRegion(xfc->display, xfc->gc, reg1); - XFillRectangle(xfc->display, xfc->window->handle, xfc->gc, 0, 0, - WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->width), - WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->height)); - XSetClipMask(xfc->display, xfc->gc, None); + LogDynAndXSetRegion(xfc->log, xfc->display, xfc->gc, reg1); + LogDynAndXFillRectangle(xfc->log, xfc->display, xfc->window->handle, xfc->gc, 0, 0, + WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->width), + WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->height)); + LogDynAndXSetClipMask(xfc->log, xfc->display, xfc->gc, None); } XDestroyRegion(reg1); @@ -347,14 +347,14 @@ static BOOL xf_desktop_resize(rdpContext* context) if (xfc->primary) { BOOL same = (xfc->primary == xfc->drawing) ? TRUE : FALSE; - XFreePixmap(xfc->display, xfc->primary); + LogDynAndXFreePixmap(xfc->log, xfc->display, xfc->primary); WINPR_ASSERT(xfc->depth != 0); - if (!(xfc->primary = - XCreatePixmap(xfc->display, xfc->drawable, - freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), - freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), - WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth)))) + if (!(xfc->primary = LogDynAndXCreatePixmap( + xfc->log, xfc->display, xfc->drawable, + freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), + freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), + WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth)))) return FALSE; if (same) @@ -397,12 +397,12 @@ static BOOL xf_desktop_resize(rdpContext* context) int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)); } - XSetFunction(xfc->display, xfc->gc, GXcopy); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, 0); - XFillRectangle(xfc->display, xfc->drawable, xfc->gc, 0, 0, - freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), - freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)); + LogDynAndXSetFunction(xfc->log, xfc->display, xfc->gc, GXcopy); + LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid); + LogDynAndXSetForeground(xfc->log, xfc->display, xfc->gc, 0); + LogDynAndXFillRectangle(xfc->log, xfc->display, xfc->drawable, xfc->gc, 0, 0, + freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), + freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)); } return TRUE; @@ -501,9 +501,10 @@ static BOOL xf_sw_desktop_resize(rdpContext* context) } WINPR_ASSERT(xfc->depth != 0); - if (!(xfc->image = XCreateImage( - xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), ZPixmap, 0, - (char*)gdi->primary_buffer, WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width), + if (!(xfc->image = LogDynAndXCreateImage( + xfc->log, xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), + ZPixmap, 0, (char*)gdi->primary_buffer, + WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width), WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height), xfc->scanline_pad, WINPR_ASSERTING_INT_CAST(int, gdi->stride)))) { @@ -693,29 +694,32 @@ BOOL xf_create_window(xfContext* xfc) } if (!xfc->gc) - xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv); + xfc->gc = + LogDynAndXCreateGC(xfc->log, xfc->display, xfc->drawable, GCGraphicsExposures, &gcv); WINPR_ASSERT(xfc->depth != 0); if (!xfc->primary) - xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, - freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), - freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), - WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth)); + xfc->primary = + LogDynAndXCreatePixmap(xfc->log, xfc->display, xfc->drawable, + freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), + freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), + WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth)); xfc->drawing = xfc->primary; if (!xfc->bitmap_mono) - xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1); + xfc->bitmap_mono = LogDynAndXCreatePixmap(xfc->log, xfc->display, xfc->drawable, 8, 8, 1); if (!xfc->gc_mono) - xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv); + xfc->gc_mono = + LogDynAndXCreateGC(xfc->log, xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv); - XSetFunction(xfc->display, xfc->gc, GXcopy); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen)); - XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0, - freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), - freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)); + LogDynAndXSetFunction(xfc->log, xfc->display, xfc->gc, GXcopy); + LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid); + LogDynAndXSetForeground(xfc->log, xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen)); + LogDynAndXFillRectangle(xfc->log, xfc->display, xfc->primary, xfc->gc, 0, 0, + freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), + freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)); LogDynAndXFlush(xfc->log, xfc->display); return TRUE; @@ -731,12 +735,12 @@ BOOL xf_create_image(xfContext* xfc) WINPR_ASSERT(cgdi); WINPR_ASSERT(xfc->depth != 0); - xfc->image = - XCreateImage(xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), - ZPixmap, 0, (char*)cgdi->primary_buffer, - freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), - freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), - xfc->scanline_pad, WINPR_ASSERTING_INT_CAST(int, cgdi->stride)); + xfc->image = LogDynAndXCreateImage( + xfc->log, xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), + ZPixmap, 0, (char*)cgdi->primary_buffer, + freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth), + freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), xfc->scanline_pad, + WINPR_ASSERTING_INT_CAST(int, cgdi->stride)); xfc->image->byte_order = LSBFirst; xfc->image->bitmap_bit_order = LSBFirst; } @@ -768,25 +772,25 @@ static void xf_window_free(xfContext* xfc) if (xfc->bitmap_mono) { - XFreePixmap(xfc->display, xfc->bitmap_mono); + LogDynAndXFreePixmap(xfc->log, xfc->display, xfc->bitmap_mono); xfc->bitmap_mono = 0; } if (xfc->gc_mono) { - XFreeGC(xfc->display, xfc->gc_mono); + LogDynAndXFreeGC(xfc->log, xfc->display, xfc->gc_mono); xfc->gc_mono = 0; } if (xfc->primary) { - XFreePixmap(xfc->display, xfc->primary); + LogDynAndXFreePixmap(xfc->log, xfc->display, xfc->primary); xfc->primary = 0; } if (xfc->gc) { - XFreeGC(xfc->display, xfc->gc); + LogDynAndXFreeGC(xfc->log, xfc->display, xfc->gc); xfc->gc = 0; } } @@ -1833,7 +1837,7 @@ void xf_teardown_x11(xfContext* xfc) if (xfc->display) { - XCloseDisplay(xfc->display); + LogDynAndXCloseDisplay(xfc->log, xfc->display); xfc->display = NULL; } @@ -1921,9 +1925,9 @@ BOOL xf_setup_x11(xfContext* xfc) unsigned long nitems = 0; unsigned long after = 0; unsigned char* data = NULL; - int status = LogTagAndXGetWindowProperty( - TAG, xfc->display, RootWindowOfScreen(xfc->screen), xfc->NET_SUPPORTED, 0, 1024, False, - XA_ATOM, &actual_type, &actual_format, &nitems, &after, &data); + int status = LogDynAndXGetWindowProperty( + xfc->log, xfc->display, RootWindowOfScreen(xfc->screen), xfc->NET_SUPPORTED, 0, 1024, + False, XA_ATOM, &actual_type, &actual_format, &nitems, &after, &data); if ((status == Success) && (actual_type == XA_ATOM) && (actual_format == 32)) { diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index 401e43db7..4a5293657 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -272,7 +272,7 @@ static BOOL xf_cliprdr_update_owner(xfClipboard* clipboard) if (!clipboard->sync) return FALSE; - Window owner = XGetSelectionOwner(xfc->display, clipboard->clipboard_atom); + Window owner = LogDynAndXGetSelectionOwner(xfc->log, xfc->display, clipboard->clipboard_atom); if (clipboard->owner == owner) return FALSE; @@ -294,7 +294,8 @@ static BOOL xf_cliprdr_is_self_owned(xfClipboard* clipboard) xfc = clipboard->xfc; WINPR_ASSERT(xfc); - return XGetSelectionOwner(xfc->display, clipboard->clipboard_atom) == xfc->drawable; + return LogDynAndXGetSelectionOwner(xfc->log, xfc->display, clipboard->clipboard_atom) == + xfc->drawable; } static void xf_cliprdr_set_raw_transfer_enabled(xfClipboard* clipboard, BOOL enabled) @@ -306,7 +307,7 @@ static void xf_cliprdr_set_raw_transfer_enabled(xfClipboard* clipboard, BOOL ena xfc = clipboard->xfc; WINPR_ASSERT(xfc); - LogTagAndXChangeProperty(TAG, xfc->display, xfc->drawable, clipboard->raw_transfer_atom, + LogDynAndXChangeProperty(xfc->log, xfc->display, xfc->drawable, clipboard->raw_transfer_atom, XA_INTEGER, 32, PropModeReplace, (const BYTE*)&data, 1); } @@ -327,13 +328,13 @@ static BOOL xf_cliprdr_is_raw_transfer_available(xfClipboard* clipboard) xfc = clipboard->xfc; WINPR_ASSERT(xfc); - owner = XGetSelectionOwner(xfc->display, clipboard->clipboard_atom); + owner = LogDynAndXGetSelectionOwner(xfc->log, xfc->display, clipboard->clipboard_atom); if (owner != None) { - result = LogTagAndXGetWindowProperty(TAG, xfc->display, owner, clipboard->raw_transfer_atom, - 0, 4, 0, XA_INTEGER, &type, &format, &length, - &bytes_left, (BYTE**)&data); + result = LogDynAndXGetWindowProperty(xfc->log, xfc->display, owner, + clipboard->raw_transfer_atom, 0, 4, 0, XA_INTEGER, + &type, &format, &length, &bytes_left, (BYTE**)&data); } if (data) @@ -638,10 +639,10 @@ static CLIPRDR_FORMAT* xf_cliprdr_get_raw_server_formats(xfClipboard* clipboard, *numFormats = 0; - Window owner = XGetSelectionOwner(xfc->display, clipboard->clipboard_atom); - LogTagAndXGetWindowProperty(TAG, xfc->display, owner, clipboard->raw_format_list_atom, 0, 4096, - False, clipboard->raw_format_list_atom, &type, &format, &length, - &remaining, &data); + Window owner = LogDynAndXGetSelectionOwner(xfc->log, xfc->display, clipboard->clipboard_atom); + LogDynAndXGetWindowProperty(xfc->log, xfc->display, owner, clipboard->raw_format_list_atom, 0, + 4096, False, clipboard->raw_format_list_atom, &type, &format, + &length, &remaining, &data); if (data && length > 0 && format == 8 && type == clipboard->raw_format_list_atom) { @@ -696,8 +697,8 @@ static CLIPRDR_FORMAT* xf_cliprdr_get_formats_from_targets(xfClipboard* clipboar WINPR_ASSERT(xfc); *numFormats = 0; - LogTagAndXGetWindowProperty(TAG, xfc->display, xfc->drawable, clipboard->property_atom, 0, 200, - 0, XA_ATOM, &atom, &format_property, &proplength, &bytes_left, + LogDynAndXGetWindowProperty(xfc->log, xfc->display, xfc->drawable, clipboard->property_atom, 0, + 200, 0, XA_ATOM, &atom, &format_property, &proplength, &bytes_left, &data); if (proplength > 0) @@ -811,13 +812,14 @@ static void xf_cliprdr_provide_server_format_list(xfClipboard* clipboard) { const size_t len = Stream_Length(formats); WINPR_ASSERT(len <= INT32_MAX); - LogTagAndXChangeProperty(TAG, xfc->display, xfc->drawable, clipboard->raw_format_list_atom, - clipboard->raw_format_list_atom, 8, PropModeReplace, - Stream_Buffer(formats), (int)len); + LogDynAndXChangeProperty(xfc->log, xfc->display, xfc->drawable, + clipboard->raw_format_list_atom, clipboard->raw_format_list_atom, + 8, PropModeReplace, Stream_Buffer(formats), (int)len); } else { - LogTagAndXDeleteProperty(TAG, xfc->display, xfc->drawable, clipboard->raw_format_list_atom); + LogDynAndXDeleteProperty(xfc->log, xfc->display, xfc->drawable, + clipboard->raw_format_list_atom); } Stream_Free(formats, TRUE); @@ -1118,8 +1120,8 @@ static BOOL xf_cliprdr_get_requested_data(xfClipboard* clipboard, Atom target) unsigned long length = 0; unsigned long total_bytes = 0; BYTE* property_data = NULL; - const int rc = LogTagAndXGetWindowProperty( - TAG, xfc->display, xfc->drawable, clipboard->property_atom, 0, 0, False, target, &type, + const int rc = LogDynAndXGetWindowProperty( + xfc->log, xfc->display, xfc->drawable, clipboard->property_atom, 0, 0, False, target, &type, &format_property, &length, &total_bytes, &property_data); if (rc != Success) { @@ -1154,8 +1156,8 @@ static BOOL xf_cliprdr_get_requested_data(xfClipboard* clipboard, Atom target) has_data = TRUE; } /* Read incremental data batch */ - else if (LogTagAndXGetWindowProperty( - TAG, xfc->display, xfc->drawable, clipboard->property_atom, 0, + else if (LogDynAndXGetWindowProperty( + xfc->log, xfc->display, xfc->drawable, clipboard->property_atom, 0, WINPR_ASSERTING_INT_CAST(int32_t, total_bytes), False, target, &type, &format_property, &incremental_len, &length, &incremental_data) == Success) { @@ -1167,7 +1169,7 @@ static BOOL xf_cliprdr_get_requested_data(xfClipboard* clipboard, Atom target) XFree(incremental_data); } - LogTagAndXDeleteProperty(TAG, xfc->display, xfc->drawable, clipboard->property_atom); + LogDynAndXDeleteProperty(xfc->log, xfc->display, xfc->drawable, clipboard->property_atom); xf_cliprdr_process_requested_data(clipboard, has_data, clipboard->incr_data, len); return TRUE; @@ -1201,8 +1203,8 @@ static void xf_cliprdr_provide_targets(xfClipboard* clipboard, const XSelectionE if (respond->property != None) { WINPR_ASSERT(clipboard->numTargets <= INT32_MAX); - LogTagAndXChangeProperty(TAG, xfc->display, respond->requestor, respond->property, XA_ATOM, - 32, PropModeReplace, (const BYTE*)clipboard->targets, + LogDynAndXChangeProperty(xfc->log, xfc->display, respond->requestor, respond->property, + XA_ATOM, 32, PropModeReplace, (const BYTE*)clipboard->targets, (int)clipboard->numTargets); } } @@ -1218,7 +1220,7 @@ static void xf_cliprdr_provide_timestamp(xfClipboard* clipboard, const XSelectio if (respond->property != None) { - LogTagAndXChangeProperty(TAG, xfc->display, respond->requestor, respond->property, + LogDynAndXChangeProperty(xfc->log, xfc->display, respond->requestor, respond->property, XA_INTEGER, 32, PropModeReplace, (const BYTE*)&clipboard->selection_ownership_timestamp, 1); } @@ -1236,7 +1238,7 @@ static void xf_cliprdr_provide_data(xfClipboard* clipboard, const XSelectionEven if (respond->property != None) { - LogTagAndXChangeProperty(TAG, xfc->display, respond->requestor, respond->property, + LogDynAndXChangeProperty(xfc->log, xfc->display, respond->requestor, respond->property, respond->target, 8, PropModeReplace, data, WINPR_ASSERTING_INT_CAST(int32_t, size)); } @@ -1556,9 +1558,9 @@ static BOOL xf_cliprdr_process_selection_request(xfClipboard* clipboard, if (formatId == CF_RAW) { - if (LogTagAndXGetWindowProperty( - TAG, xfc->display, xevent->requestor, clipboard->property_atom, 0, 4, 0, - XA_INTEGER, &type, &fmt, &length, &bytes_left, &data) != Success) + if (LogDynAndXGetWindowProperty( + xfc->log, xfc->display, xevent->requestor, clipboard->property_atom, 0, 4, + 0, XA_INTEGER, &type, &fmt, &length, &bytes_left, &data) != Success) { } @@ -1668,7 +1670,8 @@ static BOOL xf_cliprdr_process_selection_clear(xfClipboard* clipboard, if (xf_cliprdr_is_self_owned(clipboard)) return FALSE; - LogTagAndXDeleteProperty(TAG, xfc->display, clipboard->root_window, clipboard->property_atom); + LogDynAndXDeleteProperty(xfc->log, xfc->display, clipboard->root_window, + clipboard->property_atom); return TRUE; } @@ -1737,7 +1740,7 @@ void xf_cliprdr_handle_xevent(xfContext* xfc, const XEvent* event) if (se->selection != clipboard->clipboard_atom) return; - if (XGetSelectionOwner(xfc->display, se->selection) == xfc->drawable) + if (LogDynAndXGetSelectionOwner(xfc->log, xfc->display, se->selection) == xfc->drawable) return; clipboard->owner = None; @@ -1830,7 +1833,7 @@ static UINT xf_cliprdr_send_client_format_list(xfClipboard* clipboard, BOOL forc if (clipboard->owner && clipboard->owner != xfc->drawable) { /* Request the owner for TARGETS, and wait for SelectionNotify event */ - LogTagAndXConvertSelection(TAG, xfc->display, clipboard->clipboard_atom, + LogDynAndXConvertSelection(xfc->log, xfc->display, clipboard->clipboard_atom, clipboard->targets[1], clipboard->property_atom, xfc->drawable, CurrentTime); } @@ -1952,8 +1955,9 @@ static void xf_cliprdr_prepare_to_set_selection_owner(xfContext* xfc, xfClipboar * anyway! */ Atom value = clipboard->timestamp_property_atom; - LogTagAndXChangeProperty(TAG, xfc->display, xfc->drawable, clipboard->timestamp_property_atom, - XA_ATOM, 32, PropModeReplace, (const BYTE*)&value, 1); + LogDynAndXChangeProperty(xfc->log, xfc->display, xfc->drawable, + clipboard->timestamp_property_atom, XA_ATOM, 32, PropModeReplace, + (const BYTE*)&value, 1); LogDynAndXFlush(xfc->log, xfc->display); } @@ -1967,7 +1971,8 @@ static void xf_cliprdr_set_selection_owner(xfContext* xfc, xfClipboard* clipboar */ clipboard->selection_ownership_timestamp = timestamp; - XSetSelectionOwner(xfc->display, clipboard->clipboard_atom, xfc->drawable, timestamp); + LogDynAndXSetSelectionOwner(xfc->log, xfc->display, clipboard->clipboard_atom, xfc->drawable, + timestamp); LogDynAndXFlush(xfc->log, xfc->display); } @@ -2128,7 +2133,7 @@ xf_cliprdr_server_format_data_request(CliprdrClientContext* context, if (rawTransfer) { format = xf_cliprdr_get_client_format_by_id(clipboard, CF_RAW); - LogTagAndXChangeProperty(TAG, xfc->display, xfc->drawable, clipboard->property_atom, + LogDynAndXChangeProperty(xfc->log, xfc->display, xfc->drawable, clipboard->property_atom, XA_INTEGER, 32, PropModeReplace, (const BYTE*)&formatId, 1); } else @@ -2141,7 +2146,7 @@ xf_cliprdr_server_format_data_request(CliprdrClientContext* context, DEBUG_CLIPRDR("requested format 0x%08" PRIx32 " [%s] {local 0x%08" PRIx32 "} [%s]", format->formatToRequest, ClipboardGetFormatIdString(format->formatToRequest), format->localFormat, format->formatName); - LogTagAndXConvertSelection(TAG, xfc->display, clipboard->clipboard_atom, format->atom, + LogDynAndXConvertSelection(xfc->log, xfc->display, clipboard->clipboard_atom, format->atom, clipboard->property_atom, xfc->drawable, CurrentTime); LogDynAndXFlush(xfc->log, xfc->display); /* After this point, we expect a SelectionNotify event from the clipboard owner. */ diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index c71a1ec82..db9537aa7 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -1332,7 +1332,7 @@ BOOL xf_event_process(freerdp* instance, const XEvent* event) if (!xf_floatbar_check_event(floatbar, event) && !xf_floatbar_is_locked(floatbar)) xf_input_handle_event(xfc, event); - XSync(xfc->display, FALSE); + LogDynAndXSync(xfc->log, xfc->display, FALSE); return status; } diff --git a/client/X11/xf_floatbar.c b/client/X11/xf_floatbar.c index 53776bb3f..caf387b4c 100644 --- a/client/X11/xf_floatbar.c +++ b/client/X11/xf_floatbar.c @@ -25,6 +25,7 @@ #include #include "xf_floatbar.h" +#include "xf_utils.h" #include "resource/close.xbm" #include "resource/lock.xbm" #include "resource/unlock.xbm" @@ -156,12 +157,14 @@ BOOL xf_floatbar_hide_and_show(xfFloatbar* floatbar) (floatbar->y > (FLOATBAR_HEIGHT * -1))) { floatbar->y = floatbar->y - 1; - XMoveWindow(xfc->display, floatbar->handle, floatbar->x, floatbar->y); + LogDynAndXMoveWindow(xfc->log, xfc->display, floatbar->handle, floatbar->x, + floatbar->y); } else if (floatbar->y < 0 && (floatbar->last_motion_y_root < 10)) { floatbar->y = floatbar->y + 1; - XMoveWindow(xfc->display, floatbar->handle, floatbar->x, floatbar->y); + LogDynAndXMoveWindow(xfc->log, xfc->display, floatbar->handle, floatbar->x, + floatbar->y); } } @@ -194,9 +197,9 @@ static BOOL create_floatbar(xfFloatbar* floatbar) if (((floatbar->flags & 0x0004) == 0) && !floatbar->locked) floatbar->y = -FLOATBAR_HEIGHT + 1; - floatbar->handle = - XCreateWindow(xfc->display, floatbar->root_window, floatbar->x, 0, FLOATBAR_DEFAULT_WIDTH, - FLOATBAR_HEIGHT, 0, CopyFromParent, InputOutput, CopyFromParent, 0, NULL); + floatbar->handle = LogDynAndXCreateWindow( + xfc->log, xfc->display, floatbar->root_window, floatbar->x, 0, FLOATBAR_DEFAULT_WIDTH, + FLOATBAR_HEIGHT, 0, CopyFromParent, InputOutput, CopyFromParent, 0, NULL); floatbar->width = FLOATBAR_DEFAULT_WIDTH; floatbar->height = FLOATBAR_HEIGHT; floatbar->mode = XF_FLOATBAR_MODE_NONE; @@ -238,13 +241,13 @@ BOOL xf_floatbar_toggle_fullscreen(xfFloatbar* floatbar, bool fullscreen) if (!create_floatbar(floatbar)) return FALSE; - XMapWindow(xfc->display, floatbar->handle); + LogDynAndXMapWindow(xfc->log, xfc->display, floatbar->handle); size = ARRAYSIZE(floatbar->buttons); for (int i = 0; i < size; i++) { xfFloatbarButton* button = floatbar->buttons[i]; - XMapWindow(xfc->display, button->handle); + LogDynAndXMapWindow(xfc->log, xfc->display, button->handle); } /* If default is hidden (and not sticky) don't show on fullscreen state changes */ @@ -256,7 +259,7 @@ BOOL xf_floatbar_toggle_fullscreen(xfFloatbar* floatbar, bool fullscreen) else if (floatbar->created) { XUnmapSubwindows(xfc->display, floatbar->handle); - XUnmapWindow(xfc->display, floatbar->handle); + LogDynAndXUnmapWindow(xfc->log, xfc->display, floatbar->handle); } return TRUE; @@ -302,9 +305,10 @@ xfFloatbarButton* xf_floatbar_new_button(xfFloatbar* floatbar, int type) button->y = 0; button->focus = FALSE; - button->handle = XCreateWindow(floatbar->xfc->display, floatbar->handle, button->x, 0, - FLOATBAR_BUTTON_WIDTH, FLOATBAR_BUTTON_WIDTH, 0, CopyFromParent, - InputOutput, CopyFromParent, 0, NULL); + button->handle = + LogDynAndXCreateWindow(floatbar->xfc->log, floatbar->xfc->display, floatbar->handle, + button->x, 0, FLOATBAR_BUTTON_WIDTH, FLOATBAR_BUTTON_WIDTH, 0, + CopyFromParent, InputOutput, CopyFromParent, 0, NULL); XSelectInput(floatbar->xfc->display, button->handle, ExposureMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask | LeaveWindowMask | EnterWindowMask | StructureNotifyMask); @@ -393,11 +397,11 @@ static void xf_floatbar_event_expose(xfFloatbar* floatbar) WINPR_ASSERT(display); /* create the pixmap that we'll use for shaping the window */ - pmap = XCreatePixmap(display, floatbar->handle, - WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->width), - WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->height), 1); - gc = XCreateGC(display, floatbar->handle, 0, 0); - shape_gc = XCreateGC(display, pmap, 0, 0); + pmap = LogDynAndXCreatePixmap(floatbar->xfc->log, display, floatbar->handle, + WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->width), + WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->height), 1); + gc = LogDynAndXCreateGC(floatbar->xfc->log, display, floatbar->handle, 0, 0); + shape_gc = LogDynAndXCreateGC(floatbar->xfc->log, display, pmap, 0, 0); /* points for drawing the floatbar */ shape[0].x = 0; shape[0].y = 0; @@ -421,23 +425,26 @@ static void xf_floatbar_event_expose(xfFloatbar* floatbar) border[4].x = border[0].x; border[4].y = border[0].y; /* Fill all pixels with 0 */ - XSetForeground(display, shape_gc, 0); - XFillRectangle(display, pmap, shape_gc, 0, 0, - WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->width), - WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->height)); + LogDynAndXSetForeground(floatbar->xfc->log, display, shape_gc, 0); + LogDynAndXFillRectangle(floatbar->xfc->log, display, pmap, shape_gc, 0, 0, + WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->width), + WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->height)); /* Fill all pixels which should be shown with 1 */ - XSetForeground(display, shape_gc, 1); + LogDynAndXSetForeground(floatbar->xfc->log, display, shape_gc, 1); XFillPolygon(display, pmap, shape_gc, shape, 5, 0, CoordModeOrigin); XShapeCombineMask(display, floatbar->handle, ShapeBounding, 0, 0, pmap, ShapeSet); /* draw the float bar */ - XSetForeground(display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BACKGROUND)); + LogDynAndXSetForeground(floatbar->xfc->log, display, gc, + xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BACKGROUND)); XFillPolygon(display, floatbar->handle, gc, shape, 4, 0, CoordModeOrigin); /* draw an border for the floatbar */ - XSetForeground(display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BORDER)); + LogDynAndXSetForeground(floatbar->xfc->log, display, gc, + xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BORDER)); XDrawLines(display, floatbar->handle, gc, border, 5, CoordModeOrigin); /* draw the host name connected to (limit to maximum file name) */ const size_t len = strnlen(floatbar->title, MAX_PATH); - XSetForeground(display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_FOREGROUND)); + LogDynAndXSetForeground(floatbar->xfc->log, display, gc, + xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_FOREGROUND)); WINPR_ASSERT(len <= INT32_MAX / 2); const int fx = floatbar->width / 2 - (int)len * 2; @@ -450,8 +457,8 @@ static void xf_floatbar_event_expose(xfFloatbar* floatbar) { XDrawString(display, floatbar->handle, gc, fx, 15, floatbar->title, (int)len); } - XFreeGC(display, gc); - XFreeGC(display, shape_gc); + LogDynAndXFreeGC(floatbar->xfc->log, display, gc); + LogDynAndXFreeGC(floatbar->xfc->log, display, shape_gc); } static xfFloatbarButton* xf_floatbar_get_button(xfFloatbar* floatbar, Window window) @@ -505,7 +512,7 @@ static void xf_floatbar_button_update_positon(xfFloatbar* floatbar) WINPR_ASSERT(xfc); WINPR_ASSERT(xfc->display); - XMoveWindow(xfc->display, button->handle, button->x, button->y); + LogDynAndXMoveWindow(xfc->log, xfc->display, button->handle, button->x, button->y); xf_floatbar_event_expose(floatbar); } } @@ -525,7 +532,7 @@ static void xf_floatbar_button_event_expose(xfFloatbar* floatbar, Window window) WINPR_ASSERT(xfc->display); WINPR_ASSERT(xfc->window); - gc = XCreateGC(xfc->display, button->handle, 0, 0); + gc = LogDynAndXCreateGC(xfc->log, xfc->display, button->handle, 0, 0); floatbar = xfc->window->floatbar; WINPR_ASSERT(floatbar); @@ -559,16 +566,18 @@ static void xf_floatbar_button_event_expose(xfFloatbar* floatbar, Window window) FLOATBAR_BUTTON_WIDTH, FLOATBAR_BUTTON_WIDTH); if (!(button->focus)) - XSetForeground(xfc->display, gc, - xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BACKGROUND)); + LogDynAndXSetForeground(floatbar->xfc->log, xfc->display, gc, + xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BACKGROUND)); else - XSetForeground(xfc->display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BORDER)); + LogDynAndXSetForeground(floatbar->xfc->log, xfc->display, gc, + xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BORDER)); - XSetBackground(xfc->display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_FOREGROUND)); + LogDynAndXSetBackground(xfc->log, xfc->display, gc, + xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_FOREGROUND)); XCopyPlane(xfc->display, pattern, button->handle, gc, 0, 0, FLOATBAR_BUTTON_WIDTH, FLOATBAR_BUTTON_WIDTH, 0, 0, 1); - XFreePixmap(xfc->display, pattern); - XFreeGC(xfc->display, gc); + LogDynAndXFreePixmap(xfc->log, xfc->display, pattern); + LogDynAndXFreeGC(xfc->log, xfc->display, gc); } static void xf_floatbar_button_event_buttonpress(xfFloatbar* floatbar, const XButtonEvent* event) @@ -666,9 +675,9 @@ static void xf_floatbar_resize(xfFloatbar* floatbar, const XMotionEvent* event) /* only resize and move window if still above minimum width */ if (FLOATBAR_MIN_WIDTH < width) { - XMoveResizeWindow(xfc->display, floatbar->handle, x, 0, - WINPR_ASSERTING_INT_CAST(uint32_t, width), - WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->height)); + LogDynAndXMoveResizeWindow(xfc->log, xfc->display, floatbar->handle, x, 0, + WINPR_ASSERTING_INT_CAST(uint32_t, width), + WINPR_ASSERTING_INT_CAST(uint32_t, floatbar->height)); floatbar->x = x; floatbar->width = width; } @@ -695,7 +704,7 @@ static void xf_floatbar_dragging(xfFloatbar* floatbar, const XMotionEvent* event return; /* move window to new x position */ - XMoveWindow(xfc->display, floatbar->handle, x, 0); + LogDynAndXMoveWindow(xfc->log, xfc->display, floatbar->handle, x, 0); /* update struct values for the next event */ floatbar->last_motion_x_root = floatbar->last_motion_x_root + movement; floatbar->x = x; @@ -887,8 +896,8 @@ static void xf_floatbar_button_free(xfContext* xfc, xfFloatbarButton* button) { WINPR_ASSERT(xfc); WINPR_ASSERT(xfc->display); - XUnmapWindow(xfc->display, button->handle); - XDestroyWindow(xfc->display, button->handle); + LogDynAndXUnmapWindow(xfc->log, xfc->display, button->handle); + LogDynAndXDestroyWindow(xfc->log, xfc->display, button->handle); } free(button); @@ -917,8 +926,8 @@ void xf_floatbar_free(xfFloatbar* floatbar) if (floatbar->handle) { WINPR_ASSERT(xfc->display); - XUnmapWindow(xfc->display, floatbar->handle); - XDestroyWindow(xfc->display, floatbar->handle); + LogDynAndXUnmapWindow(xfc->log, xfc->display, floatbar->handle); + LogDynAndXDestroyWindow(xfc->log, xfc->display, floatbar->handle); } free(floatbar); diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 6ab4ef9aa..37d0bb17b 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -59,9 +59,9 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) surfaceRect.top = 0; surfaceRect.right = WINPR_ASSERTING_INT_CAST(UINT16, surface->gdi.mappedWidth); surfaceRect.bottom = WINPR_ASSERTING_INT_CAST(UINT16, surface->gdi.mappedHeight); - XSetClipMask(xfc->display, xfc->gc, None); - XSetFunction(xfc->display, xfc->gc, GXcopy); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); + LogDynAndXSetClipMask(xfc->log, xfc->display, xfc->gc, None); + LogDynAndXSetFunction(xfc->log, xfc->display, xfc->gc, GXcopy); + LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid); region16_intersect_rect(&(surface->gdi.invalidRegion), &(surface->gdi.invalidRegion), &surfaceRect); @@ -133,8 +133,8 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) rc = CHANNEL_RC_OK; fail: region16_clear(&surface->gdi.invalidRegion); - XSetClipMask(xfc->display, xfc->gc, None); - XSync(xfc->display, False); + LogDynAndXSetClipMask(xfc->log, xfc->display, xfc->gc, None); + LogDynAndXSync(xfc->log, xfc->display, False); return rc; } @@ -344,10 +344,11 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, if (FreeRDPAreColorFormatsEqualNoAlpha(gdi->dstFormat, surface->gdi.format)) { WINPR_ASSERT(xfc->depth != 0); - surface->image = XCreateImage( - xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), ZPixmap, 0, - (char*)surface->gdi.data, surface->gdi.mappedWidth, surface->gdi.mappedHeight, - xfc->scanline_pad, WINPR_ASSERTING_INT_CAST(int, surface->gdi.scanline)); + surface->image = LogDynAndXCreateImage( + xfc->log, xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), + ZPixmap, 0, (char*)surface->gdi.data, surface->gdi.mappedWidth, + surface->gdi.mappedHeight, xfc->scanline_pad, + WINPR_ASSERTING_INT_CAST(int, surface->gdi.scanline)); } else { @@ -367,9 +368,9 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, ZeroMemory(surface->stage, size); WINPR_ASSERT(xfc->depth != 0); - surface->image = XCreateImage( - xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), ZPixmap, 0, - (char*)surface->stage, surface->gdi.mappedWidth, surface->gdi.mappedHeight, + surface->image = LogDynAndXCreateImage( + xfc->log, xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), + ZPixmap, 0, (char*)surface->stage, surface->gdi.mappedWidth, surface->gdi.mappedHeight, xfc->scanline_pad, WINPR_ASSERTING_INT_CAST(int, surface->stageScanline)); } diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index 6eaa8dfda..8baa3766f 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -39,6 +39,7 @@ #include "xf_graphics.h" #include "xf_event.h" +#include "xf_utils.h" #include #define TAG CLIENT_TAG("x11") @@ -467,21 +468,16 @@ static BOOL xf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y) tmp.event_mask = (current.your_event_mask & ~(PointerMotionMask)); - rc = XChangeWindowAttributes(xfc->display, handle, CWEventMask, &tmp); + rc = LogDynAndXChangeWindowAttributes(xfc->log, xfc->display, handle, CWEventMask, &tmp); if (rc == 0) - { - WLog_WARN(TAG, "XChangeWindowAttributes==%d", rc); goto out; - } rc = XWarpPointer(xfc->display, handle, handle, 0, 0, 0, 0, WINPR_ASSERTING_INT_CAST(int, x), WINPR_ASSERTING_INT_CAST(int, y)); if (rc == 0) WLog_WARN(TAG, "XWarpPointer==%d", rc); tmp.event_mask = current.your_event_mask; - rc = XChangeWindowAttributes(xfc->display, handle, CWEventMask, &tmp); - if (rc == 0) - WLog_WARN(TAG, "2.try XChangeWindowAttributes==%d", rc); + LogDynAndXChangeWindowAttributes(xfc->log, xfc->display, handle, CWEventMask, &tmp); ret = TRUE; out: xf_unlock_x11(xfc); diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 6a35b8aec..94ede4404 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -537,7 +537,7 @@ BOOL xf_keyboard_init(xfContext* xfc) UINT32 KeyboardLayout = freerdp_settings_get_uint32(settings, FreeRDP_KeyboardLayout); if (KeyboardLayout == 0) { - xf_detect_keyboard_layout_from_xkb(&KeyboardLayout); + xf_detect_keyboard_layout_from_xkb(xfc->log, &KeyboardLayout); if (KeyboardLayout == 0) freerdp_detect_keyboard_layout_from_system_locale(&KeyboardLayout); if (KeyboardLayout == 0) diff --git a/client/X11/xf_monitor.c b/client/X11/xf_monitor.c index f93973fa2..a2642f2fb 100644 --- a/client/X11/xf_monitor.c +++ b/client/X11/xf_monitor.c @@ -50,6 +50,7 @@ #endif #include "xf_monitor.h" +#include "xf_utils.h" /* See MSDN Section on Multiple Display Monitors: http://msdn.microsoft.com/en-us/library/dd145071 */ @@ -111,7 +112,7 @@ int xf_list_monitors(xfContext* xfc) } #endif - XCloseDisplay(display); + LogDynAndXCloseDisplay(xfc->log, display); return 0; } diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index be841e1f6..1fdfaf23f 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -756,8 +756,8 @@ static void xf_rail_set_window_icon(xfContext* xfc, xfAppWindow* railWindow, xfR { WINPR_ASSERT(xfc); - LogTagAndXChangeProperty(TAG, xfc->display, railWindow->handle, xfc->NET_WM_ICON, XA_CARDINAL, - 32, replace ? PropModeReplace : PropModeAppend, + LogDynAndXChangeProperty(xfc->log, xfc->display, railWindow->handle, xfc->NET_WM_ICON, + XA_CARDINAL, 32, replace ? PropModeReplace : PropModeAppend, (unsigned char*)icon->data, icon->length); LogDynAndXFlush(xfc->log, xfc->display); } diff --git a/client/X11/xf_tsmf.c b/client/X11/xf_tsmf.c index 9ed346009..7d79c04b8 100644 --- a/client/X11/xf_tsmf.c +++ b/client/X11/xf_tsmf.c @@ -137,13 +137,13 @@ static int xf_tsmf_xv_video_frame_event(TsmfClientContext* tsmf, TSMF_VIDEO_FRAM if (xv->xv_colorkey_atom != None) { XvGetPortAttribute(xfc->display, xv->xv_port, xv->xv_colorkey_atom, &colorkey); - XSetFunction(xfc->display, xfc->gc, GXcopy); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); - XSetForeground(xfc->display, xfc->gc, colorkey); + LogDynAndXSetFunction(xfc->log, xfc->display, xfc->gc, GXcopy); + LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid); + LogDynAndXSetForeground(xfc->log, xfc->display, xfc->gc, colorkey); if (event->numVisibleRects < 1) { - XSetClipMask(xfc->display, xfc->gc, None); + LogDynAndXSetClipMask(xfc->log, xfc->display, xfc->gc, None); } else { @@ -152,12 +152,12 @@ static int xf_tsmf_xv_video_frame_event(TsmfClientContext* tsmf, TSMF_VIDEO_FRAM } else { - XSetFunction(xfc->display, xfc->gc, GXcopy); - XSetFillStyle(xfc->display, xfc->gc, FillSolid); + LogDynAndXSetFunction(xfc->log, xfc->display, xfc->gc, GXcopy); + LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid); if (event->numVisibleRects < 1) { - XSetClipMask(xfc->display, xfc->gc, None); + LogDynAndXSetClipMask(xfc->log, xfc->display, xfc->gc, None); } else { @@ -295,9 +295,9 @@ static int xf_tsmf_xv_video_frame_event(TsmfClientContext* tsmf, TSMF_VIDEO_FRAM FALSE); if (xv->xv_colorkey_atom == None) - XSetClipMask(xfc->display, xfc->gc, None); + LogDynAndXSetClipMask(xfc->log, xfc->display, xfc->gc, None); - XSync(xfc->display, FALSE); + LogDynAndXSync(xfc->log, xfc->display, FALSE); XShmDetach(xfc->display, &shminfo); XFree(image); diff --git a/client/X11/xf_utils.c b/client/X11/xf_utils.c index 2fc0cf325..db9faf3e4 100644 --- a/client/X11/xf_utils.c +++ b/client/X11/xf_utils.c @@ -32,6 +32,16 @@ static const DWORD log_level = WLOG_TRACE; +static const char* error_to_string(wLog* log, Display* display, int error, char* buffer, + size_t size) +{ + WINPR_ASSERT(size <= INT32_MAX); + const int rc = XGetErrorText(display, error, buffer, (int)size); + if (rc != Success) + WLog_Print(log, WLOG_WARN, "XGetErrorText returned %d", rc); + return buffer; +} + static void write_log(wLog* log, DWORD level, const char* fname, const char* fkt, size_t line, ...) { va_list ap = { 0 }; @@ -40,6 +50,41 @@ static void write_log(wLog* log, DWORD level, const char* fname, const char* fkt va_end(ap); } +static BOOL ignore_code(int rc, size_t count, va_list ap) +{ + for (size_t x = 0; x < count; x++) + { + const int val = va_arg(ap, int); + if (rc == val) + return TRUE; + } + return FALSE; +} + +static int write_result_log(wLog* log, DWORD level, const char* fname, const char* fkt, size_t line, + Display* display, char* name, int rc, size_t count, ...) +{ + if (rc != Success) + { + va_list ap; + va_start(ap, count); + const BOOL ignore = ignore_code(rc, count, ap); + va_end(ap); + + if (!ignore) + { + char buffer[128] = { 0 }; + + if (WLog_IsLevelActive(log, level)) + { + WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, fname, fkt, "%s returned %s", + name, error_to_string(log, display, rc, buffer, sizeof(buffer))); + } + } + } + return rc; +} + char* Safe_XGetAtomNameEx(wLog* log, Display* display, Atom atom, const char* varname) { WLog_Print(log, log_level, "XGetAtomName(%s, 0x%08" PRIx32 ")", varname, atom); @@ -59,28 +104,10 @@ Atom Logging_XInternAtom(wLog* log, Display* display, _Xconst char* atom_name, B return atom; } -static const char* error_to_string(Display* display, int error, char* buffer, size_t size) -{ - WINPR_ASSERT(size <= INT32_MAX); - const int rc = XGetErrorText(display, error, buffer, (int)size); - if (rc != Success) - WLog_WARN(TAG, "XGetErrorText returned %d", rc); - return buffer; -} - const char* x11_error_to_string(xfContext* xfc, int error, char* buffer, size_t size) { WINPR_ASSERT(xfc); - return error_to_string(xfc->display, error, buffer, size); -} - -int LogTagAndXChangeProperty_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Window w, Atom property, Atom type, int format, - int mode, const unsigned char* data, int nelements) -{ - wLog* log = WLog_Get(tag); - return LogDynAndXChangeProperty_ex(log, file, fkt, line, display, w, property, type, format, - mode, data, nelements); + return error_to_string(xfc->log, xfc->display, error, buffer, size); } int LogDynAndXChangeProperty_ex(wLog* log, const char* file, const char* fkt, size_t line, @@ -98,29 +125,8 @@ int LogDynAndXChangeProperty_ex(wLog* log, const char* file, const char* fkt, si XFree(typestr); } const int rc = XChangeProperty(display, w, property, type, format, mode, data, nelements); - if (rc != Success) - { - char buffer[128] = { 0 }; - - char* propstr = Safe_XGetAtomName(log, display, property); - char* typestr = Safe_XGetAtomName(log, display, type); - - /* There are lots of requests to atoms that do not exist. - * These are harmless and would only spam the log, so make them trace only */ - const DWORD lvl = (rc == BadRequest) ? WLOG_DEBUG : WLOG_WARN; - WLog_Print(log, lvl, "XChangeProperty(%s, %s) returned %s", propstr, typestr, - error_to_string(display, rc, buffer, sizeof(buffer))); - XFree(propstr); - XFree(typestr); - } - return rc; -} - -int LogTagAndXDeleteProperty_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Window w, Atom property) -{ - wLog* log = WLog_Get(tag); - return LogDynAndXDeleteProperty_ex(log, file, fkt, line, display, w, property); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XChangeProperty", rc, 1, + BadRequest); } int LogDynAndXDeleteProperty_ex(wLog* log, const char* file, const char* fkt, size_t line, @@ -134,25 +140,7 @@ int LogDynAndXDeleteProperty_ex(wLog* log, const char* file, const char* fkt, si XFree(propstr); } const int rc = XDeleteProperty(display, w, property); - if (rc != Success) - { - char buffer[128] = { 0 }; - - char* propstr = Safe_XGetAtomName(log, display, property); - WLog_Print(log, WLOG_WARN, "XDeleteProperty(%s) returned %s", propstr, - error_to_string(display, rc, buffer, sizeof(buffer))); - XFree(propstr); - } - return rc; -} - -int LogTagAndXConvertSelection_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Atom selection, Atom target, Atom property, - Window requestor, Time time) -{ - wLog* log = WLog_Get(tag); - return LogDynAndXConvertSelection_ex(log, file, fkt, line, display, selection, target, property, - requestor, time); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XDeleteProperty", rc, 0); } int LogDynAndXConvertSelection_ex(wLog* log, const char* file, const char* fkt, size_t line, @@ -172,33 +160,7 @@ int LogDynAndXConvertSelection_ex(wLog* log, const char* file, const char* fkt, XFree(selectstr); } const int rc = XConvertSelection(display, selection, target, property, requestor, time); - if (rc != Success) - { - char buffer[128] = { 0 }; - - char* selectstr = Safe_XGetAtomName(log, display, selection); - char* targetstr = Safe_XGetAtomName(log, display, target); - char* propstr = Safe_XGetAtomName(log, display, property); - WLog_Print(log, WLOG_WARN, "XConvertSelection(%s, %s, %s) returned %s", selectstr, - targetstr, propstr, error_to_string(display, rc, buffer, sizeof(buffer))); - XFree(propstr); - XFree(targetstr); - XFree(selectstr); - } - return rc; -} - -int LogTagAndXGetWindowProperty_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Window w, Atom property, long long_offset, - long long_length, int delete, Atom req_type, - Atom* actual_type_return, int* actual_format_return, - unsigned long* nitems_return, unsigned long* bytes_after_return, - unsigned char** prop_return) -{ - wLog* log = WLog_Get(tag); - return LogDynAndXGetWindowProperty_ex( - log, file, fkt, line, display, w, property, long_offset, long_length, delete, req_type, - actual_type_return, actual_format_return, nitems_return, bytes_after_return, prop_return); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XConvertSelection", rc, 0); } int LogDynAndXGetWindowProperty_ex(wLog* log, const char* file, const char* fkt, size_t line, @@ -223,17 +185,7 @@ int LogDynAndXGetWindowProperty_ex(wLog* log, const char* file, const char* fkt, const int rc = XGetWindowProperty(display, w, property, long_offset, long_length, delete, req_type, actual_type_return, actual_format_return, nitems_return, bytes_after_return, prop_return); - if (rc != Success) - { - char buffer[128] = { 0 }; - char* propstr = Safe_XGetAtomName(log, display, property); - char* req_type_str = Safe_XGetAtomName(log, display, req_type); - WLog_Print(log, WLOG_WARN, "XGetWindowProperty(%s, %s) returned %s", propstr, req_type_str, - error_to_string(display, rc, buffer, sizeof(buffer))); - XFree(propstr); - XFree(req_type_str); - } - return rc; + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XGetWindowProperty", rc, 0); } BOOL IsGnome(void) @@ -327,17 +279,8 @@ int LogDynAndXCopyArea_ex(wLog* log, const char* file, const char* fkt, size_t l } const int rc = XCopyArea(display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y); - if (rc != Success) - { - char buffer[128] = { 0 }; - - /* TODO: We get BadRequest return values, they are not documented properly and the call - * looks ok... */ - const DWORD lvl = (rc == BadRequest) ? WLOG_DEBUG : WLOG_WARN; - WLog_Print(log, lvl, "XCopyArea returned %s", - error_to_string(display, rc, buffer, sizeof(buffer))); - } - return rc; + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XCopyArea", rc, 1, + BadRequest); } int LogDynAndXPutImage_ex(wLog* log, const char* file, const char* fkt, size_t line, @@ -363,13 +306,7 @@ int LogDynAndXPutImage_ex(wLog* log, const char* file, const char* fkt, size_t l } const int rc = XPutImage(display, d, gc, image, src_x, src_y, dest_x, dest_y, width, height); - if (rc != Success) - { - char buffer[128] = { 0 }; - WLog_Print(log, WLOG_WARN, "XPutImage returned %s", - error_to_string(display, rc, buffer, sizeof(buffer))); - } - return rc; + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XPutImage", rc, 0); } int LogDynAndXSendEvent_ex(wLog* log, const char* file, const char* fkt, size_t line, @@ -385,16 +322,8 @@ int LogDynAndXSendEvent_ex(wLog* log, const char* file, const char* fkt, size_t } const int rc = XSendEvent(display, w, propagate, event_mask, event_send); - if (rc != Success) - { - char buffer[128] = { 0 }; - /* TODO: We get BadRequest return values, they are not documented properly and the call - * looks ok... */ - const DWORD lvl = (rc == BadRequest) ? WLOG_DEBUG : WLOG_WARN; - WLog_Print(log, lvl, "XSendEvent returned %s", - error_to_string(display, rc, buffer, sizeof(buffer))); - } - return rc; + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSendEvent", rc, 1, + BadRequest); } int LogDynAndXFlush_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display) @@ -405,13 +334,374 @@ int LogDynAndXFlush_ex(wLog* log, const char* file, const char* fkt, size_t line } const int rc = XFlush(display); - if (rc < 0) - { - char buffer[128] = { 0 }; - - const DWORD lvl = WLOG_WARN; - WLog_Print(log, lvl, "XFlush returned %s", - error_to_string(display, rc, buffer, sizeof(buffer))); - } - return rc; + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XFlush", rc, 1, BadRequest); +} + +Window LogDynAndXGetSelectionOwner_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Atom selection) +{ + if (WLog_IsLevelActive(log, log_level)) + { + char* selectionstr = Safe_XGetAtomName(log, display, selection); + write_log(log, log_level, file, fkt, line, "XGetSelectionOwner(%p, %s)", display, + selectionstr); + XFree(selectionstr); + } + return XGetSelectionOwner(display, selection); +} + +int LogDynAndXDestroyWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window window) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XDestroyWindow(%p, %lu)", display, window); + } + const int rc = XDestroyWindow(display, window); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XDestroyWindow", rc, 1, + BadRequest); +} + +int LogDynAndXSync_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display, + Bool discard) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSync(%p, %d)", display, discard); + } + const int rc = XSync(display, discard); + /* XSync most likely returns number of events, but not sure. + * https://www.x.org/releases/X11R7.5/doc/man/man3/XSync.3.html + * does not mention that. + */ + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSync", rc, 1, BadRequest); +} + +int LogDynAndXChangeWindowAttributes_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window window, unsigned long valuemask, + XSetWindowAttributes* attributes) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XChangeWindowAttributes(%p, %lu, 0x%08lu, %p)", + display, window, valuemask, attributes); + } + const int rc = XChangeWindowAttributes(display, window, valuemask, attributes); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XChangeWindowAttributes", rc, + 1, BadRequest); +} + +int LogDynAndXSetTransientForHint_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window window, Window prop_window) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSetTransientForHint(%p, %lu, %lu)", display, + window, prop_window); + } + const int rc = XSetTransientForHint(display, window, prop_window); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetTransientForHint", rc, 1, + BadRequest); +} + +int LogDynAndXCloseDisplay_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XCloseDisplay(%p)", display); + } + const int rc = XCloseDisplay(display); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XCloseDisplay", rc, 0); +} + +XImage* LogDynAndXCreateImage_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Visual* visual, unsigned int depth, int format, + int offset, char* data, unsigned int width, unsigned int height, + int bitmap_pad, int bytes_per_line) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XCreateImage(%p)", display); + } + return XCreateImage(display, visual, depth, format, offset, data, width, height, bitmap_pad, + bytes_per_line); +} + +Window LogDynAndXCreateWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window parent, int x, int y, unsigned int width, + unsigned int height, unsigned int border_width, int depth, + unsigned int class, Visual* visual, unsigned long valuemask, + XSetWindowAttributes* attributes) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XCreateWindow(%p)", display); + } + return XCreateWindow(display, parent, x, y, width, height, border_width, depth, class, visual, + valuemask, attributes); +} + +GC LogDynAndXCreateGC_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Drawable d, unsigned long valuemask, XGCValues* values) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XCreateGC(%p)", display); + } + return XCreateGC(display, d, valuemask, values); +} + +int LogDynAndXFreeGC_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display, + GC gc) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XFreeGC(%p)", display); + } + const int rc = XFreeGC(display, gc); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XFreeGC", rc, 1, BadRequest); +} + +Pixmap LogDynAndXCreatePixmap_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Drawable d, unsigned int width, + unsigned int height, unsigned int depth) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XCreatePixmap(%p, 0x%08lu, %u, %u, %u)", + display, d, width, height, depth); + } + return XCreatePixmap(display, d, width, height, depth); +} + +int LogDynAndXFreePixmap_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Pixmap pixmap) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XFreePixmap(%p)", display); + } + const int rc = XFreePixmap(display, pixmap); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XFreePixmap", rc, 1, + BadRequest); +} + +int LogDynAndXSetSelectionOwner_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Atom selection, Window owner, Time time) +{ + if (WLog_IsLevelActive(log, log_level)) + { + char* selectionstr = Safe_XGetAtomName(log, display, selection); + write_log(log, log_level, file, fkt, line, "XSetSelectionOwner(%p, %s, 0x%08lu, %lu)", + display, selectionstr, owner, time); + XFree(selectionstr); + } + const int rc = XSetSelectionOwner(display, selection, owner, time); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetSelectionOwner", rc, 1, + BadRequest); +} + +int LogDynAndXSetForeground_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, unsigned long foreground) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSetForeground(%p, %p, 0x%08lu)", display, gc, + foreground); + } + const int rc = XSetForeground(display, gc, foreground); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetForeground", rc, 1, + BadRequest); +} + +int LogDynAndXMoveWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, int x, int y) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XMoveWindow(%p, 0x%08lu, %d, %d)", display, w, + x, y); + } + const int rc = XMoveWindow(display, w, x, y); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XMoveWindow", rc, 1, + BadRequest); +} + +int LogDynAndXSetFillStyle_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, int fill_style) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSetFillStyle(%p, %p, %d)", display, gc, + fill_style); + } + const int rc = XSetFillStyle(display, gc, fill_style); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetFillStyle", rc, 1, + BadRequest); +} + +int LogDynAndXSetFunction_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, int function) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSetFunction(%p, %p, %d)", display, gc, + function); + } + const int rc = XSetFunction(display, gc, function); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetFunction", rc, 1, + BadRequest); +} + +int LogDynAndXRaiseWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XRaiseWindow(%p, %lu)", display, w); + } + const int rc = XRaiseWindow(display, w); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XRaiseWindow", rc, 1, + BadRequest); +} + +int LogDynAndXMapWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XMapWindow(%p, %lu)", display, w); + } + const int rc = XMapWindow(display, w); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XMapWindow", rc, 1, + BadRequest); +} + +int LogDynAndXUnmapWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XUnmapWindow(%p, %lu)", display, w); + } + const int rc = XUnmapWindow(display, w); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XUnmapWindow", rc, 1, + BadRequest); +} + +int LogDynAndXMoveResizeWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, int x, int y, unsigned int width, + unsigned int height) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XMoveResizeWindow(%p, %lu, %d, %d, %u, %u)", + display, w, x, y, width, height); + } + const int rc = XMoveResizeWindow(display, w, x, y, width, height); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XMoveResizeWindow", rc, 1, + BadRequest); +} + +int LogDynAndXWithdrawWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, int screen_number) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XWithdrawWindow(%p, %lu, %d)", display, w, + screen_number); + } + const int rc = XWithdrawWindow(display, w, screen_number); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XWithdrawWindow", rc, 1, + BadRequest); +} + +int LogDynAndXResizeWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, unsigned int width, unsigned int height) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XResizeWindow(%p, %lu, %u, %u)", display, w, + width, height); + } + const int rc = XResizeWindow(display, w, width, height); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XResizeWindow", rc, 1, + BadRequest); +} + +int LogDynAndXClearWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XClearWindow(%p, %lu)", display, w); + } + const int rc = XClearWindow(display, w); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XClearWindow", rc, 1, + BadRequest); +} + +int LogDynAndXSetBackground_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, unsigned long background) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSetBackground(%p, %p, %lu)", display, gc, + background); + } + const int rc = XSetBackground(display, gc, background); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetBackground", rc, 1, + BadRequest); +} + +int LogDynAndXSetClipMask_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, Pixmap pixmap) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSetClipMask(%p, %p, %lu)", display, gc, + pixmap); + } + const int rc = XSetClipMask(display, gc, pixmap); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetClipMask", rc, 1, + BadRequest); +} + +int LogDynAndXFillRectangle_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, GC gc, int x, int y, unsigned int width, + unsigned int height) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XFillRectangle(%p, %lu, %p, %d, %d, %u, %u)", + display, w, gc, x, y, width, height); + } + const int rc = XFillRectangle(display, w, gc, x, y, width, height); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XFillRectangle", rc, 1, + BadRequest); +} + +int LogDynAndXSetRegion_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, Region r) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XSetRegion(%p, %p, %lu)", display, gc, r); + } + const int rc = XSetRegion(display, gc, r); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XSetRegion", rc, 1, + BadRequest); +} + +int LogDynAndXReparentWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, Window parent, int x, int y) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, "XReparentWindow(%p, %lu, %lu, %d, %d)", display, + w, parent, x, y); + } + const int rc = XReparentWindow(display, w, parent, x, y); + return write_result_log(log, WLOG_WARN, file, fkt, line, display, "XReparentWindow", rc, 0); } diff --git a/client/X11/xf_utils.h b/client/X11/xf_utils.h index a22274dad..ea51256ab 100644 --- a/client/X11/xf_utils.h +++ b/client/X11/xf_utils.h @@ -23,6 +23,7 @@ #include #include +#include #include "xfreerdp.h" const char* x11_error_to_string(xfContext* xfc, int error, char* buffer, size_t size); @@ -38,19 +39,83 @@ typedef BOOL (*fn_action_script_run)(xfContext* xfc, const char* buffer, size_t BOOL run_action_script(xfContext* xfc, const char* what, const char* arg, fn_action_script_run fkt, void* user); -#define LogTagAndXGetWindowProperty(tag, display, w, property, long_offset, long_length, delete, \ - req_type, actual_type_return, actual_format_return, \ - nitems_return, bytes_after_return, prop_return) \ - LogTagAndXGetWindowProperty_ex((tag), __FILE__, __func__, __LINE__, (display), (w), \ - (property), (long_offset), (long_length), (delete), (req_type), \ - (actual_type_return), (actual_format_return), (nitems_return), \ - (bytes_after_return), (prop_return)) -int LogTagAndXGetWindowProperty_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Window w, Atom property, long long_offset, - long long_length, Bool delete, Atom req_type, - Atom* actual_type_return, int* actual_format_return, - unsigned long* nitems_return, unsigned long* bytes_after_return, - unsigned char** prop_return); +#define LogDynAndXCreatePixmap(log, display, d, width, height, depth) \ + LogDynAndXCreatePixmap_ex((log), __FILE__, __func__, __LINE__, (display), (d), (width), \ + (height), (depth)) + +Pixmap LogDynAndXCreatePixmap_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Drawable d, unsigned int width, + unsigned int height, unsigned int depth); + +#define LogDynAndXFreePixmap(log, display, pixmap) \ + LogDynAndXFreePixmap_ex(log, __FILE__, __func__, __LINE__, (display), (pixmap)) + +int LogDynAndXFreePixmap_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Pixmap pixmap); + +#define LogDynAndXCreateWindow(log, display, parent, x, y, width, height, border_width, depth, \ + class, visual, valuemask, attributes) \ + LogDynAndXCreateWindow_ex((log), __FILE__, __func__, __LINE__, (display), (parent), (x), (y), \ + (width), (height), (border_width), (depth), (class), (visual), \ + (valuemask), (attributes)) + +Window LogDynAndXCreateWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window parent, int x, int y, unsigned int width, + unsigned int height, unsigned int border_width, int depth, + unsigned int class, Visual* visual, unsigned long valuemask, + XSetWindowAttributes* attributes); + +#define LogDynAndXRaiseWindow(log, display, w) \ + LogDynAndXRaiseWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w)) + +int LogDynAndXRaiseWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w); + +#define LogDynAndXMapWindow(log, display, w) \ + LogDynAndXMapWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w)) + +int LogDynAndXMapWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w); + +#define LogDynAndXUnmapWindow(log, display, w) \ + LogDynAndXUnmapWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w)) + +int LogDynAndXUnmapWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w); + +#define LogDynAndXMoveResizeWindow(log, display, w, x, y, width, height) \ + LogDynAndXMoveResizeWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w), (x), (y), \ + (width), (height)) + +int LogDynAndXMoveResizeWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, int x, int y, unsigned int width, + unsigned int height); + +#define LogDynAndXWithdrawWindow(log, display, w, screen_number) \ + LogDynAndXWithdrawWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w), \ + (screen_number)) + +int LogDynAndXWithdrawWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, int screen_number); + +#define LogDynAndXMoveWindow(log, display, w, x, y) \ + LogDynAndXMoveWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w), (x), (y)) + +int LogDynAndXMoveWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, int x, int y); + +#define LogDynAndXResizeWindow(log, display, w, width, height) \ + LogDynAndXResizeWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w), (width), \ + (height)) + +int LogDynAndXResizeWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, unsigned int width, unsigned int height); + +#define LogDynAndXClearWindow(log, display, w) \ + LogDynAndXClearWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w)) + +int LogDynAndXClearWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w); #define LogDynAndXGetWindowProperty(log, display, w, property, long_offset, long_length, delete, \ req_type, actual_type_return, actual_format_return, \ @@ -59,6 +124,7 @@ int LogTagAndXGetWindowProperty_ex(const char* tag, const char* file, const char (property), (long_offset), (long_length), (delete), (req_type), \ (actual_type_return), (actual_format_return), (nitems_return), \ (bytes_after_return), (prop_return)) + int LogDynAndXGetWindowProperty_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display, Window w, Atom property, long long_offset, long long_length, Bool delete, Atom req_type, @@ -66,12 +132,12 @@ int LogDynAndXGetWindowProperty_ex(wLog* log, const char* file, const char* fkt, unsigned long* nitems_return, unsigned long* bytes_after_return, unsigned char** prop_return); -#define LogTagAndXChangeProperty(tag, display, w, property, type, format, mode, data, nelements) \ - LogTagAndXChangeProperty_ex((tag), __FILE__, __func__, __LINE__, (display), (w), (property), \ - (type), (format), (mode), (data), (nelements)) -int LogTagAndXChangeProperty_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Window w, Atom property, Atom type, int format, - int mode, _Xconst unsigned char* data, int nelements); +#define LogDynAndXReparentWindow(log, display, w, parent, x, y) \ + LogDynAndXReparentWindow_ex((log), __FILE__, __func__, __LINE__, (display), (w), (parent), \ + (x), (y)) + +int LogDynAndXReparentWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, Window parent, int x, int y); #define LogDynAndXChangeProperty(log, display, w, property, type, format, mode, data, nelements) \ LogDynAndXChangeProperty_ex((log), __FILE__, __func__, __LINE__, (display), (w), (property), \ @@ -80,29 +146,40 @@ int LogDynAndXChangeProperty_ex(wLog* log, const char* file, const char* fkt, si Display* display, Window w, Atom property, Atom type, int format, int mode, _Xconst unsigned char* data, int nelements); -#define LogTagAndXDeleteProperty(tag, display, w, property) \ - LogTagAndXDeleteProperty_ex((tag), __FILE__, __func__, __LINE__, (display), (w), (property)) -int LogTagAndXDeleteProperty_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Window w, Atom property); - #define LogDynAndXDeleteProperty(log, display, w, property) \ LogDynAndXDeleteProperty_ex((log), __FILE__, __func__, __LINE__, (display), (w), (property)) int LogDynAndXDeleteProperty_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display, Window w, Atom property); -#define LogTagAndXConvertSelection(tag, display, selection, target, property, requestor, time) \ - LogTagAndXConvertSelection_ex((tag), __FILE__, __func__, __LINE__, (display), (selection), \ - (target), (property), (requestor), (time)) -int LogTagAndXConvertSelection_ex(const char* tag, const char* file, const char* fkt, size_t line, - Display* display, Atom selection, Atom target, Atom property, - Window requestor, Time time); - #define LogDynAndXConvertSelection(log, display, selection, target, property, requestor, time) \ - LogDynAndXConvertSelection_ex((log), __FILE__, __func__, __LINE__, (display), (w), (property)) + LogDynAndXConvertSelection_ex((log), __FILE__, __func__, __LINE__, (display), (selection), \ + (target), (property), (requestor), (time)) int LogDynAndXConvertSelection_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display, Atom selection, Atom target, Atom property, Window requestor, Time time); +#define LogDynAndXCreateGC(log, display, d, valuemask, values) \ + LogDynAndXCreateGC_ex(log, __FILE__, __func__, __LINE__, (display), (d), (valuemask), (values)) + +GC LogDynAndXCreateGC_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Drawable d, unsigned long valuemask, XGCValues* values); + +#define LogDynAndXFreeGC(log, display, gc) \ + LogDynAndXFreeGC_ex(log, __FILE__, __func__, __LINE__, (display), (gc)) + +int LogDynAndXFreeGC_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display, + GC gc); + +#define LogDynAndXCreateImage(log, display, visual, depth, format, offset, data, width, height, \ + bitmap_pad, bytes_per_line) \ + LogDynAndXCreateImage_ex(log, __FILE__, __func__, __LINE__, (display), (visual), (depth), \ + (format), (offset), (data), (width), (height), (bitmap_pad), \ + (bytes_per_line)) +XImage* LogDynAndXCreateImage_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Visual* visual, unsigned int depth, int format, + int offset, char* data, unsigned int width, unsigned int height, + int bitmap_pad, int bytes_per_line); + #define LogDynAndXPutImage(log, display, d, gc, image, src_x, src_y, dest_x, dest_y, width, \ height) \ LogDynAndXPutImage_ex(log, __FILE__, __func__, __LINE__, (display), (d), (gc), (image), \ @@ -132,4 +209,83 @@ extern Status LogDynAndXSendEvent_ex(wLog* log, const char* file, const char* fk extern Status LogDynAndXFlush_ex(wLog* log, const char* file, const char* fkt, size_t line, Display* display); +#define LogDynAndXSync(log, display, discard) \ + LogDynAndXSync_ex(log, __FILE__, __func__, __LINE__, (display), (discard)) +extern int LogDynAndXSync_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Bool discard); + +#define LogDynAndXGetSelectionOwner(log, display, selection) \ + LogDynAndXGetSelectionOwner_ex(log, __FILE__, __func__, __LINE__, (display), (selection)) +extern Window LogDynAndXGetSelectionOwner_ex(wLog* log, const char* file, const char* fkt, + size_t line, Display* display, Atom selection); + +#define LogDynAndXSetSelectionOwner(log, display, selection, owner, time) \ + LogDynAndXSetSelectionOwner_ex(log, __FILE__, __func__, __LINE__, (display), (selection), \ + (owner), (time)) +extern int LogDynAndXSetSelectionOwner_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Atom selection, Window owner, + Time time); + +#define LogDynAndXDestroyWindow(log, display, window) \ + LogDynAndXDestroyWindow_ex(log, __FILE__, __func__, __LINE__, (display), (window)) +extern int LogDynAndXDestroyWindow_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window window); + +#define LogDynAndXChangeWindowAttributes(log, display, window, valuemask, attributes) \ + LogDynAndXChangeWindowAttributes_ex(log, __FILE__, __func__, __LINE__, (display), (window), \ + (valuemask), (attributes)) +extern int LogDynAndXChangeWindowAttributes_ex(wLog* log, const char* file, const char* fkt, + size_t line, Display* display, Window window, + unsigned long valuemask, + XSetWindowAttributes* attributes); + +#define LogDynAndXSetTransientForHint(log, display, window, prop_window) \ + LogDynAndXSetTransientForHint_ex(log, __FILE__, __func__, __LINE__, (display), (window), \ + (prop_window)) +extern int LogDynAndXSetTransientForHint_ex(wLog* log, const char* file, const char* fkt, + size_t line, Display* display, Window window, + Window prop_window); + +#define LogDynAndXCloseDisplay(log, display) \ + LogDynAndXCloseDisplay_ex(log, __FILE__, __func__, __LINE__, (display)) +extern int LogDynAndXCloseDisplay_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display); + +#define LogDynAndXSetClipMask(log, display, gc, pixmap) \ + LogDynAndXSetClipMask_ex(log, __FILE__, __func__, __LINE__, (display), (gc), (pixmap)) +extern int LogDynAndXSetClipMask_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, Pixmap pixmap); + +#define LogDynAndXSetRegion(log, display, gc, r) \ + LogDynAndXSetRegion_ex(log, __FILE__, __func__, __LINE__, (display), (gc), (r)) +extern int LogDynAndXSetRegion_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, Region r); + +#define LogDynAndXSetBackground(log, display, gc, background) \ + LogDynAndXSetBackground_ex(log, __FILE__, __func__, __LINE__, (display), (gc), (background)) +extern int LogDynAndXSetBackground_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, unsigned long background); + +#define LogDynAndXSetForeground(log, display, gc, foreground) \ + LogDynAndXSetForeground_ex(log, __FILE__, __func__, __LINE__, (display), (gc), (foreground)) +extern int LogDynAndXSetForeground_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, unsigned long foreground); + +#define LogDynAndXSetFillStyle(log, display, gc, fill_style) \ + LogDynAndXSetFillStyle_ex(log, __FILE__, __func__, __LINE__, (display), (gc), (fill_style)) +extern int LogDynAndXSetFillStyle_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, int fill_style); + +#define LogDynAndXFillRectangle(log, display, w, gc, x, y, width, height) \ + LogDynAndXFillRectangle_ex(log, __FILE__, __func__, __LINE__, (display), (w), (gc), (x), (y), \ + (width), (height)) +extern int LogDynAndXFillRectangle_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Window w, GC gc, int x, int y, + unsigned int width, unsigned int height); + +#define LogDynAndXSetFunction(log, display, gc, function) \ + LogDynAndXSetFunction_ex(log, __FILE__, __func__, __LINE__, (display), (gc), (function)) +extern int LogDynAndXSetFunction_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, GC gc, int function); + BOOL IsGnome(void); diff --git a/client/X11/xf_video.c b/client/X11/xf_video.c index 4f8f36520..27dde8617 100644 --- a/client/X11/xf_video.c +++ b/client/X11/xf_video.c @@ -48,9 +48,10 @@ static VideoSurface* xfVideoCreateSurface(VideoClientContext* video, UINT32 x, U xfc = (xfContext*)video->custom; WINPR_ASSERT(xfc); - ret->image = XCreateImage( - xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), ZPixmap, 0, - (char*)ret->base.data, width, height, 8, WINPR_ASSERTING_INT_CAST(int, ret->base.scanline)); + ret->image = LogDynAndXCreateImage(xfc->log, xfc->display, xfc->visual, + WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), ZPixmap, 0, + (char*)ret->base.data, width, height, 8, + WINPR_ASSERTING_INT_CAST(int, ret->base.scanline)); if (!ret->image) { diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 567f88982..699a9648f 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -222,7 +222,7 @@ static void xf_SetWindowTitleText(xfContext* xfc, Window window, const char* nam XStoreName(xfc->display, window, name); Atom wm_Name = xfc->NET_WM_NAME; Atom utf8Str = xfc->UTF8_STRING; - LogTagAndXChangeProperty(TAG, xfc->display, window, wm_Name, utf8Str, 8, PropModeReplace, + LogDynAndXChangeProperty(xfc->log, xfc->display, window, wm_Name, utf8Str, 8, PropModeReplace, (const unsigned char*)name, (int)i); } @@ -251,7 +251,7 @@ void xf_SendClientEvent(xfContext* xfc, Window window, Atom atom, unsigned int n DEBUG_X11("Send ClientMessage Event: wnd=0x%04lX", (unsigned long)xevent.xclient.window); LogDynAndXSendEvent(xfc->log, xfc->display, RootWindowOfScreen(xfc->screen), False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent); - XSync(xfc->display, False); + LogDynAndXSync(xfc->log, xfc->display, False); va_end(argp); } @@ -345,7 +345,7 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) if (fullscreen) { /* enter full screen: move the window before adding NET_WM_STATE_FULLSCREEN */ - XMoveWindow(xfc->display, window->handle, startX, startY); + LogDynAndXMoveWindow(xfc->log, xfc->display, window->handle, startX, startY); } /* Set the fullscreen state */ @@ -361,7 +361,7 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) */ xf_ResizeDesktopWindow(xfc, window, WINPR_ASSERTING_INT_CAST(int, width), WINPR_ASSERTING_INT_CAST(int, height)); - XMoveWindow(xfc->display, window->handle, startX, startY); + LogDynAndXMoveWindow(xfc->log, xfc->display, window->handle, startX, startY); } /* Set monitor bounds */ @@ -387,10 +387,12 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) { XSetWindowAttributes xswa = { 0 }; xswa.override_redirect = True; - XChangeWindowAttributes(xfc->display, window->handle, CWOverrideRedirect, &xswa); - XRaiseWindow(xfc->display, window->handle); + LogDynAndXChangeWindowAttributes(xfc->log, xfc->display, window->handle, + CWOverrideRedirect, &xswa); + LogDynAndXRaiseWindow(xfc->log, xfc->display, window->handle); xswa.override_redirect = False; - XChangeWindowAttributes(xfc->display, window->handle, CWOverrideRedirect, &xswa); + LogDynAndXChangeWindowAttributes(xfc->log, xfc->display, window->handle, + CWOverrideRedirect, &xswa); } /* if window is in maximized state, save and remove */ @@ -436,14 +438,14 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) DEBUG_X11("X window move and resize %dx%d@%dx%d", startX, startY, width, height); xf_ResizeDesktopWindow(xfc, window, WINPR_ASSERTING_INT_CAST(int, width), WINPR_ASSERTING_INT_CAST(int, height)); - XMoveWindow(xfc->display, window->handle, startX, startY); + LogDynAndXMoveWindow(xfc->log, xfc->display, window->handle, startX, startY); } else { xf_SetWindowDecorations(xfc, window->handle, window->decorations); xf_ResizeDesktopWindow(xfc, window, WINPR_ASSERTING_INT_CAST(int, width), WINPR_ASSERTING_INT_CAST(int, height)); - XMoveWindow(xfc->display, window->handle, startX, startY); + LogDynAndXMoveWindow(xfc->log, xfc->display, window->handle, startX, startY); if (xfc->fullscreenMonitors.top) { @@ -481,7 +483,7 @@ BOOL xf_GetWindowProperty(xfContext* xfc, Window window, Atom property, int leng if (property == None) return FALSE; - status = LogTagAndXGetWindowProperty(TAG, xfc->display, window, property, 0, length, False, + status = LogDynAndXGetWindowProperty(xfc->log, xfc->display, window, property, 0, length, False, AnyPropertyType, &actual_type, &actual_format, nitems, bytes, prop); @@ -594,15 +596,16 @@ void xf_SetWindowDecorations(xfContext* xfc, Window window, BOOL show) .inputMode = 0, .status = 0 }; WINPR_ASSERT(xfc); - LogTagAndXChangeProperty(TAG, xfc->display, window, xfc->MOTIF_WM_HINTS, xfc->MOTIF_WM_HINTS, - 32, PropModeReplace, (BYTE*)&hints, PROP_MOTIF_WM_HINTS_ELEMENTS); + LogDynAndXChangeProperty(xfc->log, xfc->display, window, xfc->MOTIF_WM_HINTS, + xfc->MOTIF_WM_HINTS, 32, PropModeReplace, (BYTE*)&hints, + PROP_MOTIF_WM_HINTS_ELEMENTS); } void xf_SetWindowUnlisted(xfContext* xfc, Window window) { WINPR_ASSERT(xfc); Atom window_state[] = { xfc->NET_WM_STATE_SKIP_PAGER, xfc->NET_WM_STATE_SKIP_TASKBAR }; - LogTagAndXChangeProperty(TAG, xfc->display, window, xfc->NET_WM_STATE, XA_ATOM, 32, + LogDynAndXChangeProperty(xfc->log, xfc->display, window, xfc->NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (BYTE*)window_state, 2); } @@ -615,8 +618,8 @@ static void xf_SetWindowPID(xfContext* xfc, Window window, pid_t pid) pid = getpid(); am_wm_pid = xfc->NET_WM_PID; - LogTagAndXChangeProperty(TAG, xfc->display, window, am_wm_pid, XA_CARDINAL, 32, PropModeReplace, - (BYTE*)&pid, 1); + LogDynAndXChangeProperty(xfc->log, xfc->display, window, am_wm_pid, XA_CARDINAL, 32, + PropModeReplace, (BYTE*)&pid, 1); } static const char* get_shm_id(void) @@ -629,17 +632,17 @@ static const char* get_shm_id(void) Window xf_CreateDummyWindow(xfContext* xfc) { - return XCreateWindow(xfc->display, RootWindowOfScreen(xfc->screen), - WINPR_ASSERTING_INT_CAST(int, xfc->workArea.x), - WINPR_ASSERTING_INT_CAST(int, xfc->workArea.y), 1, 1, 0, xfc->depth, - InputOutput, xfc->visual, - WINPR_ASSERTING_INT_CAST(uint32_t, xfc->attribs_mask), &xfc->attribs); + return LogDynAndXCreateWindow( + xfc->log, xfc->display, RootWindowOfScreen(xfc->screen), + WINPR_ASSERTING_INT_CAST(int, xfc->workArea.x), + WINPR_ASSERTING_INT_CAST(int, xfc->workArea.y), 1, 1, 0, xfc->depth, InputOutput, + xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->attribs_mask), &xfc->attribs); } void xf_DestroyDummyWindow(xfContext* xfc, Window window) { if (window) - XDestroyWindow(xfc->display, window); + LogDynAndXDestroyWindow(xfc->log, xfc->display, window); } xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int height) @@ -663,12 +666,12 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int heig window->is_transient = FALSE; WINPR_ASSERT(xfc->depth != 0); - window->handle = - XCreateWindow(xfc->display, RootWindowOfScreen(xfc->screen), - WINPR_ASSERTING_INT_CAST(int, xfc->workArea.x), - WINPR_ASSERTING_INT_CAST(int, xfc->workArea.y), xfc->workArea.width, - xfc->workArea.height, 0, xfc->depth, InputOutput, xfc->visual, - WINPR_ASSERTING_INT_CAST(uint32_t, xfc->attribs_mask), &xfc->attribs); + window->handle = LogDynAndXCreateWindow( + xfc->log, xfc->display, RootWindowOfScreen(xfc->screen), + WINPR_ASSERTING_INT_CAST(int, xfc->workArea.x), + WINPR_ASSERTING_INT_CAST(int, xfc->workArea.y), xfc->workArea.width, xfc->workArea.height, + 0, xfc->depth, InputOutput, xfc->visual, + WINPR_ASSERTING_INT_CAST(uint32_t, xfc->attribs_mask), &xfc->attribs); window->shmid = shm_open(get_shm_id(), (O_CREAT | O_RDWR), (S_IREAD | S_IWRITE)); if (window->shmid < 0) @@ -734,16 +737,16 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int heig if (xfc->grab_keyboard) input_mask |= EnterWindowMask | LeaveWindowMask; - LogTagAndXChangeProperty(TAG, xfc->display, window->handle, xfc->NET_WM_ICON, XA_CARDINAL, 32, - PropModeReplace, (BYTE*)xf_icon_prop, ARRAYSIZE(xf_icon_prop)); + LogDynAndXChangeProperty(xfc->log, xfc->display, window->handle, xfc->NET_WM_ICON, XA_CARDINAL, + 32, PropModeReplace, (BYTE*)xf_icon_prop, ARRAYSIZE(xf_icon_prop)); if (parentWindow) - XReparentWindow(xfc->display, window->handle, parentWindow, 0, 0); + LogDynAndXReparentWindow(xfc->log, xfc->display, window->handle, parentWindow, 0, 0); XSelectInput(xfc->display, window->handle, input_mask); - XClearWindow(xfc->display, window->handle); + LogDynAndXClearWindow(xfc->log, xfc->display, window->handle); xf_SetWindowTitleText(xfc, window->handle, name); - XMapWindow(xfc->display, window->handle); + LogDynAndXMapWindow(xfc->log, xfc->display, window->handle); xf_input_init(xfc, window->handle); /* @@ -762,16 +765,16 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int heig */ if (freerdp_settings_get_bool(settings, FreeRDP_RemoteApplicationMode)) { - XMoveWindow(xfc->display, window->handle, 0, 0); + LogDynAndXMoveWindow(xfc->log, xfc->display, window->handle, 0, 0); } else if ((freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosX) != UINT32_MAX) && (freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosY) != UINT32_MAX)) { - XMoveWindow(xfc->display, window->handle, - WINPR_ASSERTING_INT_CAST( - int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosX)), - WINPR_ASSERTING_INT_CAST( - int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosY))); + LogDynAndXMoveWindow(xfc->log, xfc->display, window->handle, + WINPR_ASSERTING_INT_CAST( + int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosX)), + WINPR_ASSERTING_INT_CAST( + int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosY))); } window->floatbar = xf_floatbar_new(xfc, window->handle, name, @@ -801,8 +804,9 @@ void xf_ResizeDesktopWindow(xfContext* xfc, xfWindow* window, int width, int hei size_hints->win_gravity = NorthWestGravity; size_hints->min_width = size_hints->min_height = 1; size_hints->max_width = size_hints->max_height = 16384; - XResizeWindow(xfc->display, window->handle, WINPR_ASSERTING_INT_CAST(uint32_t, width), - WINPR_ASSERTING_INT_CAST(uint32_t, height)); + LogDynAndXResizeWindow(xfc->log, xfc->display, window->handle, + WINPR_ASSERTING_INT_CAST(uint32_t, width), + WINPR_ASSERTING_INT_CAST(uint32_t, height)); #ifdef WITH_XRENDER if (!freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) && @@ -833,12 +837,12 @@ void xf_DestroyDesktopWindow(xfContext* xfc, xfWindow* window) xf_floatbar_free(window->floatbar); if (window->gc) - XFreeGC(xfc->display, window->gc); + LogDynAndXFreeGC(xfc->log, xfc->display, window->gc); if (window->handle) { - XUnmapWindow(xfc->display, window->handle); - XDestroyWindow(xfc->display, window->handle); + LogDynAndXUnmapWindow(xfc->log, xfc->display, window->handle); + LogDynAndXDestroyWindow(xfc->log, xfc->display, window->handle); } if (window->xfwin) @@ -908,11 +912,12 @@ void xf_SetWindowStyle(xfContext* xfc, xfAppWindow* appWindow, UINT32 style, UIN */ XSetWindowAttributes attrs = { 0 }; attrs.override_redirect = redirect ? True : False; - XChangeWindowAttributes(xfc->display, appWindow->handle, CWOverrideRedirect, &attrs); + LogDynAndXChangeWindowAttributes(xfc->log, xfc->display, appWindow->handle, + CWOverrideRedirect, &attrs); } - LogTagAndXChangeProperty(TAG, xfc->display, appWindow->handle, xfc->NET_WM_WINDOW_TYPE, XA_ATOM, - 32, PropModeReplace, (BYTE*)&window_type, 1); + LogDynAndXChangeProperty(xfc->log, xfc->display, appWindow->handle, xfc->NET_WM_WINDOW_TYPE, + XA_ATOM, 32, PropModeReplace, (BYTE*)&window_type, 1); const BOOL above = (ex_style & WS_EX_TOPMOST) != 0; const BOOL transient = (style & WS_CHILD) == 0; @@ -951,8 +956,8 @@ void xf_SetWindowActions(xfContext* xfc, xfAppWindow* appWindow) allowed_actions[6] = 0; } - XChangeProperty(xfc->display, appWindow->handle, xfc->NET_WM_ALLOWED_ACTIONS, XA_ATOM, 32, - PropModeReplace, (unsigned char*)&allowed_actions, 8); + LogDynAndXChangeProperty(xfc->log, xfc->display, appWindow->handle, xfc->NET_WM_ALLOWED_ACTIONS, + XA_ATOM, 32, PropModeReplace, (unsigned char*)&allowed_actions, 8); } void xf_SetWindowText(xfContext* xfc, xfAppWindow* appWindow, const char* name) @@ -1009,8 +1014,8 @@ int xf_AppWindowInit(xfContext* xfc, xfAppWindow* appWindow) xf_SetWindowStyle(xfc, appWindow, appWindow->dwStyle, appWindow->dwExStyle); xf_SetWindowPID(xfc, appWindow->handle, 0); xf_ShowWindow(xfc, appWindow, WINDOW_SHOW); - XClearWindow(xfc->display, appWindow->handle); - XMapWindow(xfc->display, appWindow->handle); + LogDynAndXClearWindow(xfc->log, xfc->display, appWindow->handle); + LogDynAndXMapWindow(xfc->log, xfc->display, appWindow->handle); /* Move doesn't seem to work until window is mapped. */ xf_MoveWindow(xfc, appWindow, appWindow->x, appWindow->y, appWindow->width, appWindow->height); xf_SetWindowText(xfc, appWindow, appWindow->title); @@ -1046,8 +1051,8 @@ BOOL xf_AppWindowCreate(xfContext* xfc, xfAppWindow* appWindow) appWindow->rail_ignore_configure = FALSE; WINPR_ASSERT(xfc->depth != 0); - appWindow->handle = XCreateWindow( - xfc->display, RootWindowOfScreen(xfc->screen), appWindow->x, appWindow->y, + appWindow->handle = LogDynAndXCreateWindow( + xfc->log, xfc->display, RootWindowOfScreen(xfc->screen), appWindow->x, appWindow->y, WINPR_ASSERTING_INT_CAST(uint32_t, appWindow->width), WINPR_ASSERTING_INT_CAST(uint32_t, appWindow->height), 0, xfc->depth, InputOutput, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->attribs_mask), &xfc->attribs); @@ -1055,7 +1060,8 @@ BOOL xf_AppWindowCreate(xfContext* xfc, xfAppWindow* appWindow) if (!appWindow->handle) return FALSE; - appWindow->gc = XCreateGC(xfc->display, appWindow->handle, GCGraphicsExposures, &gcv); + appWindow->gc = + LogDynAndXCreateGC(xfc->log, xfc->display, appWindow->handle, GCGraphicsExposures, &gcv); if (!xf_AppWindowResize(xfc, appWindow)) return FALSE; @@ -1197,11 +1203,11 @@ void xf_MoveWindow(xfContext* xfc, xfAppWindow* appWindow, int x, int y, int wid appWindow->height = height; if (resize) - XMoveResizeWindow(xfc->display, appWindow->handle, x, y, - WINPR_ASSERTING_INT_CAST(uint32_t, width), - WINPR_ASSERTING_INT_CAST(uint32_t, height)); + LogDynAndXMoveResizeWindow(xfc->log, xfc->display, appWindow->handle, x, y, + WINPR_ASSERTING_INT_CAST(uint32_t, width), + WINPR_ASSERTING_INT_CAST(uint32_t, height)); else - XMoveWindow(xfc->display, appWindow->handle, x, y); + LogDynAndXMoveWindow(xfc->log, xfc->display, appWindow->handle, x, y); xf_UpdateWindowArea(xfc, appWindow, 0, 0, width, height); } @@ -1214,7 +1220,7 @@ void xf_ShowWindow(xfContext* xfc, xfAppWindow* appWindow, BYTE state) switch (state) { case WINDOW_HIDE: - XWithdrawWindow(xfc->display, appWindow->handle, xfc->screen_number); + LogDynAndXWithdrawWindow(xfc->log, xfc->display, appWindow->handle, xfc->screen_number); break; case WINDOW_SHOW_MINIMIZED: @@ -1265,7 +1271,7 @@ void xf_ShowWindow(xfContext* xfc, xfAppWindow* appWindow, BYTE state) if (appWindow->is_transient) xf_SetWindowUnlisted(xfc, appWindow->handle); - XMapWindow(xfc->display, appWindow->handle); + LogDynAndXMapWindow(xfc->log, xfc->display, appWindow->handle); break; default: break; @@ -1389,17 +1395,17 @@ void xf_DestroyWindow(xfContext* xfc, xfAppWindow* appWindow) xfc->appWindow = NULL; if (appWindow->gc) - XFreeGC(xfc->display, appWindow->gc); + LogDynAndXFreeGC(xfc->log, xfc->display, appWindow->gc); if (appWindow->pixmap) - XFreePixmap(xfc->display, appWindow->pixmap); + LogDynAndXFreePixmap(xfc->log, xfc->display, appWindow->pixmap); xf_AppWindowDestroyImage(appWindow); if (appWindow->handle) { - XUnmapWindow(xfc->display, appWindow->handle); - XDestroyWindow(xfc->display, appWindow->handle); + LogDynAndXUnmapWindow(xfc->log, xfc->display, appWindow->handle); + LogDynAndXDestroyWindow(xfc->log, xfc->display, appWindow->handle); } if (appWindow->xfwin) @@ -1483,10 +1489,10 @@ UINT xf_AppUpdateWindowFromSurface(xfContext* xfc, gdiGfxSurface* surface) if (!appWindow->image) { WINPR_ASSERT(xfc->depth != 0); - appWindow->image = XCreateImage( - xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), ZPixmap, - 0, (char*)surface->data, surface->width, surface->height, xfc->scanline_pad, - WINPR_ASSERTING_INT_CAST(int, surface->scanline)); + appWindow->image = LogDynAndXCreateImage( + xfc->log, xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth), + ZPixmap, 0, (char*)surface->data, surface->width, surface->height, + xfc->scanline_pad, WINPR_ASSERTING_INT_CAST(int, surface->scanline)); if (!appWindow->image) { WLog_WARN(TAG, @@ -1535,13 +1541,13 @@ BOOL xf_AppWindowResize(xfContext* xfc, xfAppWindow* appWindow) WINPR_ASSERT(appWindow); if (appWindow->pixmap != 0) - XFreePixmap(xfc->display, appWindow->pixmap); + LogDynAndXFreePixmap(xfc->log, xfc->display, appWindow->pixmap); WINPR_ASSERT(xfc->depth != 0); - appWindow->pixmap = XCreatePixmap(xfc->display, xfc->drawable, - WINPR_ASSERTING_INT_CAST(uint32_t, appWindow->width), - WINPR_ASSERTING_INT_CAST(uint32_t, appWindow->height), - WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth)); + appWindow->pixmap = LogDynAndXCreatePixmap( + xfc->log, xfc->display, xfc->drawable, WINPR_ASSERTING_INT_CAST(uint32_t, appWindow->width), + WINPR_ASSERTING_INT_CAST(uint32_t, appWindow->height), + WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth)); xf_AppWindowDestroyImage(appWindow); return appWindow->pixmap != 0; @@ -1559,11 +1565,5 @@ void xf_XSetTransientForHint(xfContext* xfc, xfAppWindow* window) if (!parent) return; - const int rc = XSetTransientForHint(xfc->display, window->handle, parent->handle); - if (rc) - { - char buffer[128] = { 0 }; - WLog_WARN(TAG, "XSetTransientForHint [%d]{%s}", rc, - x11_error_to_string(xfc, rc, buffer, sizeof(buffer))); - } + (void)LogDynAndXSetTransientForHint(xfc->log, xfc->display, window->handle, parent->handle); }