From 96268d7dc5a3cbe42340915e19c4cd569031e88e Mon Sep 17 00:00:00 2001 From: Paul Manias Date: Mon, 1 Apr 2024 21:32:50 +0100 Subject: [PATCH] Fixed Linux build issues --- CMakeLists.txt | 5 - docs/xml/modules/display.xml | 6 + docs/xml/modules/fluid.xml | 4 +- docs/xml/modules/xrandr.xml | 4 +- include/parasol/modules/display.h | 6 + include/parasol/modules/fluid.h | 6 +- include/parasol/modules/xrandr.h | 24 ++- src/audio/alsa.cpp | 8 +- src/audio/class_audio.cpp | 2 +- src/audio/class_sound.cpp | 18 +- src/core/CMakeLists.txt | 4 - src/core/classes/class_file.cpp | 18 +- src/core/classes/class_task.cpp | 10 +- src/core/core.cpp | 2 +- src/core/lib_filesystem.cpp | 16 +- src/core/lib_functions.cpp | 16 +- src/core/lib_messages.cpp | 6 +- src/core/lib_objects.cpp | 4 - src/core/static_modules.cpp | 5 - src/core/tests/memory_locking.cpp | 14 +- src/core/tests/object_locking.cpp | 14 +- src/display/CMakeLists.txt | 2 +- src/display/class_bitmap.cpp | 6 +- src/display/class_display.cpp | 22 +- src/display/class_pointer.cpp | 10 +- src/display/defs.h | 12 +- src/display/display-driver.cpp | 116 +++++++++-- src/display/display.fdl | 6 + src/display/idl.h | 2 +- src/display/lib_bitmap.cpp | 2 +- src/display/lib_cursor.cpp | 9 +- src/display/x11/handlers.cpp | 24 +-- src/display/x11/xrandr.cpp | 127 ++++++++++++ src/fluid/fluid_class.cpp | 2 +- src/link/init-unix.cpp | 8 +- src/xrandr/CMakeLists.txt | 26 --- src/xrandr/module_def.c | 21 -- src/xrandr/xrandr.cpp | 333 ------------------------------ src/xrandr/xrandr.fdl | 17 -- 39 files changed, 394 insertions(+), 543 deletions(-) create mode 100644 src/display/x11/xrandr.cpp delete mode 100644 src/xrandr/CMakeLists.txt delete mode 100644 src/xrandr/module_def.c delete mode 100644 src/xrandr/xrandr.cpp delete mode 100644 src/xrandr/xrandr.fdl diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cb2dddc0..286cc38a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -550,11 +550,6 @@ if (NOT DISABLE_VECTOR AND NOT DISABLE_DISPLAY AND NOT DISABLE_FONT) list (APPEND LIB_LIST vector) endif () -if (X11_Xrandr_FOUND) - add_subdirectory (src/xrandr) - list (APPEND LIB_LIST xrandr) -endif () - list (APPEND LIB_LIST fluid json jpeg xml) add_subdirectory (src/link) diff --git a/docs/xml/modules/display.xml b/docs/xml/modules/display.xml index 209e71a6d..af69f0b15 100644 --- a/docs/xml/modules/display.xml +++ b/docs/xml/modules/display.xml @@ -1238,5 +1238,11 @@ Alpha = CFUnpackAlpha(Format,Colour) Line width of the bitmap, in bytes + + Horizontal + Vertical + bit depth + + diff --git a/docs/xml/modules/fluid.xml b/docs/xml/modules/fluid.xml index a805e6b0f..59f5d58b5 100644 --- a/docs/xml/modules/fluid.xml +++ b/docs/xml/modules/fluid.xml @@ -15,7 +15,7 @@ SetVariable Sets any variable in a loaded Fluid script. - ERROR flSetVariable(OBJECTPTR Script, CSTRING Name, LONG Type, ...) + ERR flSetVariable(OBJECTPTR Script, CSTRING Name, LONG Type, ...) Pointer to a Fluid script. The name of the variable to set. @@ -25,7 +25,7 @@

The SetVariable() function provides a method for setting global variables in a Fluid script prior to execution of that script. If the script is cached, the variable settings will be available on the next activation.

- + Operation successful. Invalid arguments passed to function. The object structure is corrupt or has not been initialised. diff --git a/docs/xml/modules/xrandr.xml b/docs/xml/modules/xrandr.xml index 1edc0b615..d8f4edd06 100644 --- a/docs/xml/modules/xrandr.xml +++ b/docs/xml/modules/xrandr.xml @@ -36,7 +36,7 @@ SetDisplayMode Change the width and height of the display. - ERROR xrSetDisplayMode(LONG * Width, LONG * Height) + ERR xrSetDisplayMode(LONG * Width, LONG * Height) The required width of the display. The required height of the display. @@ -44,7 +44,7 @@

This function changes the width and height of the display to that indicated by the Width and Height parameters. If the requested size does not match a known mode, the closest matching mode will be chosen.

- + Operation successful.
diff --git a/include/parasol/modules/display.h b/include/parasol/modules/display.h index 416440e49..bb7aef25f 100644 --- a/include/parasol/modules/display.h +++ b/include/parasol/modules/display.h @@ -417,6 +417,12 @@ struct SurfaceCoords { LONG AbsY; // Absolute Y }; +struct xrMode { + LONG Width; // Horizontal + LONG Height; // Vertical + LONG Depth; // bit depth +}; + typedef struct PixelFormat { UBYTE RedShift; // Right shift value UBYTE GreenShift; // Green shift value diff --git a/include/parasol/modules/fluid.h b/include/parasol/modules/fluid.h index 9f39ae4e1..8973d2424 100644 --- a/include/parasol/modules/fluid.h +++ b/include/parasol/modules/fluid.h @@ -16,17 +16,17 @@ struct FluidBase { #ifndef PARASOL_STATIC - ERROR (*_SetVariable)(OBJECTPTR Script, CSTRING Name, LONG Type, ...); + ERR (*_SetVariable)(OBJECTPTR Script, CSTRING Name, LONG Type, ...); #endif // PARASOL_STATIC }; #ifndef PRV_FLUID_MODULE #ifndef PARASOL_STATIC extern struct FluidBase *FluidBase; -template ERROR flSetVariable(OBJECTPTR Script, CSTRING Name, LONG Type, Args... Tags) { return FluidBase->_SetVariable(Script,Name,Type,Tags...); } +template ERR flSetVariable(OBJECTPTR Script, CSTRING Name, LONG Type, Args... Tags) { return FluidBase->_SetVariable(Script,Name,Type,Tags...); } #else extern "C" { -extern ERROR flSetVariable(OBJECTPTR Script, CSTRING Name, LONG Type, ...); +extern ERR flSetVariable(OBJECTPTR Script, CSTRING Name, LONG Type, ...); } #endif // PARASOL_STATIC #endif diff --git a/include/parasol/modules/xrandr.h b/include/parasol/modules/xrandr.h index 97395bda7..645c8068b 100644 --- a/include/parasol/modules/xrandr.h +++ b/include/parasol/modules/xrandr.h @@ -8,21 +8,39 @@ #define MODVERSION_XRANDR (1) -extern struct XRandRBase *XRandRBase; +#ifdef PARASOL_STATIC +#define JUMPTABLE_XRANDR static struct XRandRBase *XRandRBase; +#else +#define JUMPTABLE_XRANDR struct XRandRBase *XRandRBase; +#endif + struct XRandRBase { - ERROR (*_SetDisplayMode)(LONG * Width, LONG * Height); +#ifndef PARASOL_STATIC + ERR (*_SetDisplayMode)(LONG * Width, LONG * Height); LONG (*_Notify)(APTR XEvent); void (*_SelectInput)(LONG Window); LONG (*_GetDisplayTotal)(void); APTR (*_GetDisplayMode)(LONG Index); +#endif // PARASOL_STATIC }; #ifndef PRV_XRANDR_MODULE -inline ERROR xrSetDisplayMode(LONG * Width, LONG * Height) { return XRandRBase->_SetDisplayMode(Width,Height); } +#ifndef PARASOL_STATIC +extern struct XRandRBase *XRandRBase; +inline ERR xrSetDisplayMode(LONG * Width, LONG * Height) { return XRandRBase->_SetDisplayMode(Width,Height); } inline LONG xrNotify(APTR XEvent) { return XRandRBase->_Notify(XEvent); } inline void xrSelectInput(LONG Window) { return XRandRBase->_SelectInput(Window); } inline LONG xrGetDisplayTotal(void) { return XRandRBase->_GetDisplayTotal(); } inline APTR xrGetDisplayMode(LONG Index) { return XRandRBase->_GetDisplayMode(Index); } +#else +extern "C" { +extern ERR xrSetDisplayMode(LONG * Width, LONG * Height); +extern LONG xrNotify(APTR XEvent); +extern void xrSelectInput(LONG Window); +extern LONG xrGetDisplayTotal(void); +extern APTR xrGetDisplayMode(LONG Index); +} +#endif // PARASOL_STATIC #endif struct xrMode { diff --git a/src/audio/alsa.cpp b/src/audio/alsa.cpp index b343235e9..e7f6bf7b2 100644 --- a/src/audio/alsa.cpp +++ b/src/audio/alsa.cpp @@ -65,7 +65,7 @@ static ERR init_audio(extAudio *Self) cardid = (STRING)snd_ctl_card_info_get_id(info); cardname = (STRING)snd_ctl_card_info_get_name(info); - if (!StrMatch(cardid, pcm_name.c_str())) { + if (StrMatch(cardid, pcm_name.c_str()) IS ERR::Okay) { pcm_name = name; snd_ctl_close(ctlhandle); break; @@ -81,7 +81,7 @@ static ERR init_audio(extAudio *Self) // Check if the default ALSA device is a real sound card. We don't want to use it if it's a modem or other // unexpected device. - if (!StrMatch("default", pcm_name.c_str())) { + if (StrMatch("default", pcm_name.c_str()) IS ERR::Okay) { // If there are no sound devices in the system, abort LONG card = -1; @@ -106,7 +106,7 @@ static ERR init_audio(extAudio *Self) log.msg("Identified card %s, name %s", cardid, cardname); - if (!StrMatch("modem", cardid)) goto next_card; + if (StrMatch("modem", cardid) IS ERR::Okay) goto next_card; snd_mixer_t *mixhandle; if ((err = snd_mixer_open(&mixhandle, 0)) >= 0) { @@ -410,7 +410,7 @@ static ERR init_audio(extAudio *Self) if (Self->AudioBuffer) { FreeResource(Self->AudioBuffer); Self->AudioBuffer = NULL; } - if (!AllocMemory(Self->AudioBufferSize, MEM::DATA, &Self->AudioBuffer)) { + if (AllocMemory(Self->AudioBufferSize, MEM::DATA, &Self->AudioBuffer) IS ERR::Okay) { #ifdef _DEBUG snd_pcm_hw_params_dump(hwparams, log); #endif diff --git a/src/audio/class_audio.cpp b/src/audio/class_audio.cpp index cf92e7dd3..a309963f1 100644 --- a/src/audio/class_audio.cpp +++ b/src/audio/class_audio.cpp @@ -850,7 +850,7 @@ static ERR AUDIO_SetVolume(extAudio *Self, struct sndSetVolume *Args) if (Args->Name) { for (index=0; index < std::ssize(Self->Volumes); index++) { - if (!StrMatch(Args->Name, Self->Volumes[index].Name.c_str())) break; + if (StrMatch(Args->Name, Self->Volumes[index].Name.c_str()) IS ERR::Okay) break; } if (index IS (LONG)Self->Volumes.size()) return ERR::Search; diff --git a/src/audio/class_sound.cpp b/src/audio/class_sound.cpp index 9113c3279..13a27587e 100644 --- a/src/audio/class_sound.cpp +++ b/src/audio/class_sound.cpp @@ -472,10 +472,10 @@ static ERR SOUND_Activate(extSound *Self, APTR Void) sndMixStop(*audio, Self->ChannelIndex); if (sndMixSample(*audio, Self->ChannelIndex, Self->Handle) IS ERR::Okay) { - if (sndMixVolume(*audio, Self->ChannelIndex, Self->Volume)) return log.warning(ERR::Failed); - if (sndMixPan(*audio, Self->ChannelIndex, Self->Pan)) return log.warning(ERR::Failed); - if (sndMixFrequency(*audio, Self->ChannelIndex, Self->Playback)) return log.warning(ERR::Failed); - if (sndMixPlay(*audio, Self->ChannelIndex, Self->Position)) return log.warning(ERR::Failed); + if (sndMixVolume(*audio, Self->ChannelIndex, Self->Volume) != ERR::Okay) return log.warning(ERR::Failed); + if (sndMixPan(*audio, Self->ChannelIndex, Self->Pan) != ERR::Okay) return log.warning(ERR::Failed); + if (sndMixFrequency(*audio, Self->ChannelIndex, Self->Playback) != ERR::Okay) return log.warning(ERR::Failed); + if (sndMixPlay(*audio, Self->ChannelIndex, Self->Position) != ERR::Okay) return log.warning(ERR::Failed); return ERR::Okay; } @@ -774,7 +774,7 @@ static ERR SOUND_Init(extSound *Self, APTR Void) ERR error; if (!Self->AudioID) { - if ((error = snd_init_audio(Self))) return error; + if ((error = snd_init_audio(Self)) != ERR::Okay) return error; } // Open channels for sound sample playback. @@ -782,7 +782,7 @@ static ERR SOUND_Init(extSound *Self, APTR Void) if (!(Self->ChannelIndex = glSoundChannels[Self->AudioID])) { pf::ScopedObjectLock audio(Self->AudioID, 3000); if (audio.granted()) { - if (!sndOpenChannels(*audio, audio->MaxChannels, &Self->ChannelIndex)) { + if (sndOpenChannels(*audio, audio->MaxChannels, &Self->ChannelIndex) IS ERR::Okay) { glSoundChannels[Self->AudioID] = Self->ChannelIndex; } else { @@ -825,11 +825,11 @@ static ERR SOUND_Init(extSound *Self, APTR Void) // Read the FMT header Self->File->seek(12, SEEK::START); - if (flReadLE(Self->File, &id)) return ERR::Read; // Contains the characters "fmt " - if (flReadLE(Self->File, &len)) return ERR::Read; // Length of data in this chunk + if (flReadLE(Self->File, &id) != ERR::Okay) return ERR::Read; // Contains the characters "fmt " + if (flReadLE(Self->File, &len) != ERR::Okay) return ERR::Read; // Length of data in this chunk WAVEFormat WAVE; - if (Self->File->read(&WAVE, len, &result) or (result < len)) { + if ((Self->File->read(&WAVE, len, &result) != ERR::Okay) or (result < len)) { log.warning("Failed to read WAVE format header (got %d, expected %d)", result, len); return ERR::Read; } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 92e1c5f4f..e71c73763 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -139,10 +139,6 @@ target_link_libraries (core PRIVATE zlib) if (PARASOL_STATIC) target_link_libraries (core PRIVATE ${LIB_LIST}) - - if (X11_Xrandr_FOUND) - target_link_libraries (core PRIVATE xrandr) - endif () endif () if (WIN32) diff --git a/src/core/classes/class_file.cpp b/src/core/classes/class_file.cpp index 295b91553..5e2107158 100644 --- a/src/core/classes/class_file.cpp +++ b/src/core/classes/class_file.cpp @@ -141,7 +141,7 @@ static ERR FILE_Activate(extFile *Self, APTR Void) if ((Self->Flags & FL::DEVICE) != FL::NIL) { openflags |= O_NOCTTY; // Prevent device from becoming the controlling terminal } - else if (!StrCompare("/dev/", path, 0)) { + else if (StrCompare("/dev/", path, 0) IS ERR::Okay) { log.warning("Opening devices not permitted without the DEVICE flag."); return ERR::NoPermission; } @@ -1374,7 +1374,7 @@ static ERR FILE_SetDate(extFile *Self, struct flSetDate *Args) #elif __unix__ CSTRING path; - if (!GET_ResolvedPath(Self, &path)) { + if (GET_ResolvedPath(Self, &path) IS ERR::Okay) { struct tm time; time.tm_year = Args->Year - 1900; time.tm_mon = Args->Month - 1; @@ -1546,7 +1546,7 @@ static ERR FILE_Watch(extFile *Self, struct flWatch *Args) } else error = log.warning(ERR::SystemCall); - if (error) return error; + if (error != ERR::Okay) return error; } #endif @@ -1559,7 +1559,7 @@ static ERR FILE_Watch(extFile *Self, struct flWatch *Args) #ifdef _WIN32 if (AllocMemory(sizeof(rkWatchPath) + winGetWatchBufferSize(), MEM::DATA, (APTR *)&Self->prvWatch, NULL) IS ERR::Okay) { #else - if (!AllocMemory(sizeof(rkWatchPath), MEM::DATA, (APTR *)&Self->prvWatch, NULL)) { + if (AllocMemory(sizeof(rkWatchPath), MEM::DATA, (APTR *)&Self->prvWatch, NULL) IS ERR::Okay) { #endif Self->prvWatch->VirtualID = vd->VirtualID; Self->prvWatch->Routine = *Args->Callback; @@ -1886,7 +1886,7 @@ ERR SET_Date(extFile *Self, DateTime *Date) CSTRING path; time_t datetime; struct utimbuf utm; - if (!GET_ResolvedPath(Self, &path)) { + if (GET_ResolvedPath(Self, &path) IS ERR::Okay) { struct tm time; time.tm_year = Date->Year - 1900; time.tm_mon = Date->Month - 1; @@ -2152,7 +2152,7 @@ static ERR GET_Link(extFile *Self, STRING *Value) *Value = NULL; if ((Self->Flags & FL::LINK) != FL::NIL) { - if (!ResolvePath(Self->Path, RSF::NIL, &path)) { + if (ResolvePath(Self->Path, RSF::NIL, &path) IS ERR::Okay) { LONG i = StrLength(path); if (path[i-1] IS '/') path[i-1] = 0; if (((i = readlink(path, buffer, sizeof(buffer)-1)) > 0) and ((size_t)i < sizeof(buffer)-1)) { @@ -2320,7 +2320,7 @@ static ERR GET_Permissions(extFile *Self, PERMIT *Value) // process could always have changed the permission flags. CSTRING path; - if (!GET_ResolvedPath(Self, &path)) { + if (GET_ResolvedPath(Self, &path) IS ERR::Okay) { LONG i = StrLength(path); while ((i >= 0) and (path[i] != '/') and (path[i] != ':') and (path[i] != '\\')) i--; if (path[i+1] IS '.') Self->Permissions = PERMIT::HIDDEN; @@ -2408,7 +2408,7 @@ static ERR set_permissions(extFile *Self, PERMIT Permissions) // File represents a folder CSTRING path; - if (!GET_ResolvedPath(Self, &path)) { + if (GET_ResolvedPath(Self, &path) IS ERR::Okay) { LONG flags = 0; if ((Permissions & PERMIT::READ) != PERMIT::NIL) flags |= S_IRUSR; if ((Permissions & PERMIT::WRITE) != PERMIT::NIL) flags |= S_IWUSR; @@ -2609,7 +2609,7 @@ static ERR SET_Size(extFile *Self, LARGE Size) // Seek past the file boundary and write a single byte to expand the file. Yes, it's legal and works. ERR error; - if (!(error = GET_ResolvedPath(Self, &path))) { + if ((error = GET_ResolvedPath(Self, &path)) IS ERR::Okay) { struct statfs fstat; if (statfs(path, &fstat) != -1) { if (Size < (LARGE)fstat.f_bavail * (LARGE)fstat.f_bsize) { diff --git a/src/core/classes/class_task.cpp b/src/core/classes/class_task.cpp index 3db64c329..1847b94b2 100644 --- a/src/core/classes/class_task.cpp +++ b/src/core/classes/class_task.cpp @@ -843,7 +843,7 @@ static ERR TASK_Activate(extTask *Self, APTR Void) buffer[i++] = ' '; if (!path) path = Self->Location; - if (!ResolvePath(path, RSF::APPROXIMATE|RSF::PATH, &path)) { + if (ResolvePath(path, RSF::APPROXIMATE|RSF::PATH, &path) IS ERR::Okay) { for (j=0; (path[j]) and ((size_t)i < sizeof(buffer)-1);) buffer[i++] = path[j++]; FreeResource(path); } @@ -860,7 +860,7 @@ static ERR TASK_Activate(extTask *Self, APTR Void) // Resolve the location of the executable (may contain an volume) and copy it to the command line buffer. - if (!ResolvePath(Self->Location, RSF::APPROXIMATE|RSF::PATH, &path)) { + if (ResolvePath(Self->Location, RSF::APPROXIMATE|RSF::PATH, &path) IS ERR::Okay) { for (j=0; (path[j]) and ((size_t)i < sizeof(buffer)-1);) buffer[i++] = path[j++]; buffer[i] = 0; FreeResource(path); @@ -1423,7 +1423,7 @@ static ERR TASK_Init(extTask *Self, APTR Void) for (len=0; buffer[len]; len++); while ((len > 1) and (buffer[len-1] != '/') and (buffer[len-1] != '\\') and (buffer[len-1] != ':')) len--; - if (!AllocMemory(len+1, MEM::STRING|MEM::NO_CLEAR, (void **)&Self->ProcessPath, NULL)) { + if (AllocMemory(len+1, MEM::STRING|MEM::NO_CLEAR, (void **)&Self->ProcessPath, NULL) IS ERR::Okay) { for (i=0; i < len; i++) Self->ProcessPath[i] = buffer[i]; Self->ProcessPath[i] = 0; } @@ -1433,7 +1433,7 @@ static ERR TASK_Init(extTask *Self, APTR Void) if (getcwd(buffer, sizeof(buffer))) { if (Self->Path) { FreeResource(Self->Path); Self->Path = NULL; } for (len=0; buffer[len]; len++); - if (!AllocMemory(len+2, MEM::STRING|MEM::NO_CLEAR, (void **)&Self->Path, NULL)) { + if (AllocMemory(len+2, MEM::STRING|MEM::NO_CLEAR, (void **)&Self->Path, NULL) IS ERR::Okay) { for (i=0; buffer[i]; i++) Self->Path[i] = buffer[i]; Self->Path[i++] = '/'; Self->Path[i] = 0; @@ -2089,7 +2089,7 @@ static ERR SET_Path(extTask *Self, CSTRING Value) #ifdef __unix__ STRING path; - if (!ResolvePath(new_path, RSF::NO_FILE_CHECK, &path)) { + if (ResolvePath(new_path, RSF::NO_FILE_CHECK, &path) IS ERR::Okay) { if (chdir(path)) { error = ERR::InvalidPath; log.msg("Failed to switch current path to: %s", path); diff --git a/src/core/core.cpp b/src/core/core.cpp index 2fb4c9251..3ae86ea79 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -1268,7 +1268,7 @@ static ERR init_volumes(const std::forward_list &Volumes) if (size < 1) size = 8192; STRING buffer; - if (!AllocMemory(size, MEM::NO_CLEAR, (APTR *)&buffer, NULL)) { + if (AllocMemory(size, MEM::NO_CLEAR, (APTR *)&buffer, NULL) IS ERR::Okay) { size = read(file, buffer, size); buffer[size] = 0; diff --git a/src/core/lib_filesystem.cpp b/src/core/lib_filesystem.cpp index 610027a4d..46d615407 100644 --- a/src/core/lib_filesystem.cpp +++ b/src/core/lib_filesystem.cpp @@ -674,8 +674,8 @@ ERR CreateLink(CSTRING From, CSTRING To) log.branch("From: %.40s, To: %s", From, To); STRING src, dest; - if (!ResolvePath(From, RSF::NO_FILE_CHECK, &src)) { - if (!ResolvePath(To, RSF::NO_FILE_CHECK, &dest)) { + if (ResolvePath(From, RSF::NO_FILE_CHECK, &src) IS ERR::Okay) { + if (ResolvePath(To, RSF::NO_FILE_CHECK, &dest) IS ERR::Okay) { auto err = symlink(dest, src); FreeResource(dest); FreeResource(src); @@ -1157,7 +1157,7 @@ ERR ReadFileToBuffer(CSTRING Path, APTR Buffer, LONG BufferSize, LONG *BytesRead else error = ERR::FileNotFound; #ifdef _DEBUG - if (error) log.warning(error); + if (error != ERR::Okay) log.warning(error); #endif return error; @@ -1380,7 +1380,7 @@ ERR findfile(STRING Path) if ((entry->d_name[0] IS '.') and (entry->d_name[1] IS 0)) continue; if ((entry->d_name[0] IS '.') and (entry->d_name[1] IS '.') and (entry->d_name[2] IS 0)) continue; - if ((!StrCompare(Path+len, entry->d_name)) and + if ((StrCompare(Path+len, entry->d_name) IS ERR::Okay) and ((entry->d_name[namelen] IS '.') or (!entry->d_name[namelen]))) { StrCopy(entry->d_name, Path+len); @@ -1835,7 +1835,7 @@ ERR fs_copy(CSTRING Source, CSTRING Dest, FUNCTION *Callback, BYTE Move) error = ERR::Read; } - if ((Move) and (!error)) { // Delete the source + if ((Move) and (error IS ERR::Okay)) { // Delete the source error = DeleteFile(src, NULL); } @@ -2084,7 +2084,7 @@ ERR fs_copy(CSTRING Source, CSTRING Dest, FUNCTION *Callback, BYTE Move) // If the sticky bits were set, we need to set them again because Linux sneakily turns off those bits when a // file is written (for security reasons). - if ((!error) and (permissions & (S_ISUID|S_ISGID))) { + if ((error IS ERR::Okay) and (permissions & (S_ISUID|S_ISGID))) { fchmod(dhandle, permissions); } #endif @@ -2831,7 +2831,7 @@ ERR fs_getdeviceinfo(CSTRING Path, objStorageDevice *Info) } else error = ERR::Okay; - if (!error) { + if (error IS ERR::Okay) { struct statfs fstat; LONG result = statfs(location, &fstat); FreeResource(location); @@ -3102,7 +3102,7 @@ ERR delete_tree(STRING Path, LONG Size, FUNCTION *Callback, FileFeedback *Feedba Path[len] = 0; - if ((!error) and (rmdir(Path))) { + if ((error IS ERR::Okay) and (rmdir(Path))) { log.error("rmdir(%s) error: %s", Path, strerror(errno)); return convert_errno(errno, ERR::SystemCall); } diff --git a/src/core/lib_functions.cpp b/src/core/lib_functions.cpp index 3b61caebf..dcf25c83d 100644 --- a/src/core/lib_functions.cpp +++ b/src/core/lib_functions.cpp @@ -450,16 +450,16 @@ LARGE GetResource(RES Resource) char str[2048]; LONG result; LARGE freemem = 0; - if (!ReadFileToBuffer("/proc/meminfo", str, sizeof(str)-1, &result)) { + if (ReadFileToBuffer("/proc/meminfo", str, sizeof(str)-1, &result) IS ERR::Okay) { LONG i = 0; while (i < result) { - if (!StrCompare("Cached", str+i, sizeof("Cached")-1)) { + if (StrCompare("Cached", str+i, sizeof("Cached")-1) IS ERR::Okay) { freemem += (LARGE)StrToInt(str+i) * 1024LL; } - else if (!StrCompare("Buffers", str+i, sizeof("Buffers")-1)) { + else if (StrCompare("Buffers", str+i, sizeof("Buffers")-1) IS ERR::Okay) { freemem += (LARGE)StrToInt(str+i) * 1024LL; } - else if (!StrCompare("MemFree", str+i, sizeof("MemFree")-1)) { + else if (StrCompare("MemFree", str+i, sizeof("MemFree")-1) IS ERR::Okay) { freemem += (LARGE)StrToInt(str+i) * 1024LL; } @@ -494,7 +494,7 @@ LARGE GetResource(RES Resource) if (file.ok()) { while ((line = flReadLine(*file))) { - if (!StrCompare("cpu Mhz", line, sizeof("cpu Mhz")-1)) { + if (StrCompare("cpu Mhz", line, sizeof("cpu Mhz")-1) IS ERR::Okay) { cpu_mhz = StrToInt(line); } } @@ -808,10 +808,10 @@ LARGE SetResource(RES Resource, LARGE Value) #ifdef __unix__ log.trace("Privileged User: %s, Current UID: %d, Depth: %d", (Value) ? "TRUE" : "FALSE", geteuid(), privileged); - if (glPrivileged) return ERR::Okay; // In privileged mode, the user is always an admin + if (glPrivileged) return LARGE(ERR::Okay); // In privileged mode, the user is always an admin if (Value) { // Enable admin privileges - oldvalue = ERR::Okay; + oldvalue = LARGE(ERR::Okay); if (!privileged) { if (glUID) { if (glUID != glEUID) { @@ -820,7 +820,7 @@ LARGE SetResource(RES Resource, LARGE Value) } else { log.msg("Admin privileges not available."); - oldvalue = ERR::Failed; // Admin privileges are not available + oldvalue = LARGE(ERR::Failed); // Admin privileges are not available } } else privileged++;; // The user already has admin privileges diff --git a/src/core/lib_messages.cpp b/src/core/lib_messages.cpp index 48afbd710..0b9d182da 100644 --- a/src/core/lib_messages.cpp +++ b/src/core/lib_messages.cpp @@ -787,7 +787,7 @@ ERR send_thread_msg(LONG Handle, LONG Type, APTR Data, LONG Size) #else LARGE end_time = (PreciseTime() / 1000LL) + 10000LL; error = write_nonblock(Handle, &msg, sizeof(msg), end_time); - if ((!error) and (Data) and (Size > 0)) { // Write the main message. + if ((error IS ERR::Okay) and (Data) and (Size > 0)) { // Write the main message. error = write_nonblock(Handle, Data, Size, end_time); } #endif @@ -806,7 +806,7 @@ ERR write_nonblock(LONG Handle, APTR Data, LONG Size, LARGE EndTime) LONG offset = 0; ERR error = ERR::Okay; - while ((offset < Size) and (!error)) { + while ((offset < Size) and (error IS ERR::Okay)) { LONG write_size = Size; if (write_size > 1024) write_size = 1024; // Limiting the size will make the chance of an EWOULDBLOCK error less likely. LONG len = write(Handle, (char *)Data+offset, write_size - offset); @@ -817,7 +817,7 @@ ERR write_nonblock(LONG Handle, APTR Data, LONG Size, LARGE EndTime) if ((errno IS EAGAIN) or (errno IS EWOULDBLOCK)) { // The write() failed because it would have blocked. Try again! fd_set wfds; struct timeval tv; - while (((PreciseTime() / 1000LL) < EndTime) and (!error)) { + while (((PreciseTime() / 1000LL) < EndTime) and (error IS ERR::Okay)) { FD_ZERO(&wfds); FD_SET(Handle, &wfds); tv.tv_sec = (EndTime - (PreciseTime() / 1000LL)) / 1000LL; diff --git a/src/core/lib_objects.cpp b/src/core/lib_objects.cpp index 751572bd6..77c346672 100644 --- a/src/core/lib_objects.cpp +++ b/src/core/lib_objects.cpp @@ -401,10 +401,6 @@ ERR Action(LONG ActionID, OBJECTPTR Object, APTR Parameters) Object->ActionDepth++; auto cl = Object->ExtClass; -#ifdef _DEBUG - auto log_depth = tlDepth; -#endif - ERR error; if (ActionID >= 0) { if (cl->ActionTable[ActionID].PerformAction) { // Can be a base-class or sub-class call diff --git a/src/core/static_modules.cpp b/src/core/static_modules.cpp index 987f00da6..82c2ea4c7 100644 --- a/src/core/static_modules.cpp +++ b/src/core/static_modules.cpp @@ -16,7 +16,6 @@ extern "C" ModHeader * register_scintilla_module(); extern "C" ModHeader * register_svg_module(); extern "C" ModHeader * register_vector_module(); extern "C" ModHeader * register_xml_module(); -extern "C" ModHeader * register_xrandr_module(); //******************************************************************************************************************** // Register all static modules that were compiled into this build. @@ -82,10 +81,6 @@ static void register_static_modules(void) #ifdef INC_MOD_XML glStaticModules["xml"] = register_xml_module(); #endif - - #ifdef INC_MOD_XRANDR - glStaticModules["xrandr"] = register_xrandr_module(); - #endif } #endif diff --git a/src/core/tests/memory_locking.cpp b/src/core/tests/memory_locking.cpp index 35aa51646..50b5f7b8c 100644 --- a/src/core/tests/memory_locking.cpp +++ b/src/core/tests/memory_locking.cpp @@ -40,7 +40,7 @@ static void * test_locking(void *Arg) //log.branch("Attempt %d.%d: Acquiring the memory.", info->index, i); BYTE *memory; - if (auto error = AccessMemory(glMemoryID, MEM::READ_WRITE, 30000, &memory); !error) { + if (auto error = AccessMemory(glMemoryID, MEM::READ_WRITE, 30000, &memory); error IS ERR::Okay) { memory[0]++; log.msg("%d.%d: Memory acquired.", info->index, i); WaitTime(0, 2000); @@ -112,22 +112,22 @@ int main(int argc, CSTRING *argv) } pf::vector *args; - if ((!CurrentTask()->getPtr(FID_Parameters, &args)) and (args)) { + if ((CurrentTask()->getPtr(FID_Parameters, &args) IS ERR::Okay) and (args)) { for (unsigned i=0; i < args->size(); i++) { - if (!StrMatch(args[0][i], "-threads")) { + if (StrMatch(args[0][i], "-threads") IS ERR::Okay) { if (++i < args->size()) glTotalThreads = StrToInt(args[0][i]); else break; } - else if (!StrMatch(args[0][i], "-attempts")) { + else if (StrMatch(args[0][i], "-attempts") IS ERR::Okay) { if (++i < args->size()) glLockAttempts = StrToInt(args[0][i]); else break; } - else if (!StrMatch(args[0][i], "-gap")) { + else if (StrMatch(args[0][i], "-gap") IS ERR::Okay) { if (++i < args->size()) glAccessGap = StrToInt(args[0][i]); else break; } - else if (!StrMatch(args[0][i], "-terminate")) glTerminateMemory = true; - else if (!StrMatch(args[0][i], "-alloc")) glTestAllocation = true; + else if (StrMatch(args[0][i], "-terminate") IS ERR::Okay) glTerminateMemory = true; + else if (StrMatch(args[0][i], "-alloc") IS ERR::Okay) glTestAllocation = true; } } diff --git a/src/core/tests/object_locking.cpp b/src/core/tests/object_locking.cpp index f2805f749..2779a20eb 100644 --- a/src/core/tests/object_locking.cpp +++ b/src/core/tests/object_locking.cpp @@ -32,7 +32,7 @@ struct thread_info{ static void * thread_entry(void *Arg) { pf::Log log(__FUNCTION__); - ERROR error; + ERR error; auto info = (thread_info *)Arg; @@ -43,7 +43,7 @@ static void * thread_entry(void *Arg) if (!glConfig) break; //log.branch("Attempt %d.%d: Acquiring the object.", info->index, i); #ifdef QUICKLOCK - if (!(error = glConfig->lock())) { + if ((error = glConfig->lock()) IS ERR::Okay) { #else if (!(error = LockObject(glConfig, 30000))) { #endif @@ -98,21 +98,21 @@ int main(int argc, CSTRING *argv) return -1; } - if ((!CurrentTask()->getPtr(FID_Parameters, &args)) and (args)) { + if ((CurrentTask()->getPtr(FID_Parameters, &args) IS ERR::Okay) and (args)) { for (unsigned i=0; i < args->size(); i++) { - if (!StrMatch(args[0][i], "-threads")) { + if (StrMatch(args[0][i], "-threads") IS ERR::Okay) { if (++i < args->size()) glTotalThreads = StrToInt(args[0][i]); else break; } - else if (!StrMatch(args[0][i], "-attempts")) { + else if (StrMatch(args[0][i], "-attempts") IS ERR::Okay) { if (++i < args->size()) glLockAttempts = StrToInt(args[0][i]); else break; } - else if (!StrMatch(args[0][i], "-gap")) { + else if (StrMatch(args[0][i], "-gap") IS ERR::Okay) { if (++i < args->size()) glAccessGap = StrToInt(args[0][i]); else break; } - else if (!StrMatch(args[0][i], "-terminate")) glTerminateObject = TRUE; + else if (StrMatch(args[0][i], "-terminate") IS ERR::Okay) glTerminateObject = TRUE; } } diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index 831e22ec0..cba3eeba4 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -106,6 +106,6 @@ else () set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-overflow") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-overflow") target_sources (${MOD} PRIVATE ${FUNCTIONS} ${CLASSES}) - target_link_libraries (${MOD} PRIVATE ${MATH_LINK} Xext X11) # x11/libXxf86dga.a + target_link_libraries (${MOD} PRIVATE ${MATH_LINK} Xrender Xrandr Xext X11) # x11/libXxf86dga.a add_compile_definitions ("__X11DGA__" "__xwindows__") endif () diff --git a/src/display/class_bitmap.cpp b/src/display/class_bitmap.cpp index 7f7a5d68c..4c2663ed0 100644 --- a/src/display/class_bitmap.cpp +++ b/src/display/class_bitmap.cpp @@ -1190,14 +1190,14 @@ static ERR BITMAP_Init(extBitmap *Self, APTR Void) if (!Self->Size) return log.warning(ERR::FieldNotSet); if (glHeadless) { - if (!AllocMemory(Self->Size, MEM::NO_BLOCKING|MEM::NO_POOL|MEM::NO_CLEAR|Self->DataFlags, &Self->Data)) { + if (AllocMemory(Self->Size, MEM::NO_BLOCKING|MEM::NO_POOL|MEM::NO_CLEAR|Self->DataFlags, &Self->Data) IS ERR::Okay) { Self->prvAFlags |= BF_DATA; } else return log.warning(ERR::AllocMemory); } else if (!Self->x11.XShmImage) { log.detail("Allocating a memory based XImage."); - if (!alloc_shm(Self->Size, &Self->Data, &Self->x11.ShmInfo.shmid)) { + if (alloc_shm(Self->Size, &Self->Data, &Self->x11.ShmInfo.shmid) IS ERR::Okay) { Self->prvAFlags |= BF_DATA; WORD alignment; @@ -1287,7 +1287,7 @@ static ERR BITMAP_Init(extBitmap *Self, APTR Void) log.warning("Support for MEM::TEXTURE not included yet."); return ERR::NoSupport; } - else if (!AllocMemory(Self->Size, Self->DataFlags|MEM::NO_BLOCKING|MEM::NO_POOL|MEM::NO_CLEAR, &Self->Data)) { + else if (AllocMemory(Self->Size, Self->DataFlags|MEM::NO_BLOCKING|MEM::NO_POOL|MEM::NO_CLEAR, &Self->Data) IS ERR::Okay) { Self->prvAFlags |= BF_DATA; } else return ERR::AllocMemory; diff --git a/src/display/class_display.cpp b/src/display/class_display.cpp index efaa308c5..44e8683ad 100644 --- a/src/display/class_display.cpp +++ b/src/display/class_display.cpp @@ -110,8 +110,8 @@ static void printConfig(EGLDisplay display, EGLConfig config) { static void get_resolutions(extDisplay *Self) { -#ifdef __xwindows__ - if (XRandRBase) { +#if defined(__xwindows__) && defined(XRANDR_ENABLED) + if (glXRRAvailable) { struct xrMode *mode; if (!Self->Resolutions.empty()) return; @@ -607,10 +607,12 @@ static ERR DISPLAY_Init(extDisplay *Self, APTR Void) XFree(list); } - if (XRandRBase) { + #ifdef XRANDR_ENABLED + if (glXRRAvailable) { // Set the refresh rate to zero to indicate that we have some control of the display (the default is -1 if there is no control). Self->RefreshRate = 0; } + #endif #endif // Set defaults @@ -778,7 +780,7 @@ static ERR DISPLAY_Init(extDisplay *Self, APTR Void) } CSTRING name; - if ((!CurrentTask()->getPtr(FID_Name, &name)) and (name)) { + if ((CurrentTask()->getPtr(FID_Name, &name) IS ERR::Okay) and (name)) { XStoreName(XDisplay, Self->XWindowHandle, name); } else XStoreName(XDisplay, Self->XWindowHandle, "Parasol"); @@ -814,7 +816,9 @@ static ERR DISPLAY_Init(extDisplay *Self, APTR Void) bmp->set(FID_Handle, (APTR)Self->XWindowHandle); XChangeWindowAttributes(XDisplay, Self->XWindowHandle, CWEventMask|CWCursor, &swa); - if (XRandRBase) xrSelectInput(Self->XWindowHandle); + #ifdef XRANDR_ENABLED + if (glXRRAvailable) xrSelectInput(Self->XWindowHandle); + #endif XWindowAttributes winattrib; XGetWindowAttributes(XDisplay, Self->XWindowHandle, &winattrib); @@ -1521,7 +1525,8 @@ static ERR DISPLAY_SetDisplay(extDisplay *Self, struct gfxSetDisplay *Args) LONG height = Args->Height; if (glX11.Manager) { // The video mode can only be changed with the XRandR extension - if ((XRandRBase) and (xrSetDisplayMode(&width, &height) IS ERR::Okay)) { +#ifdef XRANDR_ENABLED + if ((glXRRAvailable) and (xrSetDisplayMode(&width, &height) IS ERR::Okay)) { Self->RefreshRate = 0; Self->Width = width; Self->Height = height; @@ -1533,6 +1538,7 @@ static ERR DISPLAY_SetDisplay(extDisplay *Self, struct gfxSetDisplay *Args) return ERR::Okay; } else return ERR::Failed; +#endif } else { XResizeWindow(XDisplay, Self->XWindowHandle, width, height); @@ -2385,7 +2391,7 @@ static ERR SET_Flags(extDisplay *Self, SCR Value) } STRING name; - if ((!CurrentTask()->getPtr(FID_Name, &name)) and (name)) { + if ((CurrentTask()->getPtr(FID_Name, &name) IS ERR::Okay) and (name)) { XStoreName(XDisplay, Self->XWindowHandle, name); } else XStoreName(XDisplay, Self->XWindowHandle, "Parasol"); @@ -2631,7 +2637,7 @@ static ERR SET_PopOver(extDisplay *Self, OBJECTID Value) Self->PopOverID = 0; XSetTransientForHint(XDisplay, Self->XWindowHandle, (Window)0); } - else if (!AccessObject(Value, 2000, &popover)) { + else if (AccessObject(Value, 2000, &popover) IS ERR::Okay) { if (popover->Class->BaseClassID IS ID_DISPLAY) { Self->PopOverID = Value; XSetTransientForHint(XDisplay, Self->XWindowHandle, (Window)popover->WindowHandle); diff --git a/src/display/class_pointer.cpp b/src/display/class_pointer.cpp index f28269d1f..9ce1689f1 100644 --- a/src/display/class_pointer.cpp +++ b/src/display/class_pointer.cpp @@ -34,6 +34,8 @@ static FunctionField mthSetWinCursor[] = { { "Cursor", FD_LONG }, { NULL, 0 } } #endif #ifdef __xwindows__ +#undef True +#undef False static ERR PTR_GrabX11Pointer(extPointer *, struct ptrGrabX11Pointer *); static ERR PTR_UngrabX11Pointer(extPointer *, APTR); static FunctionField mthGrabX11Pointer[] = { { "Surface", FD_LONG }, { NULL, 0 } }; @@ -92,11 +94,11 @@ static ERR PTR_GrabX11Pointer(extPointer *Self, struct ptrGrabX11Pointer *Args) APTR xwin; OBJECTPTR surface; - if (!AccessObject(Self->SurfaceID, 5000, &surface)) { + if (AccessObject(Self->SurfaceID, 5000, &surface) IS ERR::Okay) { surface->getPtr(FID_WindowHandle, &xwin); ReleaseObject(surface); - if (xwin) XGrabPointer(XDisplay, (Window)xwin, True, 0, GrabModeAsync, GrabModeAsync, (Window)xwin, None, CurrentTime); + if (xwin) XGrabPointer(XDisplay, (Window)xwin, 1, 0, GrabModeAsync, GrabModeAsync, (Window)xwin, None, CurrentTime); } return ERR::Okay; @@ -641,10 +643,10 @@ static ERR PTR_MoveToPoint(extPointer *Self, struct acMoveToPoint *Args) #ifdef __xwindows__ OBJECTPTR surface; - if (!AccessObject(Self->SurfaceID, 3000, &surface)) { + if (AccessObject(Self->SurfaceID, 3000, &surface) IS ERR::Okay) { APTR xwin; - if (!surface->getPtr(FID_WindowHandle, &xwin)) { + if (surface->getPtr(FID_WindowHandle, &xwin) IS ERR::Okay) { if ((Args->Flags & MTF::X) != MTF::NIL) Self->X = Args->X; if ((Args->Flags & MTF::Y) != MTF::NIL) Self->Y = Args->Y; if (Self->X < 0) Self->X = 0; diff --git a/src/display/defs.h b/src/display/defs.h index c4e2b783a..bf1a50223 100644 --- a/src/display/defs.h +++ b/src/display/defs.h @@ -14,6 +14,8 @@ //#define DBG_LAYERS #define FOCUSMSG(...) //LogF(NULL, __VA_ARGS__) +#include + #ifdef DBG_LAYERS #include #endif @@ -61,8 +63,6 @@ #ifdef XRANDR_ENABLED #include // Requires libxrandr-dev #endif - - #include #endif #ifdef _GLES_ @@ -559,7 +559,6 @@ extern APTR glDGAMemory; extern XVisualInfo glXInfoAlpha; extern X11Globals glX11; extern _XDisplay *XDisplay; -extern struct XRandRBase *XRandRBase; extern bool glX11ShmImage; extern bool glXCompositeSupported; extern UBYTE KeyHeld[LONG(KEY::LIST_END)]; @@ -574,6 +573,13 @@ extern Cursor C_Default; extern OBJECTPTR modXRR; extern WORD glPlugin; extern APTR glDGAVideo; +extern bool glXRRAvailable; + +extern LONG xrNotify(XEvent *); +extern ERR xrSetDisplayMode(LONG *, LONG *); +extern void xrSelectInput(Window); +extern LONG xrGetDisplayTotal(void); +extern struct xrMode * xrGetDisplayMode(LONG); #endif diff --git a/src/display/display-driver.cpp b/src/display/display-driver.cpp index eec0104c6..c5b90b25f 100644 --- a/src/display/display-driver.cpp +++ b/src/display/display-driver.cpp @@ -36,7 +36,6 @@ void handle_stack_change(XCirculateEvent *); X11Globals glX11; _XDisplay *XDisplay = 0; -struct XRandRBase *XRandRBase = 0; XVisualInfo glXInfoAlpha; bool glX11ShmImage = false; bool glXCompositeSupported = false; @@ -52,6 +51,15 @@ Cursor C_Default; OBJECTPTR modXRR = NULL; WORD glPlugin = FALSE; APTR glDGAVideo = NULL; + +#ifdef XRANDR_ENABLED +bool glXRRAvailable = false; +static XRRScreenSize glCustomSizes[] = { { 640,480,0,0 }, { 800,600,0,0 }, { 1024,768,0,0 }, { 1280,1024,0,0 } }; +static XRRScreenSize *glSizes = glCustomSizes; +static LONG glSizeCount = ARRAYSIZE(glCustomSizes); +static LONG glActualCount = 0; +#endif + #endif #ifdef _WIN32 @@ -803,26 +811,13 @@ static ERR CMDInit(OBJECTPTR argModule, struct CoreBase *argCoreBase) if (!getenv("PARASOL_XDISPLAY")) setenv("PARASOL_XDISPLAY", strdisplay, FALSE); - XSync(XDisplay, False); + XSync(XDisplay, 0); XSetErrorHandler((XErrorHandler)CatchXError); XSetIOErrorHandler(CatchXIOError); } else return ERR::Failed; - // Try to load XRandR if we are the display manager, but it's okay if not available - - if ((glX11.Manager) and (!NewObject(ID_MODULE, &modXRR))) { - char buffer[32]; - IntToStr((MAXINT)XDisplay, buffer, sizeof(buffer)); - acSetVar(modXRR, "XDisplay", buffer); - modXRR->set(FID_Name, "xrandr"); - if (!InitObject(modXRR)) { - if (modXRR->getPtr(FID_ModBase, &XRandRBase) != ERR::Okay) XRandRBase = NULL; - } - } - else XRandRBase = NULL; - // Get the X11 file descriptor (for incoming events) and tell the Core to listen to it when the task is sleeping. // The FD is currently marked as a dummy because processes aren't being woken from select() if the X11 FD already // contains input events. Dummy FD routines are always called manually prior to select(). @@ -882,7 +877,97 @@ static ERR CMDInit(OBJECTPTR argModule, struct CoreBase *argCoreBase) // Set the DISPLAY variable for clients to :10, which is the default X11 display for the rootless X Server. if (glX11.Manager) setenv("DISPLAY", ":10", TRUE); + +#ifdef XRANDR_ENABLED + WORD i; + XRRScreenSize *sizes; + XPixmapFormatValues *list; + LONG errors, count; + char buffer[512]; + + LONG events; + if ((glX11.Manager) and (XRRQueryExtension(XDisplay, &events, &errors))) { + glXRRAvailable = true; + if ((sizes = XRRSizes(XDisplay, DefaultScreen(XDisplay), &count)) and (count)) { + glSizes = sizes; + glSizeCount = count; + } + else log.msg("XRRSizes() failed."); + + // Build the screen.xml file if this is the first task to initialise the RandR extension. + + auto file = objFile::create { fl::Path("user:config/screen.xml"), fl::Flags(FL::NEW|FL::WRITE) }; + + if (file.ok()) { + auto write_string = [](objFile *File, CSTRING String) { + struct acWrite write = { .Buffer = String, .Length = StrLength(String) }; + Action(AC_Write, File, &write); + }; + + write_string(*file, "\n\n"); + write_string(*file, "\n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, " \n"); + write_string(*file, "\n\n"); + + WORD xbpp = DefaultDepth(XDisplay, DefaultScreen(XDisplay)); + + WORD xbytes; + if (xbpp <= 8) xbytes = 1; + else if (xbpp <= 16) xbytes = 2; + else if (xbpp <= 24) xbytes = 3; + else xbytes = 4; + + if ((list = XListPixmapFormats(XDisplay, &count))) { + for (i=0; i < count; i++) { + if (list[i].depth IS xbpp) { + xbytes = list[i].bits_per_pixel; + if (list[i].bits_per_pixel <= 8) xbytes = 1; + else if (list[i].bits_per_pixel <= 16) xbytes = 2; + else if (list[i].bits_per_pixel <= 24) xbytes = 3; + else xbytes = 4; + } + } + } + + if (xbytes IS 4) xbpp = 32; + + LONG xcolours; + switch(xbpp) { + case 1: xcolours = 2; break; + case 8: xcolours = 256; break; + case 15: xcolours = 32768; break; + case 16: xcolours = 65536; break; + default: xcolours = 16777216; break; + } + + for (i=0; i < glSizeCount; i++) { + if ((glSizes[i].width >= 640) and (glSizes[i].height >= 480)) { + snprintf(buffer, sizeof(buffer), "\n", xbytes); + write_string(*file, buffer); + + write_string(*file, "\n\n"); + } + } + } + } + else log.msg("XRRQueryExtension() failed."); +#endif // XRANDR_ENABLED + } + #elif _WIN32 if ((glInstance = winGetModuleHandle())) { @@ -1386,6 +1471,7 @@ ERR update_display(extDisplay *Self, extBitmap *Bitmap, LONG X, LONG Y, LONG Wid #ifdef __xwindows__ #include "x11/handlers.cpp" +#include "x11/xrandr.cpp" #endif #ifdef _WIN32 diff --git a/src/display/display.fdl b/src/display/display.fdl index 9c89aeabb..1690a4244 100644 --- a/src/display/display.fdl +++ b/src/display/display.fdl @@ -259,6 +259,12 @@ module({ name="Display", copyright="Paul Manias 2003-2024", version=1.0, status= int AbsY # Absolute Y ]]) + struct("xrMode", { comment="Display mode." }, [[ + int Width # Horizontal + int Height # Vertical + int Depth # bit depth + ]]) + -- PixelFormat duplicates the Core module's ColourFormat structure. struct("PixelFormat", { type="pixelformat", comment="Carries instructions to pack or unpack RGBA colours." }, [[ diff --git a/src/display/idl.h b/src/display/idl.h index add7593fd..1d9a80d13 100644 --- a/src/display/idl.h +++ b/src/display/idl.h @@ -1,2 +1,2 @@ #undef MOD_IDL -#define MOD_IDL "s.SurfaceInfo:pData,lParentID,lBitmapID,lDisplayID,lFlags,lX,lY,lWidth,lHeight,lAbsX,lAbsY,wLevel,cBitsPerPixel,cBytesPerPixel,lLineWidth\ns.SurfaceCoords:lX,lY,lWidth,lHeight,lAbsX,lAbsY\ns.PixelFormat:ucRedShift,ucGreenShift,ucBlueShift,ucAlphaShift,ucRedMask,ucGreenMask,ucBlueMask,ucAlphaMask,ucRedPos,ucGreenPos,ucBluePos,ucAlphaPos\ns.DisplayInfo:lDisplay,lFlags,wWidth,wHeight,wBitsPerPixel,wBytesPerPixel,xAccelFlags,lAmtColours,ePixelFormat:PixelFormat,fMinRefresh,fMaxRefresh,fRefreshRate,lIndex,lHDensity,lVDensity\ns.CursorInfo:lWidth,lHeight,lFlags,wBitsPerPixel\ns.BitmapSurface:pData,wWidth,wHeight,lLineWidth,ucBitsPerPixel,ucBytesPerPixel,ucOpacity,ucVersion,lColour,eClip:ClipRectangle,wXOffset,wYOffset,eFormat:ColourFormat\nc.ACF:SOFTWARE_BLIT=0x2,VIDEO_BLIT=0x1\nc.BAF:BLEND=0x2,COPY=0x4,DITHER=0x1,FILL=0x1,LINEAR=0x8\nc.BDF:DITHER=0x2,REDRAW=0x1\nc.BMF:ACCELERATED_2D=0x200,ACCELERATED_3D=0x400,ALPHA_CHANNEL=0x800,BLANK_PALETTE=0x1,CLEAR=0x80,COMPRESSED=0x2,FIXED_DEPTH=0x4000,INVERSE_ALPHA=0x20,MASK=0x10,NEVER_SHRINK=0x1000,NO_BLEND=0x8000,NO_DATA=0x4,PREMUL=0x10000,QUERIED=0x40,TRANSPARENT=0x8,USER=0x100,X11_DGA=0x2000\nc.BMP:CHUNKY=0x3,PLANAR=0x2\nc.CEF:DELETE=0x1,EXTEND=0x2\nc.CLIPTYPE:AUDIO=0x2,DATA=0x1,FILE=0x8,IMAGE=0x4,OBJECT=0x10,TEXT=0x20\nc.CPF:DRAG_DROP=0x1,HISTORY_BUFFER=0x4,HOST=0x2\nc.CRF:BUFFER=0x10,LMB=0x1,MMB=0x2,NO_BUTTONS=0x20,RESTRICT=0x8,RMB=0x4\nc.CS:CIE_LAB=0x3,CIE_LCH=0x4,LINEAR_RGB=0x2,SRGB=0x1\nc.CSRF:ALPHA=0x2,CLIP=0x10,DEFAULT_FORMAT=0x8,OFFSET=0x20,TRANSLUCENT=0x4,TRANSPARENT=0x1\nc.CT:AUDIO=0x1,DATA=0x0,END=0x6,FILE=0x3,IMAGE=0x2,OBJECT=0x4,TEXT=0x5\nc.DPMS:DEFAULT=0x0,OFF=0x1,STANDBY=0x3,SUSPEND=0x2\nc.DRAG:ANCHOR=0x1,NONE=0x0,NORMAL=0x2\nc.DSF:NO_DRAW=0x1,NO_EXPOSE=0x2\nc.DT:GLES=0x4,NATIVE=0x1,WINGDI=0x3,X11=0x2\nc.EXF:ABSOLUTE=0x8,ABSOLUTE_COORDS=0x8,CHILDREN=0x1,CURSOR_SPLIT=0x10,REDRAW_VOLATILE=0x2,REDRAW_VOLATILE_OVERLAP=0x4\nc.FLIP:HORIZONTAL=0x1,VERTICAL=0x2\nc.GMF:SAVE=0x1\nc.HOST:STICK_TO_FRONT=0x3,TASKBAR=0x2,TRANSLUCENCE=0x4,TRANSPARENT=0x5,TRAY_ICON=0x1\nc.IRF:FORCE_DRAW=0x10,IGNORE_CHILDREN=0x2,IGNORE_NV_CHILDREN=0x1,REDRAWS_CHILDREN=0x20,RELATIVE=0x8,SINGLE_BITMAP=0x4\nc.LVF:EXPOSE_CHANGES=0x1\nc.MON:AUTO_DETECT=0x1,BIT_6=0x2\nc.PF:ANCHOR=0x4,UNUSED=0x1,VISIBLE=0x2\nc.RNF:AFTER_COPY=0x10000,ASPECT_RATIO=0x2000000,AUTO_QUIT=0x100,COMPOSITE=0x400000,CURSOR=0x4000,DISABLED=0x80,FIXED_BUFFER=0x20000,FIXED_DEPTH=0x100000,FULL_SCREEN=0x800000,GRAB_FOCUS=0x20,HAS_FOCUS=0x40,HOST=0x200,IGNORE_FOCUS=0x1000000,INIT_ONLY=0x1960e81,NO_FOCUS=0x80000,NO_HORIZONTAL=0x1000,NO_PRECOMPOSITE=0x400000,NO_VERTICAL=0x2000,PERVASIVE_COPY=0x40000,POINTER=0x4000,POST_COMPOSITE=0x400000,PRECOPY=0x400,READ_ONLY=0x14040,SCROLL_CONTENT=0x8000,STICKY=0x10,STICK_TO_BACK=0x2,STICK_TO_FRONT=0x4,TOTAL_REDRAW=0x200000,TRANSPARENT=0x1,VIDEO=0x800,VISIBLE=0x8,VOLATILE=0x14400,WRITE_ONLY=0x800\nc.RT:ROOT=0x1\nc.SCR:ALPHA_BLEND=0x40,AUTO_SAVE=0x2,BIT_6=0x10,BORDERLESS=0x20,BUFFER=0x4,COMPOSITE=0x40,CUSTOM_WINDOW=0x40000000,DPMS_ENABLED=0x8000000,FLIPPABLE=0x20000000,GTF_ENABLED=0x10000000,HOSTED=0x2000000,MAXIMISE=0x80000000,MAXSIZE=0x100000,NO_ACCELERATION=0x8,POWERSAVE=0x4000000,READ_ONLY=0xfe300019,REFRESH=0x200000,VISIBLE=0x1\nc.SWIN:HOST=0x0,ICON_TRAY=0x2,NONE=0x3,TASKBAR=0x1\nc.WH:CLOSE=0x1\n" +#define MOD_IDL "s.SurfaceInfo:pData,lParentID,lBitmapID,lDisplayID,lFlags,lX,lY,lWidth,lHeight,lAbsX,lAbsY,wLevel,cBitsPerPixel,cBytesPerPixel,lLineWidth\ns.SurfaceCoords:lX,lY,lWidth,lHeight,lAbsX,lAbsY\ns.xrMode:lWidth,lHeight,lDepth\ns.PixelFormat:ucRedShift,ucGreenShift,ucBlueShift,ucAlphaShift,ucRedMask,ucGreenMask,ucBlueMask,ucAlphaMask,ucRedPos,ucGreenPos,ucBluePos,ucAlphaPos\ns.DisplayInfo:lDisplay,lFlags,wWidth,wHeight,wBitsPerPixel,wBytesPerPixel,xAccelFlags,lAmtColours,ePixelFormat:PixelFormat,fMinRefresh,fMaxRefresh,fRefreshRate,lIndex,lHDensity,lVDensity\ns.CursorInfo:lWidth,lHeight,lFlags,wBitsPerPixel\ns.BitmapSurface:pData,wWidth,wHeight,lLineWidth,ucBitsPerPixel,ucBytesPerPixel,ucOpacity,ucVersion,lColour,eClip:ClipRectangle,wXOffset,wYOffset,eFormat:ColourFormat\nc.ACF:SOFTWARE_BLIT=0x2,VIDEO_BLIT=0x1\nc.BAF:BLEND=0x2,COPY=0x4,DITHER=0x1,FILL=0x1,LINEAR=0x8\nc.BDF:DITHER=0x2,REDRAW=0x1\nc.BMF:ACCELERATED_2D=0x200,ACCELERATED_3D=0x400,ALPHA_CHANNEL=0x800,BLANK_PALETTE=0x1,CLEAR=0x80,COMPRESSED=0x2,FIXED_DEPTH=0x4000,INVERSE_ALPHA=0x20,MASK=0x10,NEVER_SHRINK=0x1000,NO_BLEND=0x8000,NO_DATA=0x4,PREMUL=0x10000,QUERIED=0x40,TRANSPARENT=0x8,USER=0x100,X11_DGA=0x2000\nc.BMP:CHUNKY=0x3,PLANAR=0x2\nc.CEF:DELETE=0x1,EXTEND=0x2\nc.CLIPTYPE:AUDIO=0x2,DATA=0x1,FILE=0x8,IMAGE=0x4,OBJECT=0x10,TEXT=0x20\nc.CPF:DRAG_DROP=0x1,HISTORY_BUFFER=0x4,HOST=0x2\nc.CRF:BUFFER=0x10,LMB=0x1,MMB=0x2,NO_BUTTONS=0x20,RESTRICT=0x8,RMB=0x4\nc.CS:CIE_LAB=0x3,CIE_LCH=0x4,LINEAR_RGB=0x2,SRGB=0x1\nc.CSRF:ALPHA=0x2,CLIP=0x10,DEFAULT_FORMAT=0x8,OFFSET=0x20,TRANSLUCENT=0x4,TRANSPARENT=0x1\nc.CT:AUDIO=0x1,DATA=0x0,END=0x6,FILE=0x3,IMAGE=0x2,OBJECT=0x4,TEXT=0x5\nc.DPMS:DEFAULT=0x0,OFF=0x1,STANDBY=0x3,SUSPEND=0x2\nc.DRAG:ANCHOR=0x1,NONE=0x0,NORMAL=0x2\nc.DSF:NO_DRAW=0x1,NO_EXPOSE=0x2\nc.DT:GLES=0x4,NATIVE=0x1,WINGDI=0x3,X11=0x2\nc.EXF:ABSOLUTE=0x8,ABSOLUTE_COORDS=0x8,CHILDREN=0x1,CURSOR_SPLIT=0x10,REDRAW_VOLATILE=0x2,REDRAW_VOLATILE_OVERLAP=0x4\nc.FLIP:HORIZONTAL=0x1,VERTICAL=0x2\nc.GMF:SAVE=0x1\nc.HOST:STICK_TO_FRONT=0x3,TASKBAR=0x2,TRANSLUCENCE=0x4,TRANSPARENT=0x5,TRAY_ICON=0x1\nc.IRF:FORCE_DRAW=0x10,IGNORE_CHILDREN=0x2,IGNORE_NV_CHILDREN=0x1,REDRAWS_CHILDREN=0x20,RELATIVE=0x8,SINGLE_BITMAP=0x4\nc.LVF:EXPOSE_CHANGES=0x1\nc.MON:AUTO_DETECT=0x1,BIT_6=0x2\nc.PF:ANCHOR=0x4,UNUSED=0x1,VISIBLE=0x2\nc.RNF:AFTER_COPY=0x10000,ASPECT_RATIO=0x2000000,AUTO_QUIT=0x100,COMPOSITE=0x400000,CURSOR=0x4000,DISABLED=0x80,FIXED_BUFFER=0x20000,FIXED_DEPTH=0x100000,FULL_SCREEN=0x800000,GRAB_FOCUS=0x20,HAS_FOCUS=0x40,HOST=0x200,IGNORE_FOCUS=0x1000000,INIT_ONLY=0x1960e81,NO_FOCUS=0x80000,NO_HORIZONTAL=0x1000,NO_PRECOMPOSITE=0x400000,NO_VERTICAL=0x2000,PERVASIVE_COPY=0x40000,POINTER=0x4000,POST_COMPOSITE=0x400000,PRECOPY=0x400,READ_ONLY=0x14040,SCROLL_CONTENT=0x8000,STICKY=0x10,STICK_TO_BACK=0x2,STICK_TO_FRONT=0x4,TOTAL_REDRAW=0x200000,TRANSPARENT=0x1,VIDEO=0x800,VISIBLE=0x8,VOLATILE=0x14400,WRITE_ONLY=0x800\nc.RT:ROOT=0x1\nc.SCR:ALPHA_BLEND=0x40,AUTO_SAVE=0x2,BIT_6=0x10,BORDERLESS=0x20,BUFFER=0x4,COMPOSITE=0x40,CUSTOM_WINDOW=0x40000000,DPMS_ENABLED=0x8000000,FLIPPABLE=0x20000000,GTF_ENABLED=0x10000000,HOSTED=0x2000000,MAXIMISE=0x80000000,MAXSIZE=0x100000,NO_ACCELERATION=0x8,POWERSAVE=0x4000000,READ_ONLY=0xfe300019,REFRESH=0x200000,VISIBLE=0x1\nc.SWIN:HOST=0x0,ICON_TRAY=0x2,NONE=0x3,TASKBAR=0x1\nc.WH:CLOSE=0x1\n" diff --git a/src/display/lib_bitmap.cpp b/src/display/lib_bitmap.cpp index 5a4850b4b..f0253f13a 100644 --- a/src/display/lib_bitmap.cpp +++ b/src/display/lib_bitmap.cpp @@ -535,7 +535,7 @@ ERR gfxCopyArea(extBitmap *Bitmap, extBitmap *dest, BAF Flags, LONG X, LONG Y, L dest->Clip.Right = DestX + Width - dest->XOffset; dest->Clip.Top = DestY - dest->YOffset; dest->Clip.Bottom = DestY + Height - dest->YOffset; - if (!lock_surface(dest, SURFACE_READ|SURFACE_WRITE)) { + if (lock_surface(dest, SURFACE_READ|SURFACE_WRITE) IS ERR::Okay) { auto srcdata = (ULONG *)(Bitmap->Data + (Y * Bitmap->LineWidth) + (X<<2)); while (Height > 0) { diff --git a/src/display/lib_cursor.cpp b/src/display/lib_cursor.cpp index b12681760..a09a05b5b 100644 --- a/src/display/lib_cursor.cpp +++ b/src/display/lib_cursor.cpp @@ -14,6 +14,9 @@ using namespace display; #ifdef __xwindows__ +#undef True // X11 name clash +#undef False // X11 name clash + struct XCursor { Cursor XCursor; PTC CursorID; @@ -71,7 +74,7 @@ static Cursor create_blank_cursor(void) XFreePixmap(XDisplay, data_pixmap); // According to XFree documentation, it is OK to free the pixmaps XFreePixmap(XDisplay, mask_pixmap); - XSync(XDisplay, False); + XSync(XDisplay, 0); return cursor; } @@ -498,8 +501,8 @@ ERR gfxSetCursor(OBJECTID ObjectID, CRF Flags, PTC CursorID, CSTRING Name, OBJEC objDisplay *display; Cursor xcursor; - if ((pointer->SurfaceID) and (!AccessObject(pointer->SurfaceID, 1000, &surface))) { - if ((surface->DisplayID) and (!AccessObject(surface->DisplayID, 1000, &display))) { + if ((pointer->SurfaceID) and (AccessObject(pointer->SurfaceID, 1000, &surface) IS ERR::Okay)) { + if ((surface->DisplayID) and (AccessObject(surface->DisplayID, 1000, &display) IS ERR::Okay)) { if ((display->getPtr(FID_WindowHandle, &xwin) IS ERR::Okay) and (xwin)) { xcursor = get_x11_cursor(CursorID); XDefineCursor(XDisplay, (Window)xwin, xcursor); diff --git a/src/display/x11/handlers.cpp b/src/display/x11/handlers.cpp index e8a583d55..444af9147 100644 --- a/src/display/x11/handlers.cpp +++ b/src/display/x11/handlers.cpp @@ -99,11 +99,11 @@ void X11ManagerLoop(HOSTHANDLE FD, APTR Data) if (glWindowHooks.contains(hook)) { auto func = &glWindowHooks[hook]; - ERROR result; + ERR result; if (func->isC()) { pf::SwitchContext ctx(func->StdC.Context); - auto callback = (ERROR (*)(OBJECTID, APTR))func->StdC.Routine; + auto callback = (ERR (*)(OBJECTID, APTR))func->StdC.Routine; result = callback(surface_id, func->StdC.Meta); } else if (func->isScript()) { @@ -112,10 +112,10 @@ void X11ManagerLoop(HOSTHANDLE FD, APTR Data) }; scCallback(func->Script.Script, func->Script.ProcedureID, args, std::ssize(args), &result); } - else result = ERR_Okay; + else result = ERR::Okay; - if (result IS ERR_Terminate) glWindowHooks.erase(hook); - else if (result IS ERR_Cancelled) { + if (result IS ERR::Terminate) glWindowHooks.erase(hook); + else if (result IS ERR::Cancelled) { log.msg("Window closure cancelled by client."); break; } @@ -142,7 +142,7 @@ void X11ManagerLoop(HOSTHANDLE FD, APTR Data) } #ifdef XRANDR_ENABLED - if ((XRandRBase) and (xrNotify(&xevent))) { + if ((glXRRAvailable) and (xrNotify(&xevent))) { // If randr indicates that the display has been resized, we must adjust the system display to match. Refer to // SetDisplay() for more information. @@ -151,12 +151,12 @@ void X11ManagerLoop(HOSTHANDLE FD, APTR Data) if (auto display_id = get_display(xevent.xany.window)) { auto surface_id = GetOwnerID(display_id); objSurface *surface; - if (!AccessObject(surface_id, 5000, &surface)) { + if (AccessObject(surface_id, 5000, &surface) IS ERR::Okay) { // Update the display width/height so that we don't recursively post further display mode updates to the // X server. extDisplay *display; - if (!AccessObject(display_id, 5000, &display)) { + if (AccessObject(display_id, 5000, &display) IS ERR::Okay) { display->Width = notify->width; display->Height = notify->height; acResize(surface, notify->width, notify->height, 0); @@ -233,7 +233,7 @@ void handle_button_press(XEvent *xevent) feed.Datatype = DATA::DEVICE_INPUT; feed.Buffer = &input; feed.Size = sizeof(input); - if (ActionMsg(AC_DataFeed, glPointerID, &feed) IS ERR_NoMatchingObject) { + if (ActionMsg(AC_DataFeed, glPointerID, &feed) IS ERR::NoMatchingObject) { glPointerID = 0; } } @@ -250,7 +250,7 @@ void handle_button_release(XEvent *xevent) log.traceBranch("Button: %d", xevent->xbutton.button); if (!glPointerID) { - if (FindObject("SystemPointer", 0, FOF::NIL, &glPointerID) != ERR_Okay) return; + if (FindObject("SystemPointer", 0, FOF::NIL, &glPointerID) != ERR::Okay) return; } struct dcDeviceInput input; @@ -281,7 +281,7 @@ void handle_button_release(XEvent *xevent) ReleaseObject(pointer); } - if (ActionMsg(AC_DataFeed, glPointerID, &feed) IS ERR_NoMatchingObject) { + if (ActionMsg(AC_DataFeed, glPointerID, &feed) IS ERR::NoMatchingObject) { glPointerID = 0; } @@ -322,7 +322,7 @@ void handle_configure_notify(XConfigureEvent *xevent) if (auto display_id = get_display(xevent->window)) { extDisplay *display; - if (!AccessObject(display_id, 3000, &display)) { + if (AccessObject(display_id, 3000, &display) IS ERR::Okay) { Window childwin; LONG absx, absy; diff --git a/src/display/x11/xrandr.cpp b/src/display/x11/xrandr.cpp new file mode 100644 index 000000000..a3fe33a1b --- /dev/null +++ b/src/display/x11/xrandr.cpp @@ -0,0 +1,127 @@ + +#ifdef XRANDR_ENABLED + +//******************************************************************************************************************** + +ERR xrSetDisplayMode(LONG *Width, LONG *Height) +{ + pf::Log log(__FUNCTION__); + LONG count; + WORD i; + + WORD width = *Width; + WORD height = *Height; + + XRRScreenSize *sizes; + if ((sizes = XRRSizes(XDisplay, DefaultScreen(XDisplay), &count)) and (count)) { + WORD index = -1; + LONG bestweight = 0x7fffffff; + + for (i=0; i < count; i++) { + LONG weight = std::abs(sizes[i].width - width) + std::abs(sizes[i].height - height); + if (weight < bestweight) { + index = i; + bestweight = weight; + } + } + + if (index IS -1) { + log.warning("No support for requested screen mode %dx%d", width, height); + return ERR::NoSupport; + } + + XRRScreenConfiguration *scrconfig; + if ((scrconfig = XRRGetScreenInfo(XDisplay, DefaultRootWindow(XDisplay)))) { + if (!XRRSetScreenConfig(XDisplay, scrconfig, + DefaultRootWindow(XDisplay), index, RR_Rotate_0, CurrentTime)) { + *Width = sizes[index].width; + *Height = sizes[index].height; + + log.msg("New mode: %dx%d (index %d/%d) from request %dx%d", sizes[index].width, sizes[index].height, index, count, width, height); + + XRRFreeScreenConfigInfo(scrconfig); + return ERR::Okay; + } + else { + log.warning("SetScreenConfig() failed."); + XRRFreeScreenConfigInfo(scrconfig); + return ERR::Failed; + } + } + else return ERR::Failed; + } + else { + log.warning("RandR not initialised."); + return ERR::Failed; + } +} + +//******************************************************************************************************************** + +LONG xrNotify(XEvent *XEvent) +{ + if (XRRUpdateConfiguration(XEvent)) return 1; + return 0; +} + +//******************************************************************************************************************** + +void xrSelectInput(Window Window) +{ + XRRSelectInput(XDisplay, DefaultRootWindow(XDisplay), RRScreenChangeNotifyMask); +} + +//******************************************************************************************************************** +// This function returns the total number of known display modes. + +LONG xrGetDisplayTotal(void) +{ + pf::Log log(__FUNCTION__); + + if (!glActualCount) { + for (LONG i=0; i < glSizeCount; i++) { + if ((glSizes[i].width >= 640) and (glSizes[i].height >= 480)) { + glActualCount++; + } + } + } + + log.msg("%d Resolutions", glActualCount); + return glActualCount; +} + +//******************************************************************************************************************** +// This function returns the width, height and depth of a given display mode. + +struct xrMode * xrGetDisplayMode(LONG Index) +{ + pf::Log log(__FUNCTION__); + static struct xrMode mode; + LONG i, j; + + if ((Index < 0) or (Index >= glActualCount)) { + log.warning("Index %d not within range 0 - %d", Index, glActualCount); + return NULL; + } + + ClearMemory(&mode, sizeof(mode)); + + j = Index; + for (i=0; i < glSizeCount; i++) { + if ((glSizes[i].width >= 640) and (glSizes[i].height >= 480)) { + if (!j) { + mode.Width = glSizes[i].width; + mode.Height = glSizes[i].height; + mode.Depth = DefaultDepth(XDisplay, DefaultScreen(XDisplay)); + log.msg("Mode %d: %dx%d", Index, mode.Width, mode.Height); + return &mode; + } + j--; + } + } + + log.warning("Failed to get mode index %d", Index); + return NULL; +} + +#endif // XRANDR_ENABLED diff --git a/src/fluid/fluid_class.cpp b/src/fluid/fluid_class.cpp index a92272cd5..9892a9b5d 100644 --- a/src/fluid/fluid_class.cpp +++ b/src/fluid/fluid_class.cpp @@ -1023,7 +1023,7 @@ static ERR run_script(objScript *Self) #ifdef _DEBUG pf::vector *list; LONG total_procedures; - if (!GET_Procedures(Self, &list, &total_procedures)) { + if (GET_Procedures(Self, &list, &total_procedures) IS ERR::Okay) { for (LONG i=0; i < total_procedures; i++) log.trace("%s", list[0][i]); } #endif diff --git a/src/link/init-unix.cpp b/src/link/init-unix.cpp index e899f9999..eab48733d 100644 --- a/src/link/init-unix.cpp +++ b/src/link/init-unix.cpp @@ -22,7 +22,7 @@ This file is in the public domain and may be distributed and modified without re struct CoreBase *CoreBase; static APTR glCoreHandle = NULL; -typedef ERROR OPENCORE(struct OpenInfo *, struct CoreBase **); +typedef ERR OPENCORE(struct OpenInfo *, struct CoreBase **); typedef void CLOSECORE(void); static CLOSECORE *CloseCore = NULL; #else @@ -102,11 +102,11 @@ extern "C" const char * init_parasol(int argc, CSTRING *argv) info.MaxDepth = 14; info.Args = argv; info.ArgCount = argc; - info.Error = ERR_Okay; + info.Error = ERR::Okay; info.Flags = OPF::ARGS|OPF::ERROR; - if (!OpenCore(&info, &CoreBase)) return NULL; - else if (info.Error IS ERR_CoreVersion) return "This program requires the latest version of the Parasol framework.\nPlease visit www.parasol.ws to upgrade."; + if (OpenCore(&info, &CoreBase) IS ERR::Okay) return NULL; + else if (info.Error IS ERR::CoreVersion) return "This program requires the latest version of the Parasol framework.\nPlease visit www.parasol.ws to upgrade."; else return "Failed to initialise Parasol. Run again with --log-info."; } diff --git a/src/xrandr/CMakeLists.txt b/src/xrandr/CMakeLists.txt deleted file mode 100644 index 6a62af40b..000000000 --- a/src/xrandr/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# XRandR Module -# Used by the Display module for full-screen graphics - -set (MOD xrandr) -set (INC_MOD_XRANDR TRUE PARENT_SCOPE) - -CHECK_C_SOURCE_COMPILES (" -#include -int main() { - return 0; -}" -XRANDR_INSTALLED) - -if (XRANDR_INSTALLED) - idl_c ("${MOD}.fdl" NAME ${MOD}_defs OUTPUT "${INCLUDE_OUTPUT}/modules/${MOD}.h" FILES "${MOD}.cpp" - ARGS "output-defs=module_def.c" "prototypes=static") - - link_directories("/usr/X11R6/lib" "/usr/lib") - - add_library (${MOD}) - - set_module_defaults (${MOD}) - - target_sources (${MOD} PRIVATE "${MOD}.cpp") - target_link_libraries (${MOD} PRIVATE Xrender Xrandr Xext) # x11/libXxf86dga.a -endif () diff --git a/src/xrandr/module_def.c b/src/xrandr/module_def.c deleted file mode 100644 index e52d68cd2..000000000 --- a/src/xrandr/module_def.c +++ /dev/null @@ -1,21 +0,0 @@ -// Auto-generated by idl-c.fluid - -#ifndef FDEF -#define FDEF static const struct FunctionField -#endif - -FDEF argsGetDisplayMode[] = { { "Result", FD_PTR }, { "Index", FD_LONG }, { 0, 0 } }; -FDEF argsGetDisplayTotal[] = { { "Result", FD_LONG }, { 0, 0 } }; -FDEF argsNotify[] = { { "Result", FD_LONG }, { "XEvent", FD_PTR }, { 0, 0 } }; -FDEF argsSelectInput[] = { { "Void", FD_VOID }, { "Window", FD_LONG }, { 0, 0 } }; -FDEF argsSetDisplayMode[] = { { "Error", FD_LONG|FD_ERROR }, { "Width", FD_LONG|FD_RESULT }, { "Height", FD_LONG|FD_RESULT }, { 0, 0 } }; - -const struct Function glFunctions[] = { - { (APTR)xrSetDisplayMode, "SetDisplayMode", argsSetDisplayMode }, - { (APTR)xrNotify, "Notify", argsNotify }, - { (APTR)xrSelectInput, "SelectInput", argsSelectInput }, - { (APTR)xrGetDisplayTotal, "GetDisplayTotal", argsGetDisplayTotal }, - { (APTR)xrGetDisplayMode, "GetDisplayMode", argsGetDisplayMode }, - { NULL, NULL, NULL } -}; - diff --git a/src/xrandr/xrandr.cpp b/src/xrandr/xrandr.cpp deleted file mode 100644 index e75a2f370..000000000 --- a/src/xrandr/xrandr.cpp +++ /dev/null @@ -1,333 +0,0 @@ - -#define PRV_XRANDR_MODULE - -#include -#include - -#include -#include - -static LONG xrNotify(XEvent *); -static ERROR xrSetDisplayMode(LONG *, LONG *); -static void xrSelectInput(Window); -static LONG xrGetDisplayTotal(void); -static struct xrMode * xrGetDisplayMode(LONG); - -JUMPTABLE_CORE -static struct _XDisplay *XDisplay; -static XRRScreenSize glCustomSizes[] = { { 640,480,0,0 }, { 800,600,0,0 }, { 1024,768,0,0 }, { 1280,1024,0,0 } }; -static XRRScreenSize *glSizes = glCustomSizes; -static LONG glSizeCount = ARRAYSIZE(glCustomSizes); -static LONG glActualCount = 0; - -//******************************************************************************************************************** - -static void write_string(objFile *File, CSTRING String) -{ - struct acWrite write = { .Buffer = String, .Length = StrLength(String) }; - Action(AC_Write, File, &write); -} - -//******************************************************************************************************************** - -static ERROR CMDInit(OBJECTPTR argModule, struct CoreBase *argCoreBase) -{ - pf::Log log("XRandR"); - WORD i; - XRRScreenSize *sizes; - XPixmapFormatValues *list; - LONG errors, count; - char buffer[512]; - - CoreBase = argCoreBase; - - // Do not proceed with initialisation if the module is being probed - - if ((((objModule *)argModule)->Flags & MOF::SYSTEM_PROBE) != MOF::NIL) return ERR_ServiceUnavailable|ERR::Notified; - - if (!acGetVar(argModule, "XDisplay", buffer, sizeof(buffer))) { - XDisplay = (struct _XDisplay *)(MAXINT)StrToInt(buffer); - if (!XDisplay) return log.warning(ERR_FieldNotSet); - } - else return log.warning(ERR_FieldNotSet); - - LONG screen = DefaultScreen(XDisplay); - - bool avail = false; - LONG events; - if (XRRQueryExtension(XDisplay, &events, &errors)) avail = true; - else log.msg("XRRQueryExtension() failed."); - - if (!avail) return ERR_ServiceUnavailable|ERR::Notified; - - if ((sizes = XRRSizes(XDisplay, screen, &count)) and (count)) { - glSizes = sizes; - glSizeCount = count; - } - else log.msg("XRRSizes() failed."); - - // Build the screen.xml file if this is the first task to initialise the RandR extension. - - auto file = objFile::create { fl::Path("user:config/screen.xml"), fl::Flags(FL::NEW|FL::WRITE) }; - - if (file.ok()) { - write_string(*file, "\n\n"); - write_string(*file, "\n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, " \n"); - write_string(*file, "\n\n"); - - WORD xbpp = DefaultDepth(XDisplay, screen); - - WORD xbytes; - if (xbpp <= 8) xbytes = 1; - else if (xbpp <= 16) xbytes = 2; - else if (xbpp <= 24) xbytes = 3; - else xbytes = 4; - - if ((list = XListPixmapFormats(XDisplay, &count))) { - for (i=0; i < count; i++) { - if (list[i].depth IS xbpp) { - xbytes = list[i].bits_per_pixel; - if (list[i].bits_per_pixel <= 8) xbytes = 1; - else if (list[i].bits_per_pixel <= 16) xbytes = 2; - else if (list[i].bits_per_pixel <= 24) xbytes = 3; - else xbytes = 4; - } - } - } - - if (xbytes IS 4) xbpp = 32; - - LONG xcolours; - switch(xbpp) { - case 1: xcolours = 2; break; - case 8: xcolours = 256; break; - case 15: xcolours = 32768; break; - case 16: xcolours = 65536; break; - default: xcolours = 16777216; break; - } - - for (i=0; i < glSizeCount; i++) { - if ((glSizes[i].width >= 640) and (glSizes[i].height >= 480)) { - snprintf(buffer, sizeof(buffer), "\n", xbytes); - write_string(*file, buffer); - - write_string(*file, "\n\n"); - } - } - } - - return ERR_Okay; -} - -/********************************************************************************************************************* - --FUNCTION- -SetDisplayMode: Change the width and height of the display. - -This function changes the width and height of the display to that indicated by the Width and Height parameters. If the requested size does not match a known mode, the closest matching mode will be chosen. - --INPUT- -&int Width: The required width of the display. -&int Height: The required height of the display. - --ERRORS- -Okay - -*********************************************************************************************************************/ - -static ERROR xrSetDisplayMode(LONG *Width, LONG *Height) -{ - pf::Log log(__FUNCTION__); - LONG count; - WORD i; - - WORD width = *Width; - WORD height = *Height; - - XRRScreenSize *sizes; - if ((sizes = XRRSizes(XDisplay, DefaultScreen(XDisplay), &count)) and (count)) { - WORD index = -1; - LONG bestweight = 0x7fffffff; - - for (i=0; i < count; i++) { - LONG weight = std::abs(sizes[i].width - width) + std::abs(sizes[i].height - height); - if (weight < bestweight) { - index = i; - bestweight = weight; - } - } - - if (index IS -1) { - log.warning("No support for requested screen mode %dx%d", width, height); - return ERR_NoSupport; - } - - XRRScreenConfiguration *scrconfig; - if ((scrconfig = XRRGetScreenInfo(XDisplay, DefaultRootWindow(XDisplay)))) { - if (!XRRSetScreenConfig(XDisplay, scrconfig, - DefaultRootWindow(XDisplay), index, RR_Rotate_0, CurrentTime)) { - *Width = sizes[index].width; - *Height = sizes[index].height; - - log.msg("New mode: %dx%d (index %d/%d) from request %dx%d", sizes[index].width, sizes[index].height, index, count, width, height); - - XRRFreeScreenConfigInfo(scrconfig); - return ERR_Okay; - } - else { - log.warning("SetScreenConfig() failed."); - XRRFreeScreenConfigInfo(scrconfig); - return ERR_Failed; - } - } - else return ERR_Failed; - } - else { - log.warning("RandR not initialised."); - return ERR_Failed; - } -} - -/********************************************************************************************************************* - --FUNCTION- -Notify: Private - -This is an internal function for the Display module. - --INPUT- -ptr XEvent: Pointer to an XEvent structure to be processed. - --RESULT- -int: Returns 0 or 1. - -*********************************************************************************************************************/ - -static LONG xrNotify(XEvent *XEvent) -{ - if (XRRUpdateConfiguration(XEvent)) return 1; - return 0; -} - -/********************************************************************************************************************* - --FUNCTION- -SelectInput: Private - -This is an internal function for the Display module. - --INPUT- -int Window: The X11 window to target. - -*********************************************************************************************************************/ - -static void xrSelectInput(Window Window) -{ - XRRSelectInput(XDisplay, DefaultRootWindow(XDisplay), RRScreenChangeNotifyMask); -} - -/********************************************************************************************************************* - --FUNCTION- -GetDisplayTotal: Returns the total number of display modes. - -This function returns the total number of known display modes. - --RESULT- -int: Returns the total number of known display modes. - -*********************************************************************************************************************/ - -static LONG xrGetDisplayTotal(void) -{ - pf::Log log(__FUNCTION__); - - if (!glActualCount) { - for (LONG i=0; i < glSizeCount; i++) { - if ((glSizes[i].width >= 640) and (glSizes[i].height >= 480)) { - glActualCount++; - } - } - } - - log.msg("%d Resolutions", glActualCount); - return glActualCount; -} - -/********************************************************************************************************************* - --FUNCTION- -GetDisplayMode: Retrieve information of a display mode. - -This function returns the width, height and depth of a given display mode. - --INPUT- -int Index: Index of the display mode to retrieve. - --RESULT- -ptr: An xrMode structure is returned or NULL on failure. - -*********************************************************************************************************************/ - -static struct xrMode * xrGetDisplayMode(LONG Index) -{ - pf::Log log(__FUNCTION__); - static struct xrMode mode; - LONG i, j; - - if ((Index < 0) or (Index >= glActualCount)) { - log.warning("Index %d not within range 0 - %d", Index, glActualCount); - return NULL; - } - - ClearMemory(&mode, sizeof(mode)); - - j = Index; - for (i=0; i < glSizeCount; i++) { - if ((glSizes[i].width >= 640) and (glSizes[i].height >= 480)) { - if (!j) { - mode.Width = glSizes[i].width; - mode.Height = glSizes[i].height; - mode.Depth = DefaultDepth(XDisplay, DefaultScreen(XDisplay)); - log.msg("Mode %d: %dx%d", Index, mode.Width, mode.Height); - return &mode; - } - j--; - } - } - - log.warning("Failed to get mode index %d", Index); - return NULL; -} - -//******************************************************************************************************************** - -#include "module_def.c" - -static ERROR CMDOpen(OBJECTPTR Module) -{ - Module->set(FID_FunctionList, glFunctions); - return ERR_Okay; -} - -static ERROR CMDExpunge(void) -{ - return ERR_Okay; -} - -PARASOL_MOD(CMDInit, NULL, CMDOpen, CMDExpunge, MOD_IDL, NULL) -extern "C" struct ModHeader * register_xrandr_module() { return &ModHeader; } diff --git a/src/xrandr/xrandr.fdl b/src/xrandr/xrandr.fdl deleted file mode 100644 index ea38c628a..000000000 --- a/src/xrandr/xrandr.fdl +++ /dev/null @@ -1,17 +0,0 @@ ---$FLUID:Include - -module({ name="XRandR", copyright="Paul Manias © 2014-2017", version=1.0, prefix="xr" }, function() - functionNames("xr", - "SetDisplayMode", - "Notify", - "SelectInput", - "GetDisplayTotal", - "GetDisplayMode") - - struct("xrMode", { comment="Display mode." }, [[ - int Width # Horizontal - int Height # Vertical - int Depth # bit depth - ]]) - -end)