Commit graph

905 commits

Author SHA1 Message Date
Niklas Poslovski
ebc5b33b77 LibCore: Don't include sys/sysctl.h on Solaris 2023-08-24 22:07:28 +01:00
nipos
abf7941bb9 LibCore: Change Errno to Error in FreeBSD and NetBSD-specific functions 2023-08-20 12:48:37 -06:00
Sam Atkins
dfb5ba0e2c LibCore: Prevent duplicate ArgsParser option names
Inspired by #20641, detect when adding an option that its long and short
names are both unique. If they are not, print a warning and crash.
2023-08-19 16:27:53 +02:00
Nicolas Ramz
fda5590313 LibGfx/ILBM: Add an IFF-ILBM decoder :)
IFF was a generic container fileformat that was popular on the Amiga
since it was the only file format supported by Deluxe Paint.

ILBM is an image format popular in the late eighties/nineties
that uses the IFF container.

This is a very first version of the decoder that only supports
(byterun) compressed files with bpp <= 8.

Only the minimal chunks are decoded: CMAP, BODY, BMHD.

I am planning to add support for the following variants:

- EHB (32 colours + lighter 32 colours)
- HAM6 / HAM8 (special mode that allowed to display the whole Amiga
4096 colours / 262 144 colours palette)
- TrueColor (24bit)

Things that could be fun to do:

- Still images could be animated using color cycle information
2023-08-15 18:36:11 +01:00
kleines Filmröllchen
001ea22917 AK+LibCore: Make output buffered stream seekable
Just like with input buffered streams, we don't currently have a use
case for output buffered streams which aren't seekable, since the main
application are files.
2023-08-12 12:25:26 -06:00
Lucas CHOLLET
3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Sebastian Zaha
fc71403842 LibCore: Implement Process::is_being_debugged for macOS
The wait_for_debugger_and_break helper now works on macOS with this
change, tested on lldb 14.
2023-08-07 13:16:28 -06:00
Sebastian Zaha
35c45a94d3 LibCore: Implement a helper that waits for a debugger then breaks
This method can be used to force the current process to sleep, waiting
for a debugger to attach. On attach, the debugger breaks at the callsite
 directly.

This is tested on Linux and macOS, in Clion and also terminal gdb and
lldb.
2023-08-07 13:16:28 -06:00
Sebastian Zaha
216667368d LibCore+Ladybird: Extract helper into generic Process::is_being_debugged 2023-08-07 13:16:28 -06:00
Sebastian Zaha
002e206af0 LibCore: Implement Process::get_name for linux and macos 2023-08-07 13:16:28 -06:00
Andreas Kling
34344120f2 AK: Make "foo"_string infallible
Stop worrying about tiny OOMs.

Work towards #20405.
2023-08-07 16:03:27 +02:00
Zaggy1024
db2a8725c6 LibCore: Only use coarse time in the Unix event loop wait_for_events()
A typo in the changes to our userland timekeeping classes caused us to
make a syscall every time we want to check whether a timer is ready to
fire in `EventLoopManagerUnix::wait_for_events()`. Instead, only use
coarse time, and get it immediately before it is used in both cases.

This reduces CPU usage by an (eyeballed) 20-30% while playing back
video with VideoPlayer.
2023-08-07 13:38:20 +02:00
Andreas Kling
ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Andreas Kling
bdf696e488 LibCore: Remove unused Core::Object::dump_tree() 2023-08-06 18:09:25 +02:00
Andreas Kling
887dfd72b9 LibCore+LibGUI: Remove leftover gunk after Inspector removal
Just some functions in Core::Object and GUI::Widget that aren't called
from anywhere anymore.
2023-08-06 18:09:25 +02:00
Andreas Kling
26647f2b10 LibCore: Remove the Core::Objects::all_objects() list
Nobody actually used the list of all Core::Objects anyway.
2023-08-06 18:09:25 +02:00
Andreas Kling
405187993a LibGUI+LibCore: Move GML property system from LibCore to LibGUI
Since Core::Object properties are really only used by GML now that the
Inspector is long gone, there's no need for these to pollute
Core::Object.

This patch adds a new GUI::Object class to hold properties, and makes
it the new base class of GUI::Window, GUI::Widget and GUI::Layout.
The "instantiate an object by name" mechanism that GML uses is also
hoisted into GUI::Object as well.
2023-08-06 18:09:25 +02:00
Liav A
93ef955597 LibCore: Keep the raw inode number value in DirectoryEntry
This will be used later on by other userspace programs that need it.
2023-08-05 18:41:01 +02:00
Zaggy1024
fe672989a9 LibCore: Add a class for thread-safe promises
Since the existing Promise class is designed with deferred tasks on the
main thread only, we need a new class that will ensure we can handle
promises that are resolved/rejected off the main thread.

This new class ensures that the callbacks are only called on the same
thread that the promise is fulfilled from. If the callbacks are not set
before the thread tries to fulfill the promise, it will spin until they
are so that they will run on that thread.
2023-08-04 13:49:36 -06:00
Zaggy1024
8626404ddb LibCore: Store the event loop stack as a function-scope thread_local
By allocating the event loop stack onto the heap, we were leaking it
when exiting. This way, we should avoid ASAN being unhappy with us.
2023-08-04 13:49:36 -06:00
Niklas Poslovski
6ea4be36b5 LibCore: Fallback to fstat() on systems without d_type support 2023-08-03 12:25:07 +01:00
Andrew Kaster
bb831a27dd LibCore: Add Core::System::current_executable_path()
This is based on Jakt::File::current_executable_path() and all the other
sources I looked at to figure out the per-platform way to do this. My
goodness, every platform has its own bespoke way.
2023-08-03 09:55:20 +02:00
Shannon Booth
8751be09f9 AK: Serialize URL hosts with 'concept-host-serializer'
In order to follow spec text to achieve this, we need to change the
underlying representation of a host in AK::URL to deserialized format.
Before this, we were parsing the host and then immediately serializing
it again.

Making that change resulted in a whole bunch of fallout.

After this change, callers can access the serialized data through
this concept-host-serializer. The functional end result of this
change is that IPv6 hosts are now correctly serialized to be
surrounded with '[' and ']'.
2023-07-31 05:18:51 +02:00
Ali Mohammad Pur
9f4feb7315 LibCore: Move the Promise::await() result instead of returning a ref
Returning a reference resulted in Mail's use of Promise causing a crash.
Also, awaiting an already-awaited promise is an odd thing to do anyway,
so let's just make it release the resolved/rejected value instead of
returning a reference to it.

Co-Authored-By: Valtteri Koskivuori <vkoskiv@gmail.com>
2023-07-24 16:42:15 +03:30
Lucas CHOLLET
475f1b6083 LibCore+LibGfx+LibGUI: Consider JPEG XL files as images
This includes registering the mime type and adding it to both the list
of supported image format and the filter for images type in LibGUI.
2023-07-21 10:47:34 -06:00
Sam Atkins
9f5e105958 LibCore: Add mime types for font files 2023-07-20 08:02:12 +01:00
Andrew Kaster
7de4fb2947 LibCore: Build LocalSocket on Android 2023-07-19 12:25:37 -06:00
Shannon Booth
06a44ac2ff LibCore: Error on a fail to write in Command::write_lines 2023-07-18 14:48:45 +01:00
Shannon Booth
125145c682 LibCore: Port Command::write_lines to ErrorOr
Keeping this in line with Command::write.
2023-07-18 14:48:45 +01:00
Shannon Booth
5dd93474ee LibCore+Tests: Unify process handling into Command class
The Test262RunnerHandler class in test-test262 was made in order to
spawn a subprocess, connect to its input/output error pipes, and obtain
its return value.

Later on, a copy of this implementation was added to TestSed with
modifications, such as adding support for reading from the output pipes
as well.

Unify these two implementations into a new Core::Command class. This new
implementation is more closely modeled from the TestSed implementation
due to the extra functionality it implemented.
2023-07-18 14:48:45 +01:00
Shannon Booth
cb920b23cc LibCore: Add System::environment
Move this from an internal function of Core::Process so that it can be
used elsewhere.
2023-07-18 14:48:45 +01:00
Lucas CHOLLET
ce4b09dfd1 LibGfx: Register the mime type image/x-icon 2023-07-17 20:17:08 +01:00
Lucas CHOLLET
545fdc849f LibCore: Register the image/vnd.ms-dds mime type 2023-07-17 06:44:37 +01:00
Lucas CHOLLET
15bd708cfd file: Use the mime-type description provided by LibCore
This allows us to get rid of another mime-type list in the codebase.

To do so, the `get_description_from_mime_type` function is introduced in
this patch.
2023-07-14 17:33:06 +01:00
Lucas CHOLLET
c543a13835 LibCore: Share the mime-type list between the two detection methods
We used to have two separate lists for mime-type detection, one for
detection based on the file extension, and the other one for detection
based on byte sniffing.

This list also contains a general description that will be of use in
`file.cpp`.

To create this list, I had to fill in some gaps as the two lists started
to diverge.
2023-07-14 17:33:06 +01:00
Pierre Delagrave
fc065ee560 LibCore: Add Traits<Core::SocketAddress>::hash() 2023-07-14 05:54:17 +02:00
Peter Elliott
da96c151ab LibCore: Exit EventLoop::spin_until() when exit requested
This keeps WebContent from staying open if it's spinning forever trying
to load a page.
2023-07-12 05:51:00 +02:00
Valtteri Koskivuori
5615ea5386 LibCore: Replace non-breaking hyphens with regular ones in MimeData
These three lines were added in commits 41d5531, 0f7a651 and 97aca8f all
the way back in June 2020, and went unnoticed until Lucas pointed this
out during my refactoring.
2023-07-11 17:48:57 +01:00
Valtteri Koskivuori
ff83b909f0 LibCore: Sort and tidy up filename mime guess function
These too should be sorted alphabetically, as evidenced by the fact that
text/markdown was in there twice before this change. :^)
Also broke out tables of sufffixes and basenames we consider plaintext,
and sorted those alphabetically as well.
2023-07-11 17:48:57 +01:00
Valtteri Koskivuori
21473ea7f1 LibCore: Improve mime type enumeration sorting
It makes far more sense to sort by the standard mime type strings,
rather than the ad-hoc variable names associated with each enumeration.
This way, the sort looks nicer, and also matches the corresponding
description enumerations in the file utility.
2023-07-11 17:48:57 +01:00
Ali Mohammad Pur
0c5c75e8a4 LibCore: Slightly rework the Core::Promise API
The previous iteration of this API was somewhat odd and rough in random
places, which degraded usability and made less than perfect sense.
This commit reworks the API to be a little closer to more
conventional promise APIs (a la javascript promises).

Also adds a test to ensure the class even works.
2023-07-08 23:13:00 +01:00
Timothy Flynn
996c020b0d Everywhere: Remove 'clang-format off' comments that are no longer needed 2023-07-08 10:32:56 +01:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Timothy Flynn
aff81d318b Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-16 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.h")
2023-07-08 10:32:56 +01:00
kamp
5338eba39a LibCore: Remove some dead code in wait_for_events
Since max_fd_added and max_fd are initialized to -1 and 0 respectively
the former could never be greater than the latter.
2023-07-07 09:47:30 +02:00
kleines Filmröllchen
10edd38543 LibCore: Keep track of file offset to avoid system call for tell()
This optimization makes the new test run 2x faster.
2023-07-06 21:05:57 +02:00
Carwyn Nelson
a2591bc5fa LibCore: Make ArgParser::Arg::accept_value return ErrorOr<bool>
Much like the previous commit, this commit makes the
ArgParser::Arg::accept_value callback return an ErrorOr<bool> instead of
just a bool.

The aim of this is to make argument parsing more robust, especially
with the newer String api that returns an ErrorOr for many functions.
2023-07-04 04:26:58 +03:30
Carwyn Nelson
abbfb00a02 LibCore: Make ArgParser::Option::accept_value return ErrorOr<bool>
This commit makes the `ArgParser::Option::accept_value` property more
error-safe by ensuring it returns an ErrorOr<bool> instead of just a
bool.
2023-07-04 04:26:58 +03:30
Lucas CHOLLET
f3d15f53c9 LibCore: Add the template instantiation ArgsParser::add_option<u8>() 2023-07-04 00:01:06 +02:00
Lucas CHOLLET
1c1ba6a2bd LibCore: Be explicit about integers size
This concerns all template instantiations of `ArgsParser::add_option()`
for integers.
2023-07-04 00:01:06 +02:00