2023-03-01 18:01:08 +03:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* X11 helper utilities
|
|
|
|
*
|
|
|
|
* Copyright 2023 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyringht 2023 Thincast Technologies GmbH
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2024-07-22 13:29:18 +03:00
|
|
|
#include <string.h>
|
2023-03-01 18:17:03 +03:00
|
|
|
#include <winpr/assert.h>
|
2024-07-22 13:29:18 +03:00
|
|
|
#include <winpr/wtypes.h>
|
2023-03-01 18:17:03 +03:00
|
|
|
|
2023-03-01 18:01:08 +03:00
|
|
|
#include "xf_utils.h"
|
|
|
|
|
2023-03-06 15:54:23 +03:00
|
|
|
static const DWORD log_level = WLOG_TRACE;
|
2023-03-01 18:17:03 +03:00
|
|
|
|
2023-03-01 18:32:13 +03:00
|
|
|
static void write_log(wLog* log, DWORD level, const char* fname, const char* fkt, size_t line, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, line);
|
|
|
|
WLog_PrintMessageVA(log, WLOG_MESSAGE_TEXT, level, line, fname, fkt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2024-06-28 10:16:48 +03:00
|
|
|
char* Safe_XGetAtomName(wLog* log, Display* display, Atom atom)
|
2023-03-01 18:52:31 +03:00
|
|
|
{
|
2024-06-28 10:16:48 +03:00
|
|
|
WLog_Print(log, log_level, "XGetAtomName(0x%08" PRIx32 ")", atom);
|
2023-03-01 18:52:31 +03:00
|
|
|
if (atom == None)
|
|
|
|
return strdup("Atom_None");
|
|
|
|
return XGetAtomName(display, atom);
|
|
|
|
}
|
|
|
|
|
2023-03-01 18:32:13 +03:00
|
|
|
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)
|
2023-03-01 18:01:08 +03:00
|
|
|
{
|
|
|
|
wLog* log = WLog_Get(tag);
|
2023-03-01 18:32:13 +03:00
|
|
|
return LogDynAndXChangeProperty_ex(log, file, fkt, line, display, w, property, type, format,
|
|
|
|
mode, data, nelements);
|
2023-03-01 18:01:08 +03:00
|
|
|
}
|
|
|
|
|
2023-03-01 18:32:13 +03:00
|
|
|
int LogDynAndXChangeProperty_ex(wLog* log, 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)
|
2023-03-01 18:01:08 +03:00
|
|
|
{
|
2023-03-06 15:54:23 +03:00
|
|
|
if (WLog_IsLevelActive(log, log_level))
|
2023-03-01 18:01:08 +03:00
|
|
|
{
|
2024-06-28 10:16:48 +03:00
|
|
|
char* propstr = Safe_XGetAtomName(log, display, property);
|
|
|
|
char* typestr = Safe_XGetAtomName(log, display, type);
|
2023-03-06 15:54:23 +03:00
|
|
|
write_log(log, log_level, file, fkt, line,
|
2023-03-01 18:32:13 +03:00
|
|
|
"XChangeProperty(%p, %d, %s [%d], %s [%d], %d, %d, %p, %d)", display, w, propstr,
|
|
|
|
property, typestr, type, format, mode, data, nelements);
|
2023-03-01 18:01:08 +03:00
|
|
|
XFree(propstr);
|
|
|
|
XFree(typestr);
|
|
|
|
}
|
|
|
|
return XChangeProperty(display, w, property, type, format, mode, data, nelements);
|
|
|
|
}
|
2023-03-01 18:17:03 +03:00
|
|
|
|
2023-03-01 18:32:13 +03:00
|
|
|
int LogTagAndXDeleteProperty_ex(const char* tag, const char* file, const char* fkt, size_t line,
|
|
|
|
Display* display, Window w, Atom property)
|
2023-03-01 18:17:03 +03:00
|
|
|
{
|
|
|
|
wLog* log = WLog_Get(tag);
|
2023-03-01 18:32:13 +03:00
|
|
|
return LogDynAndXDeleteProperty_ex(log, file, fkt, line, display, w, property);
|
2023-03-01 18:17:03 +03:00
|
|
|
}
|
|
|
|
|
2023-03-01 18:32:13 +03:00
|
|
|
int LogDynAndXDeleteProperty_ex(wLog* log, const char* file, const char* fkt, size_t line,
|
|
|
|
Display* display, Window w, Atom property)
|
2023-03-01 18:17:03 +03:00
|
|
|
{
|
2023-03-06 15:54:23 +03:00
|
|
|
if (WLog_IsLevelActive(log, log_level))
|
2023-03-01 18:17:03 +03:00
|
|
|
{
|
2024-06-28 10:16:48 +03:00
|
|
|
char* propstr = Safe_XGetAtomName(log, display, property);
|
2023-03-06 15:54:23 +03:00
|
|
|
write_log(log, log_level, file, fkt, line, "XDeleteProperty(%p, %d, %s [%d])", display, w,
|
2023-03-01 18:32:13 +03:00
|
|
|
propstr, property);
|
2023-03-01 18:17:03 +03:00
|
|
|
XFree(propstr);
|
|
|
|
}
|
|
|
|
return XDeleteProperty(display, w, property);
|
|
|
|
}
|
2023-03-01 18:25:19 +03:00
|
|
|
|
2024-07-17 12:05:57 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (WLog_IsLevelActive(log, log_level))
|
|
|
|
{
|
|
|
|
char* selectstr = Safe_XGetAtomName(log, display, selection);
|
|
|
|
char* targetstr = Safe_XGetAtomName(log, display, target);
|
|
|
|
char* propstr = Safe_XGetAtomName(log, display, property);
|
|
|
|
write_log(log, log_level, file, fkt, line,
|
|
|
|
"XConvertSelection(%p, %s [%d], %s [%d], %s [%d], %d, %lu)", display, selectstr,
|
|
|
|
selection, targetstr, target, propstr, property, requestor, time);
|
|
|
|
XFree(propstr);
|
|
|
|
XFree(targetstr);
|
|
|
|
XFree(selectstr);
|
|
|
|
}
|
|
|
|
return XConvertSelection(display, selection, target, property, requestor, time);
|
|
|
|
}
|
|
|
|
|
2023-03-01 18:32:13 +03:00
|
|
|
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)
|
2023-03-01 18:25:19 +03:00
|
|
|
{
|
|
|
|
wLog* log = WLog_Get(tag);
|
2023-03-01 18:32:13 +03:00
|
|
|
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);
|
2023-03-01 18:25:19 +03:00
|
|
|
}
|
|
|
|
|
2023-03-01 18:32:13 +03:00
|
|
|
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, 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)
|
2023-03-01 18:25:19 +03:00
|
|
|
{
|
2023-03-06 15:54:23 +03:00
|
|
|
if (WLog_IsLevelActive(log, log_level))
|
2023-03-01 18:25:19 +03:00
|
|
|
{
|
2024-06-28 10:16:48 +03:00
|
|
|
char* propstr = Safe_XGetAtomName(log, display, property);
|
|
|
|
char* req_type_str = Safe_XGetAtomName(log, display, req_type);
|
2023-03-06 15:54:23 +03:00
|
|
|
write_log(log, log_level, file, fkt, line,
|
2023-03-01 18:32:13 +03:00
|
|
|
"XGetWindowProperty(%p, %d, %s [%d], %ld, %ld, %d, %s [%d], %p, %p, %p, %p, %p)",
|
|
|
|
display, w, propstr, property, long_offset, long_length, delete, req_type_str,
|
|
|
|
req_type, actual_type_return, actual_format_return, nitems_return,
|
|
|
|
bytes_after_return, prop_return);
|
2023-03-01 18:25:19 +03:00
|
|
|
XFree(propstr);
|
|
|
|
XFree(req_type_str);
|
|
|
|
}
|
|
|
|
return XGetWindowProperty(display, w, property, long_offset, long_length, delete, req_type,
|
|
|
|
actual_type_return, actual_format_return, nitems_return,
|
|
|
|
bytes_after_return, prop_return);
|
|
|
|
}
|
2024-07-22 13:29:18 +03:00
|
|
|
|
|
|
|
BOOL IsGnome(void)
|
|
|
|
{
|
|
|
|
char* env = getenv("DESKTOP_SESSION");
|
|
|
|
return (env != NULL && strcmp(env, "gnome") == 0);
|
|
|
|
}
|