misc fixes and cleanup

This commit is contained in:
nakst 2021-09-04 20:51:26 +01:00
parent 3542184a9c
commit 271606f94a
23 changed files with 134 additions and 91 deletions

View File

@ -466,7 +466,7 @@ void InstanceChangeSortColumn(EsMenu *menu, EsGeneric context) {
EsListViewContentChanged(instance->list);
}
__attribute__((optimize("-O3")))
ES_FUNCTION_OPTIMISE_O3
void ThumbnailResize(uint32_t *bits, uint32_t originalWidth, uint32_t originalHeight, uint32_t targetWidth, uint32_t targetHeight) {
// NOTE Modifies the original bits!
// NOTE It looks like this only gets vectorised in -O3.
@ -1077,7 +1077,7 @@ void InstanceReportError(Instance *instance, int error, EsError code) {
message = interfaceString_FileManagerItemAlreadyExistsError;
} else if (code == ES_ERROR_FILE_DOES_NOT_EXIST) {
message = interfaceString_FileManagerItemDoesNotExistError;
} else if (code == ES_ERROR_FILE_PERMISSION_NOT_GRANTED) {
} else if (code == ES_ERROR_PERMISSION_NOT_GRANTED) {
message = interfaceString_FileManagerPermissionNotGrantedError;
}

View File

@ -40,7 +40,7 @@ void Transform(float *destination, float *left, float *right) {
destination[5] = d[5];
}
__attribute__((optimize("-O2")))
ES_FUNCTION_OPTIMISE_O3
void Draw(Texture *texture,
float x, float y, float w = -1, float h = -1,
float sx = 0, float sy = 0, float sw = -1, float sh = -1,

View File

@ -1094,7 +1094,7 @@ void EsInstanceSaveComplete(EsMessage *message, bool success) {
switch (message->instanceSave.file->error) {
case ES_ERROR_FILE_DOES_NOT_EXIST:
case ES_ERROR_NODE_DELETED:
case ES_ERROR_FILE_PERMISSION_NOT_GRANTED:
case ES_ERROR_PERMISSION_NOT_GRANTED:
case ES_ERROR_INCORRECT_NODE_TYPE:
errorMessage = interfaceString_FileSaveErrorFileDeleted;
break;

View File

@ -7,8 +7,6 @@
// - Duplicate tabs.
// TODO Graphical issues:
// - New tab button isn't flush with right border when tab band full.
// - Cursor doesn't update after switching embed window owners.
// - Closing tabs isn't animating.
// - Inactivate windows don't dim outline around tabs.
// - Resizing windows doesn't redraw old shadow sometimes.
@ -612,9 +610,10 @@ int WindowTabBandMessage(EsElement *element, EsMessage *message) {
}
}
int x = ReorderListLayout(band, band->GetChild(0)->currentStyle->preferredWidth + 10, true, band->preventNextTabSizeAnimation);
int x = ReorderListLayout(band, band->GetChild(0)->currentStyle->preferredWidth + 10 * theming.scale,
true, band->preventNextTabSizeAnimation);
band->GetChild(0)->InternalMove(band->GetChild(0)->currentStyle->preferredWidth,
band->GetChild(0)->currentStyle->preferredHeight, x + 10, 4);
band->GetChild(0)->currentStyle->preferredHeight, x + 10 * theming.scale, 4 * theming.scale);
band->preventNextTabSizeAnimation = false;
} else if (message->type == ES_MSG_MOUSE_LEFT_DOWN) {
} else if (message->type == ES_MSG_MOUSE_LEFT_DRAG) {

View File

@ -294,7 +294,7 @@ struct ScrollPane {
double position[2];
int64_t limit[2];
int32_t fixedViewport[2];
bool autoScrollbars[2];
bool enabled[2];
bool dragScrolling;
#define SCROLL_MODE_NONE (0) // No scrolling takes place on this axis.
@ -835,6 +835,7 @@ EsWindow *EsWindowCreate(EsInstance *instance, EsWindowStyle style) {
window->window = window;
window->width = window->windowWidth, window->height = window->windowHeight;
window->hovered = window;
window->hovering = true;
window->windowStyle = style;
window->RefreshStyle();
@ -2924,13 +2925,13 @@ void ScrollPane::Refresh() {
if (bar[0]) {
bar[0]->InternalMove(parent->width - parent->internalOffsetRight, bar[0]->currentStyle->preferredHeight,
0, parent->height - parent->internalOffsetBottom);
autoScrollbars[0] = ~bar[0]->flags & ES_ELEMENT_DISABLED;
enabled[0] = ~bar[0]->flags & ES_ELEMENT_DISABLED;
}
if (bar[1]) {
bar[1]->InternalMove(bar[1]->currentStyle->preferredWidth, parent->height - parent->internalOffsetBottom,
parent->width - parent->internalOffsetRight, 0);
autoScrollbars[1] = ~bar[1]->flags & ES_ELEMENT_DISABLED;
enabled[1] = ~bar[1]->flags & ES_ELEMENT_DISABLED;
}
if (pad) {
@ -3089,12 +3090,18 @@ int ProcessPanelMessage(EsElement *element, EsMessage *message) {
panel->measurementCache.Store(message);
}
} else if (message->type == ES_MSG_ENSURE_VISIBLE) {
EsElement *child = message->child, *e = child;
int offsetX = panel->scroll.position[0], offsetY = panel->scroll.position[1];
while (e != element) offsetX += e->offsetX, offsetY += e->offsetY, e = e->parent;
EsRectangle bounds = panel->GetBounds();
panel->scroll.SetX(offsetX + child->width / 2 - bounds.r / 2);
panel->scroll.SetY(offsetY + child->height / 2 - bounds.b / 2);
if (panel->scroll.enabled[0] || panel->scroll.enabled[1]) {
EsElement *child = message->child, *e = child;
int offsetX = panel->scroll.position[0], offsetY = panel->scroll.position[1];
while (e != element) offsetX += e->offsetX, offsetY += e->offsetY, e = e->parent;
EsRectangle bounds = panel->GetBounds();
panel->scroll.SetX(offsetX + child->width / 2 - bounds.r / 2);
panel->scroll.SetY(offsetY + child->height / 2 - bounds.b / 2);
return ES_HANDLED;
} else {
// This is not a scroll container, so don't update the child element being made visible.
return 0;
}
} else if (message->type == ES_MSG_PRE_ADD_CHILD) {
if (!panel->addingSeparator && panel->separatorStylePart && panel->GetChildCount()) {
panel->addingSeparator = true;
@ -5282,14 +5289,14 @@ void EsWindowSetTitle(EsWindow *window, const char *title, ptrdiff_t titleBytes)
MessageDesktop(buffer, bytes, window->handle);
}
void EsMouseSetPosition(EsWindow *relativeWindow, int x, int y) {
EsError EsMouseSetPosition(EsWindow *relativeWindow, int x, int y) {
if (relativeWindow) {
EsRectangle bounds = EsWindowGetBounds(relativeWindow);
x += bounds.l;
y += bounds.t;
}
EsSyscall(ES_SYSCALL_CURSOR_POSITION_SET, x, y, 0, 0);
return EsSyscall(ES_SYSCALL_CURSOR_POSITION_SET, x, y, 0, 0);
}
EsPoint EsMouseGetPosition(EsElement *relativeElement) {
@ -6743,6 +6750,12 @@ void UIProcessWindowManagerMessage(EsWindow *window, EsMessage *message, Process
EsElementSetHidden(alternative->small, !belowThreshold);
EsElementSetHidden(alternative->big, belowThreshold);
}
// The mouse position gets reset to (0,0) on deactivation, so get the correct position here.
EsSyscall(ES_SYSCALL_CURSOR_POSITION_GET, (uintptr_t) &window->mousePosition, 0, 0, 0);
EsRectangle windowBounds = EsWindowGetBounds(window);
window->mousePosition.x -= windowBounds.l, window->mousePosition.y -= windowBounds.t;
window->hovering = true;
} else if (message->type == ES_MSG_WINDOW_DEACTIVATED) {
AccessKeyModeExit();
@ -6801,14 +6814,13 @@ void UIProcessWindowManagerMessage(EsWindow *window, EsMessage *message, Process
return;
}
UIFindHoverElement(window);
bool changedCursor = UISetCursor(window);
if (window->receivedFirstResize || window->windowStyle != ES_WINDOW_NORMAL) {
UIWindowLayoutNow(window, timing);
}
UIFindHoverElement(window);
bool changedCursor = UISetCursor(window);
if (THEME_RECT_VALID(window->updateRegion) && window->width == (int) window->windowWidth && window->height == (int) window->windowHeight) {
UIWindowPaintNow(window, timing, message->type == ES_MSG_WINDOW_RESIZED);
} else if (changedCursor) {

View File

@ -661,7 +661,7 @@ struct EsListView : EsElement {
position + contentBounds.l,
currentStyle->insets.t - this->scroll.position[1] + visibleItem->indent * currentStyle->gapWrap + contentBounds.t);
position += visibleItem->element->width;
} else if ((flags & ES_LIST_VIEW_COLUMNS) && ((~flags & ES_LIST_VIEW_CHOICE_SELECT) || (this->scroll.autoScrollbars[0]))) {
} else if ((flags & ES_LIST_VIEW_COLUMNS) && ((~flags & ES_LIST_VIEW_CHOICE_SELECT) || (this->scroll.enabled[0]))) {
int indent = visibleItem->indent * currentStyle->gapWrap;
int firstColumn = columns[0].width * theming.scale + secondaryCellStyle->gapMajor;
visibleItem->startAtSecondColumn = indent > firstColumn;

View File

@ -285,7 +285,7 @@ define ES_ERROR_FILE_ALREADY_EXISTS (-19)
define ES_ERROR_FILE_DOES_NOT_EXIST (-20)
define ES_ERROR_DRIVE_ERROR_FILE_DAMAGED (-21)
define ES_ERROR_ACCESS_NOT_WITHIN_FILE_BOUNDS (-22)
define ES_ERROR_FILE_PERMISSION_NOT_GRANTED (-23)
define ES_ERROR_PERMISSION_NOT_GRANTED (-23)
define ES_ERROR_FILE_IN_EXCLUSIVE_USE (-24)
define ES_ERROR_FILE_CANNOT_GET_EXCLUSIVE_USE (-25)
define ES_ERROR_INCORRECT_NODE_TYPE (-26)
@ -2121,7 +2121,7 @@ function size_t EsGameControllerStatePoll(EsGameControllerState *buffer); // Ret
function uint8_t EsKeyboardGetModifiers(); // Synchronous with respect to message processing.
function EsPoint EsMouseGetPosition(EsElement *relativeElement = ES_NULL);
function void EsMouseSetPosition(EsWindow *relativeWindow, int x, int y);
function EsError EsMouseSetPosition(EsWindow *relativeWindow, int x, int y); // The request will be rejected if the user is not clicking on your window.
function bool EsMouseIsLeftHeld();
function bool EsMouseIsRightHeld();
function bool EsMouseIsMiddleHeld();

View File

@ -145,6 +145,10 @@ ES_EXTERN_C uintptr_t _APISyscall(uintptr_t argument0, uintptr_t argument1, uint
#endif
#endif
#define ES_STRUCT_PACKED __attribute__((packed))
#define ES_FUNCTION_OPTIMISE_O2 __attribute__((optimize("-O2")))
#define ES_FUNCTION_OPTIMISE_O3 __attribute__((optimize("-O3")))
// --------- Algorithms:
#define ES_MACRO_SORT(_name, _type, _compar, _contextType) void _name(_type *base, size_t nmemb, _contextType context) { \

View File

@ -367,7 +367,7 @@ struct {
} theming;
#endif
__attribute__((optimize("-O2")))
ES_FUNCTION_OPTIMISE_O2
void ThemeFillRectangle(EsPainter *painter, EsRectangle bounds, ThemePaintData paint, GradientCache *gradient) {
uint32_t *bits = (uint32_t *) painter->target->bits;
int width = painter->target->width;
@ -463,9 +463,7 @@ void ThemeFillRectangle(EsPainter *painter, EsRectangle bounds, ThemePaintData p
}
}
#ifndef IN_DESIGNER
__attribute__((optimize("-O2")))
#endif
ES_FUNCTION_OPTIMISE_O2
void ThemeFillCorner(EsPainter *painter, EsRectangle bounds, int cx, int cy,
int border, int corner, ThemePaintData mainPaint, ThemePaintData borderPaint,
GradientCache *mainGradient, GradientCache *borderGradient) {
@ -571,15 +569,17 @@ void ThemeFillCorner(EsPainter *painter, EsRectangle bounds, int cx, int cy,
}
}
#ifndef IN_DESIGNER
__attribute__((optimize("-O2")))
#endif
ES_FUNCTION_OPTIMISE_O2
void ThemeFillBlurCutCorner(EsPainter *painter, EsRectangle bounds, int cx, int cy, int border, int corner, GradientCache *gradient, ThemePaintData mainPaint) {
uint32_t *bits = (uint32_t *) painter->target->bits;
int width = painter->target->width;
cx += bounds.l, cy += bounds.t;
bounds = ThemeRectangleIntersection(bounds, painter->clip);
if (!THEME_RECT_VALID(bounds)) {
return;
}
int dp = (GRADIENT_CACHE_COUNT << GRADIENT_COORD_BASE) / border;
float mainRadius = corner > border ? corner - border : 0;
@ -622,15 +622,17 @@ void ThemeFillBlurCutCorner(EsPainter *painter, EsRectangle bounds, int cx, int
}
}
#ifndef IN_DESIGNER
__attribute__((optimize("-O2")))
#endif
ES_FUNCTION_OPTIMISE_O2
void ThemeFillBlurCorner(EsPainter *painter, EsRectangle bounds, int cx, int cy, int border, int corner, GradientCache *gradient) {
uint32_t *bits = (uint32_t *) painter->target->bits;
int width = painter->target->width;
cx += bounds.l, cy += bounds.t;
bounds = ThemeRectangleIntersection(bounds, painter->clip);
if (!THEME_RECT_VALID(bounds)) {
return;
}
int dp = (GRADIENT_CACHE_COUNT << GRADIENT_COORD_BASE) / border;
int mainRadius = corner > border ? corner - border : 0;
@ -648,7 +650,7 @@ void ThemeFillBlurCorner(EsPainter *painter, EsRectangle bounds, int cx, int cy,
}
}
__attribute__((optimize("-O2")))
ES_FUNCTION_OPTIMISE_O2
void GradientCacheSetup(GradientCache *cache, const ThemePaintLinearGradient *gradient, int width, int height, EsBuffer *data) {
width--, height--;

View File

@ -20,7 +20,7 @@ struct SuperBlockCommon {
uint16_t heads;
uint32_t hiddenSectors;
uint32_t largeSectorCount;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct SuperBlock16 : SuperBlockCommon {
uint8_t deviceID;
@ -30,7 +30,7 @@ struct SuperBlock16 : SuperBlockCommon {
uint8_t label[11];
uint64_t systemIdentifier;
uint8_t _unused1[450];
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct SuperBlock32 : SuperBlockCommon {
uint32_t sectorsPerFAT32;
@ -47,7 +47,7 @@ struct SuperBlock32 : SuperBlockCommon {
uint8_t label[11];
uint64_t systemIdentifier;
uint8_t _unused1[422];
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct DirectoryEntry {
uint8_t name[11];
@ -62,7 +62,7 @@ struct DirectoryEntry {
uint16_t modificationDate;
uint16_t firstClusterLow;
uint32_t fileSizeBytes;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct Volume : KFileSystem {
union {

View File

@ -29,7 +29,7 @@ struct DateTime {
char second[2];
char centiseconds[2];
int8_t timeZoneOffset;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct DateTime2 {
uint8_t year;
@ -39,7 +39,7 @@ struct DateTime2 {
uint8_t minute;
uint8_t second;
int8_t timeZoneOffset;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct DirectoryRecord {
uint8_t length;
@ -52,7 +52,7 @@ struct DirectoryRecord {
uint8_t interleavedGapSize;
LBE16 volumeSequenceNumber;
uint8_t fileNameBytes;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct PrimaryDescriptor {
uint8_t typeCode;
@ -89,7 +89,7 @@ struct PrimaryDescriptor {
uint8_t _unused3;
char applicationSpecific[512];
uint8_t _unused4[653];
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct DirectoryRecordReference {
uint32_t sector, offset;

View File

@ -30,7 +30,7 @@ struct BootSector {
uint32_t checksum;
uint8_t bootloader[426];
uint16_t bootSignature;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct FileRecordHeader {
uint32_t magic;
@ -47,7 +47,7 @@ struct FileRecordHeader {
uint16_t nextAttributeID;
uint16_t unused;
uint32_t recordNumber;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct AttributeHeader {
uint32_t attributeType;
@ -57,14 +57,14 @@ struct AttributeHeader {
uint16_t nameOffset;
uint16_t flags;
uint16_t attributeID;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct ResidentAttributeHeader : AttributeHeader {
uint32_t attributeLength;
uint16_t attributeOffset;
uint8_t indexed;
uint8_t unused;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct FileNameAttributeHeader {
uint64_t parentRecordNumber : 48;
@ -79,7 +79,7 @@ struct FileNameAttributeHeader {
uint32_t reparse;
uint8_t fileNameLength;
uint8_t namespaceType;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct NonResidentAttributeHeader : AttributeHeader {
uint64_t firstCluster;
@ -90,12 +90,12 @@ struct NonResidentAttributeHeader : AttributeHeader {
uint64_t attributeAllocated;
uint64_t attributeSize;
uint64_t streamDataSize;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct RunHeader {
uint8_t lengthFieldBytes : 4;
uint8_t offsetFieldBytes : 4;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct IndexBlockHeader {
uint32_t magic;
@ -107,7 +107,7 @@ struct IndexBlockHeader {
uint32_t totalEntrySize;
uint32_t allocatedSize;
uint32_t flags;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct IndexRootHeader {
uint32_t attributeType;
@ -119,7 +119,7 @@ struct IndexRootHeader {
uint32_t totalEntrySize;
uint32_t allocatedSize;
uint32_t flags;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct IndexEntryHeader {
uint64_t fileRecordNumber : 48;
@ -127,7 +127,7 @@ struct IndexEntryHeader {
uint16_t indexEntryLength;
uint16_t streamLength;
uint32_t flags;
} __attribute__((packed));
} ES_STRUCT_PACKED;
// TODO Support other MFT file record sizes.
#define MFT_FILE_SIZE (1024)

View File

@ -30,7 +30,7 @@ struct CommandBlock {
uint8_t lun;
uint8_t commandBytes;
uint8_t command[16];
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct CommandStatus {
#define COMMAND_STATUS_SIGNATURE (0x53425355)
@ -40,7 +40,7 @@ struct CommandStatus {
#define STATUS_FAILED (1)
#define STATUS_PHASE_ERROR (2)
uint8_t status;
} __attribute__((packed));
} ES_STRUCT_PACKED;
bool Device::DoTransfer(CommandBlock *block, void *buffer) {
KMutexAcquire(&mutex);

View File

@ -419,7 +419,7 @@ EsError FSNodeDelete(KNode *node) {
FSDirectory *parent = entry->parent;
FSFile *file = entry->type == ES_NODE_FILE ? (FSFile *) node : nullptr;
if (!parent) return ES_ERROR_FILE_PERMISSION_NOT_GRANTED;
if (!parent) return ES_ERROR_PERMISSION_NOT_GRANTED;
// Open a handle to the parent, so that if its directory entry count drops to zero after the operation,
// it is put on the node cache list when the handle is closed.
@ -1260,7 +1260,7 @@ EsError FSNodeTraverseLayer(uintptr_t *sectionEnd,
// The node does not exist.
if (flags & _ES_NODE_NO_WRITE_BASE) {
error = ES_ERROR_FILE_PERMISSION_NOT_GRANTED;
error = ES_ERROR_PERMISSION_NOT_GRANTED;
goto failed;
}
@ -1359,7 +1359,7 @@ EsError FSNodeTraverseLayer(uintptr_t *sectionEnd,
KNodeInformation FSNodeOpen(const char *path, size_t pathBytes, uint32_t flags, KNode *baseDirectory) {
if ((1 << (flags & 0xF)) & ~(0x117)) {
// You should only pass one access flag! (or none)
return { ES_ERROR_FILE_PERMISSION_NOT_GRANTED };
return { ES_ERROR_PERMISSION_NOT_GRANTED };
}
if (fs.shutdown) return { ES_ERROR_PATH_NOT_TRAVERSABLE };

View File

@ -232,7 +232,7 @@ void Surface::Scroll(EsRectangle region, ptrdiff_t delta, bool vertical) {
#define C2(p) ((p & 0x00FF0000) >> 0x10)
#define C3(p) ((p & 0xFF000000) >> 0x18)
__attribute__((optimize("-O2")))
ES_FUNCTION_OPTIMISE_O2
void BlurRegionOfImage(uint32_t *image, int width, int height, int stride, uint16_t *k, uintptr_t repeat) {
if (width <= 3 || height <= 3) {
return;
@ -273,7 +273,7 @@ void BlurRegionOfImage(uint32_t *image, int width, int height, int stride, uint1
}
}
__attribute__((optimize("-O2")))
ES_FUNCTION_OPTIMISE_O2
void BlurRegionOfImage(uint32_t *image, int width, int height, int stride, uintptr_t repeat) {
if (width <= 3 || height <= 3) {
return;
@ -337,7 +337,7 @@ void Surface::Blur(EsRectangle region, EsRectangle clip) {
#endif
}
__attribute__((optimize("-O2")))
ES_FUNCTION_OPTIMISE_O2
void Surface::BlendWindow(Surface *source, EsPoint destinationPoint, EsRectangle sourceRegion, int material, uint8_t alpha, EsRectangle materialRegion) {
if (destinationPoint.x < 0) { sourceRegion.l -= destinationPoint.x; destinationPoint.x = 0; }
if (destinationPoint.y < 0) { sourceRegion.t -= destinationPoint.y; destinationPoint.y = 0; }

View File

@ -704,7 +704,7 @@ void KPCIWriteConfig(uint8_t bus, uint8_t device, uint8_t function, uint8_t offs
struct KUSBDescriptorHeader {
uint8_t length;
uint8_t descriptorType;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct KUSBConfigurationDescriptor : KUSBDescriptorHeader {
uint16_t totalLength;
@ -713,7 +713,7 @@ struct KUSBConfigurationDescriptor : KUSBDescriptorHeader {
uint8_t configurationString;
uint8_t attributes;
uint8_t maximumPower;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct KUSBInterfaceDescriptor : KUSBDescriptorHeader {
uint8_t interfaceIndex;
@ -723,7 +723,7 @@ struct KUSBInterfaceDescriptor : KUSBDescriptorHeader {
uint8_t interfaceSubclass;
uint8_t interfaceProtocol;
uint8_t interfaceString;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct KUSBDeviceDescriptor : KUSBDescriptorHeader {
uint16_t specificationVersion;
@ -738,7 +738,7 @@ struct KUSBDeviceDescriptor : KUSBDescriptorHeader {
uint8_t productString;
uint8_t serialNumberString;
uint8_t configurationCount;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct KUSBEndpointCompanionDescriptor : KUSBDescriptorHeader {
uint8_t maxBurst;
@ -747,12 +747,12 @@ struct KUSBEndpointCompanionDescriptor : KUSBDescriptorHeader {
inline uint8_t GetMaximumStreams() { return attributes & 0x1F; }
inline bool HasISOCompanion() { return attributes & (1 << 7); }
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct KUSBEndpointIsochronousCompanionDescriptor : KUSBDescriptorHeader {
uint16_t reserved;
uint32_t bytesPerInterval;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct KUSBEndpointDescriptor : KUSBDescriptorHeader {
uint8_t address;
@ -768,7 +768,7 @@ struct KUSBEndpointDescriptor : KUSBDescriptorHeader {
inline bool IsOutput() { return !(address & 0x80); }
inline uint8_t GetAddress() { return address & 0x0F; }
inline uint16_t GetMaximumPacketSize() { return maximumPacketSize & 0x7FF; }
} __attribute__((packed));
} ES_STRUCT_PACKED;
typedef void (*KUSBTransferCallback)(ptrdiff_t bytesNotTransferred /* -1 if error */, EsGeneric context);

View File

@ -33,7 +33,7 @@ struct EthernetHeader {
KMACAddress destinationMAC;
KMACAddress sourceMAC;
uint16_t type;
} __attribute__((packed));
} ES_STRUCT_PACKED;
#define ETHERNET_HEADER(ethernet, _type, _destinationMAC) \
if (ethernet) { \
@ -72,7 +72,7 @@ struct IPHeader {
return SwapBigEndian16(~sum);
}
} __attribute__((packed));
} ES_STRUCT_PACKED;
#define IP_HEADER(ip, _destinationAddress, _protocol) \
if (ip) { \
@ -142,7 +142,7 @@ struct UDPHeader {
return (sum == 0xFFFF) ? 0xFFFF : SwapBigEndian16(~sum);
}
} __attribute__((packed));
} ES_STRUCT_PACKED;
#define UDP_HEADER(udp, _sourcePort, _destinationPort) \
if (udp) { \
@ -204,7 +204,7 @@ struct TCPHeader {
return SwapBigEndian16(~sum);
}
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct TCPReceivedData {
uint16_t flags;
@ -291,7 +291,7 @@ struct DHCPHeader {
uint8_t serverHostName[64];
uint8_t bootFileName[128];
uint8_t optionsMagic[4];
} __attribute__((packed));
} ES_STRUCT_PACKED;
#define DHCP_HEADER(dhcp, _opCode) \
if (dhcp) { \
@ -342,7 +342,7 @@ struct ARPHeader {
uint8_t hardwareAddressLength;
uint8_t protocolAddressLength;
uint16_t opCode;
} __attribute__((packed));
} ES_STRUCT_PACKED;
#define ARP_ETHERNET (0x0001)
#define ARP_IPV4 (0x0800)
@ -380,7 +380,7 @@ struct ICMPHeader {
return SwapBigEndian16(~sum);
}
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct DNSHeader {
uint16_t identifier;
@ -389,7 +389,7 @@ struct DNSHeader {
uint16_t answerCount;
uint16_t authorityCount;
uint16_t additionalCount;
} __attribute__((packed));
} ES_STRUCT_PACKED;
struct Networking {
KMutex interfacesListMutex;

View File

@ -768,7 +768,7 @@ SYSCALL_IMPLEMENT(syscallName) { \
CHECK_OBJECT(_process); \
Process *process = (Process *) _process.object; \
uint32_t sharedFlags = _sharedFlags; \
if (!OpenHandleToObject(share.object, objectType, sharedFlags)) return ES_ERROR_FILE_PERMISSION_NOT_GRANTED; \
if (!OpenHandleToObject(share.object, objectType, sharedFlags)) return ES_ERROR_PERMISSION_NOT_GRANTED; \
SYSCALL_RETURN(process->handleTable.OpenHandle(share.object, sharedFlags, objectType), false); \
}
@ -827,7 +827,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_NODE_OPEN) {
}
if ((~_directory.flags & _ES_NODE_DIRECTORY_WRITE) && needWritePermission) {
SYSCALL_RETURN(ES_ERROR_FILE_PERMISSION_NOT_GRANTED, false);
SYSCALL_RETURN(ES_ERROR_PERMISSION_NOT_GRANTED, false);
}
if (~_directory.flags & _ES_NODE_DIRECTORY_WRITE) {
@ -863,7 +863,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_NODE_DELETE) {
KNode *node = (KNode *) object.object;
if (object.flags & _ES_NODE_NO_WRITE_BASE) {
SYSCALL_RETURN(ES_ERROR_FILE_PERMISSION_NOT_GRANTED, false);
SYSCALL_RETURN(ES_ERROR_PERMISSION_NOT_GRANTED, false);
}
if (node->directoryEntry->type == ES_NODE_FILE && (~object.flags & ES_FILE_WRITE)) {
@ -1143,12 +1143,36 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_CURSOR_POSITION_GET) {
SYSCALL_IMPLEMENT(ES_SYSCALL_CURSOR_POSITION_SET) {
KMutexAcquire(&windowManager.mutex);
windowManager.cursorX = argument0;
windowManager.cursorY = argument1;
windowManager.cursorXPrecise = argument0 * K_CURSOR_MOVEMENT_SCALE;
windowManager.cursorYPrecise = argument1 * K_CURSOR_MOVEMENT_SCALE;
// Only allow the cursor position to be modified by the process
// if it owns the window that is currently being pressed.
bool allowed = false;
if (windowManager.pressedWindow) {
if (windowManager.pressedWindow->embed) {
if (windowManager.pressedWindow->embed->owner == currentProcess) {
allowed = true;
}
}
if (windowManager.pressedWindow->owner == currentProcess) {
allowed = true;
}
}
if (allowed) {
// Preseve the precise offset.
int32_t offsetX = windowManager.cursorXPrecise - windowManager.cursorX * K_CURSOR_MOVEMENT_SCALE;
int32_t offsetY = windowManager.cursorYPrecise - windowManager.cursorY * K_CURSOR_MOVEMENT_SCALE;
windowManager.cursorX = argument0;
windowManager.cursorY = argument1;
windowManager.cursorXPrecise = argument0 * K_CURSOR_MOVEMENT_SCALE + offsetX;
windowManager.cursorYPrecise = argument1 * K_CURSOR_MOVEMENT_SCALE + offsetY;
}
KMutexRelease(&windowManager.mutex);
SYSCALL_RETURN(ES_SUCCESS, false);
SYSCALL_RETURN(allowed ? ES_SUCCESS : ES_ERROR_PERMISSION_NOT_GRANTED, false);
}
SYSCALL_IMPLEMENT(ES_SYSCALL_CURSOR_PROPERTIES_SET) {

View File

@ -96,8 +96,8 @@ struct WindowManager {
// Cursor:
int cursorX, cursorY;
int cursorXPrecise, cursorYPrecise; // Scaled up by a factor of K_CURSOR_MOVEMENT_SCALE.
int32_t cursorX, cursorY;
int32_t cursorXPrecise, cursorYPrecise; // Scaled up by a factor of K_CURSOR_MOVEMENT_SCALE.
uint32_t lastButtons;
Surface cursorSurface, cursorSwap, cursorTemporary;
@ -196,8 +196,7 @@ void SendMessageToWindow(Window *window, EsMessage *message) {
window->embed->owner->messageQueue.SendMessage(window->embed->apiWindow, message);
} else if (message->type == ES_MSG_MOUSE_MOVED) {
EsRectangle embedRegion = ES_RECT_4(WINDOW_INSET, window->width - WINDOW_INSET, WINDOW_INSET + CONTAINER_TAB_BAND_HEIGHT, window->height - WINDOW_INSET);
bool inEmbed = windowManager.pressedWindow
? window->hoveringOverEmbed
bool inEmbed = windowManager.pressedWindow ? window->hoveringOverEmbed
: EsRectangleContains(embedRegion, message->mouseMoved.newPositionX, message->mouseMoved.newPositionY);
if (inEmbed) {
@ -570,6 +569,8 @@ void WindowManager::ClickCursor(unsigned buttons) {
if (delta & K_RIGHT_BUTTON) message.type = (buttons & K_RIGHT_BUTTON) ? ES_MSG_MOUSE_RIGHT_DOWN : ES_MSG_MOUSE_RIGHT_UP;
if (delta & K_MIDDLE_BUTTON) message.type = (buttons & K_MIDDLE_BUTTON) ? ES_MSG_MOUSE_MIDDLE_DOWN : ES_MSG_MOUSE_MIDDLE_UP;
// TODO Setting pressedWindow if holding with other mouse buttons.
if (message.type == ES_MSG_MOUSE_LEFT_DOWN) {
pressedWindow = window;
} else if (message.type == ES_MSG_MOUSE_LEFT_UP) {

Binary file not shown.

Binary file not shown.

View File

@ -167,7 +167,7 @@ EsRectangle EsRectangleCut(EsRectangle a, int32_t amount, char side) {
#ifdef SHARED_COMMON_WANT_RENDERING
__attribute__((optimize("-O3")))
ES_FUNCTION_OPTIMISE_O3
void BlendPixel(uint32_t *destinationPixel, uint32_t modified, bool fullAlpha) {
if ((modified & 0xFF000000) == 0xFF000000) {
*destinationPixel = modified;

View File

@ -42,6 +42,7 @@
#define EsCRTceilf ceilf
#define EsMemoryCopy memcpy
#define EsMemoryZero(a, b) memset((a), 0, (b))
#define ES_FUNCTION_OPTIMISE_O2 __attribute__((optimize("-O2")))
#define ES_INFINITY INFINITY
#define IN_DESIGNER