Compare commits

..

7 Commits

Author SHA1 Message Date
github-actions[bot]
2320030121 chore(master): release 0.6.57 (#130) 2024-12-07 22:19:36 +00:00
c53c398cac feat(patches/alpha-background): add experimental alpha-background patch (#129)
Resolves #111
2024-12-07 21:00:41 +00:00
github-actions[bot]
f7b2baa363 chore(master): release 0.6.56 (#128)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-12-03 03:23:24 +00:00
d396165808 fix(patches): improve chance of successful patch application by using -l
This causes patch to ignore whitespace changes, which should make it
more likely to apply patches which may not be an exact match.
2024-12-03 03:21:31 +00:00
66ccd9c6fd feat(options): add --patch option which accepts file path or URL (#127)
This allows users to easily apply custom patches from a file on disk, or
from a URL. It's particularly hady to quickly test out a changeset from
a GitHub commit/diff or elsewhere.
2024-12-03 03:14:14 +00:00
github-actions[bot]
907f7babbc chore(master): release 0.6.55 (#126)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-12-03 00:19:59 +00:00
e030fee670 feat(nix/deps): update nixpkgs from 24.11-beta to 24.11 2024-12-03 00:18:35 +00:00
7 changed files with 835 additions and 232 deletions

View File

@@ -1,3 +1,3 @@
{
".": "0.6.54"
".": "0.6.57"
}

View File

@@ -1,5 +1,31 @@
# Changelog
## [0.6.57](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.56...v0.6.57) (2024-12-07)
### Features
* **patches/alpha-background:** add experimental alpha-background patch ([#129](https://github.com/jimeh/build-emacs-for-macos/issues/129)) ([c53c398](https://github.com/jimeh/build-emacs-for-macos/commit/c53c398cace6479a9c188e46196462791960abee)), closes [#111](https://github.com/jimeh/build-emacs-for-macos/issues/111)
## [0.6.56](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.55...v0.6.56) (2024-12-03)
### Features
* **options:** add --patch option which accepts file path or URL ([#127](https://github.com/jimeh/build-emacs-for-macos/issues/127)) ([66ccd9c](https://github.com/jimeh/build-emacs-for-macos/commit/66ccd9c6fd077d558eae484cdbab831486fbfd58))
### Bug Fixes
* **patches:** improve chance of successful patch application by using -l ([d396165](https://github.com/jimeh/build-emacs-for-macos/commit/d396165808ab5852566e7ff6bcc23d47ddfdfdee))
## [0.6.55](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.54...v0.6.55) (2024-12-03)
### Features
* **nix/deps:** update nixpkgs from 24.11-beta to 24.11 ([e030fee](https://github.com/jimeh/build-emacs-for-macos/commit/e030fee6704618b7ddefea7424dff4e94f43e84d))
## [0.6.54](https://github.com/jimeh/build-emacs-for-macos/compare/v0.6.53...v0.6.54) (2024-12-01)

View File

@@ -131,7 +131,6 @@ Options:
-j, --parallel COUNT Compile using COUNT parallel processes (detected: 16)
--git-sha SHA Override detected git SHA of specified branch allowing builds of old commits
--[no-]use-nix Use Nix instead of Homebrew to find dependencies (default: enabled if IN_NIX_SHELL is set)
--[no-]xwidgets Enable/disable XWidgets if supported (default: enabled)
--[no-]tree-sitter Enable/disable tree-sitter if supported (default: enabled)
--[no-]native-comp Enable/disable native-comp (default: enabled if supported)
--optimize Shorthand for --native-march --native-mtune --fomit-frame-pointer (default: disabled)
@@ -142,10 +141,13 @@ Options:
--[no-]relink-eln-files Enable/disable re-linking shared libraries in bundled *.eln files (default: enabled)
--[no-]rsvg Enable/disable SVG image support via librsvg (default: enabled)
--[no-]dbus Enable/disable dbus support (default: enabled)
--no-titlebar Apply no-titlebar patch (default: disabled)
--posix-spawn Apply posix-spawn patch (deprecated)
--no-frame-refocus Apply no-frame-refocus patch (default: disabled)
--[no-]alpha-background Enable/disable experimental alpha-background patch when building Emacs 30.x - 31.x (default: disabled)
--no-frame-refocus Apply no-frame-refocus patch when building Emacs 27.x - 31.x (default: disabled)
--no-titlebar Apply no-titlebar patch when building Emacs 27.x - 28.x (default: disabled)
--[no-]xwidgets Enable/disable XWidgets when building Emacs 27.x (default: disabled)
--[no-]poll Apply poll patch (deprecated)
--posix-spawn Apply posix-spawn patch (deprecated)
-p, --patch=URL Specify a custom patch file or URL to apply to the Emacs source (can be used multiple times)
--[no-]fd-setsize SIZE Set an file descriptor (max open files) limit (default: 10000)
--github-src-repo REPO Specify a GitHub repo to download source tarballs from (default: emacs-mirror/emacs)
--[no-]github-auth Make authenticated GitHub API requests if GITHUB_TOKEN environment variable is set.(default: enabled)

View File

@@ -79,6 +79,16 @@ module Output
end
end
module Helpers
def valid_url?(uri)
uri = URI.parse(uri)
(uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)) &&
uri.host.respond_to?(:empty?) && !uri.host.empty?
rescue URI::InvalidURIError
false
end
end
module System
include Output
@@ -183,6 +193,7 @@ end
class Build
include Output
include System
include Helpers
DEFAULT_GITHUB_REPO = 'emacs-mirror/emacs'
@@ -207,7 +218,7 @@ class Build
end
tarball = download_tarball(meta[:sha])
@source_dir = extract_tarball(tarball, patches(options))
@source_dir = extract_tarball(tarball, build_patches)
autogen
detect_native_comp if options[:native_comp].nil?
@@ -1041,7 +1052,7 @@ class Build
end
end
def patches(opts = {})
def build_patches
p = []
# Enabled by default patches.
@@ -1118,7 +1129,7 @@ class Build
}
end
if opts[:xwidgets] && effective_version == 27
if options[:xwidgets] && effective_version == 27
p << {
url:
'https://github.com/d12frosted/homebrew-emacs-plus/raw/master/' \
@@ -1126,6 +1137,36 @@ class Build
}
end
if options[:alpha_background]
if effective_version == 29
p << {
file: File.join(
__dir__, 'patches', 'emacs-29', 'ns-alpha-background.patch'
)
}
elsif (30..31).include?(effective_version)
p << {
url:
"https://github.com/emacs-mirror/emacs/compare/#{meta[:sha]}" \
'...jonrubens:emacs:ns-alpha-background.patch'
}
end
end
# Custom patches.
options[:patches].each do |patch_str|
patch = {}
if valid_url?(patch_str)
patch[:url] = patch_str
elsif File.exist?(patch_str)
patch[:file] = patch_str
else
fatal "Patch file or URL not found: #{patch_str}"
end
p << patch
end
p.uniq
end
@@ -1134,7 +1175,9 @@ class Build
if patch[:file]
info 'Applying patch...'
FileUtils.cd(target) { run_cmd('patch', '-f', '-p1', '-i', patch[:file]) }
FileUtils.cd(target) do
run_cmd('patch', '-f', '-p1', '-l', '-i', patch[:file])
end
elsif patch[:url]
patch_dir = "#{target}/macos_patches"
run_cmd('mkdir', '-p', patch_dir)
@@ -1827,228 +1870,273 @@ class GccInfo
end
end
if __FILE__ == $PROGRAM_NAME
use_nix_default = !ENV.fetch('IN_NIX_SHELL', '').empty?
class CLIOptions
include Output
include Helpers
cli_options = {
work_dir: File.expand_path(__dir__),
native_full_aot: false,
relink_eln: true,
native_march: false,
parallel: Etc.nprocessors,
rsvg: true,
dbus: true,
use_nix: use_nix_default,
xwidgets: true,
tree_sitter: true,
fd_setsize: 10_000,
github_src_repo: nil,
github_auth: true,
dist_include: ['COPYING', 'configure_output.txt'],
self_sign: true,
archive: true,
archive_keep: false,
log_level: 'info'
}
parser = OptionParser.new do |opts|
opts.banner = <<~DOC
Usage: ./build-emacs-for-macos [options] <branch/tag/sha>
Branch, tag, and SHA are from the emacs-mirror/emacs/emacs Github repo,
available here: https://github.com/emacs-mirror/emacs
Options:
DOC
opts.on(
'--info',
'Print environment info and detected library paths, then exit'
) { |v| cli_options[:info] = v }
opts.on(
'--preview',
'Print preview details about build and exit.'
) { |v| cli_options[:preview] = v }
opts.on(
'-j',
'--parallel COUNT',
'Compile using COUNT parallel processes ' \
"(detected: #{cli_options[:parallel]})"
) { |v| cli_options[:parallel] = v }
opts.on(
'--git-sha SHA',
'Override detected git SHA of specified ' \
'branch allowing builds of old commits'
) { |v| cli_options[:git_sha] = v }
opts.on(
'--[no-]use-nix',
'Use Nix instead of Homebrew to find dependencies ' \
'(default: enabled if IN_NIX_SHELL is set)'
) { |v| cli_options[:use_nix] = v }
opts.on(
'--[no-]xwidgets',
'Enable/disable XWidgets if supported ' \
'(default: enabled)'
) { |v| cli_options[:xwidgets] = v }
opts.on(
'--[no-]tree-sitter',
'Enable/disable tree-sitter if supported ' \
'(default: enabled)'
) { |v| cli_options[:tree_sitter] = v }
opts.on(
'--[no-]native-comp',
'Enable/disable native-comp ' \
'(default: enabled if supported)'
) { |v| cli_options[:native_comp] = v }
opts.on(
'--optimize',
'Shorthand for --native-march --native-mtune --fomit-frame-pointer ' \
'(default: disabled)'
) do
cli_options[:native_march] = true
cli_options[:native_mtune] = true
cli_options[:fomit_frame_pointer] = true
end
opts.on(
'--[no-]native-march',
'Enable/disable -march=native CFLAG ' \
'(default: disabled)'
) { |v| cli_options[:native_march] = v }
opts.on(
'--[no-]native-mtune',
'Enable/disable -mtune=native CFLAG ' \
'(default: disabled)'
) { |v| cli_options[:native_mtune] = v }
opts.on(
'--[no-]fomit-frame-pointer',
'Enable/disable -fomit-frame-pointer CFLAG ' \
'(default: disabled)'
) { |v| cli_options[:fomit_frame_pointer] = v }
opts.on(
'--[no-]native-full-aot',
'Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation ' \
'(default: disabled)'
) { |v| cli_options[:native_full_aot] = v }
opts.on(
'--[no-]relink-eln-files',
'Enable/disable re-linking shared libraries in bundled *.eln ' \
'files (default: enabled)'
) { |v| cli_options[:relink_eln] = v }
opts.on(
'--[no-]rsvg',
'Enable/disable SVG image support via librsvg ' \
'(default: enabled)'
) { |v| cli_options[:rsvg] = v }
opts.on(
'--[no-]dbus',
'Enable/disable dbus support (default: enabled)'
) { |v| cli_options[:dbus] = v }
opts.on(
'--no-titlebar',
'Apply no-titlebar patch (default: disabled)'
) { cli_options[:no_titlebar] = true }
opts.on('--posix-spawn', 'Apply posix-spawn patch (deprecated)') do
warn '==> WARN: posix-spawn patch is deprecated and has no effect.'
end
opts.on(
'--no-frame-refocus',
'Apply no-frame-refocus patch (default: disabled)'
) { cli_options[:no_frame_refocus] = true }
opts.on('--[no-]poll', 'Apply poll patch (deprecated)') do
warn '==> WARN: poll patch is deprecated and has no effect.'
end
opts.on(
'--[no-]fd-setsize SIZE',
'Set an file descriptor (max open files) limit (default: 10000)'
) { |v| cli_options[:fd_setsize] = v.respond_to?(:to_i) ? v.to_i : 0 }
opts.on(
'--github-src-repo REPO',
'Specify a GitHub repo to download source tarballs from ' \
'(default: emacs-mirror/emacs)'
) { |v| cli_options[:github_src_repo] = v }
opts.on(
'--[no-]github-auth',
'Make authenticated GitHub API requests if GITHUB_TOKEN ' \
'environment variable is set.' \
'(default: enabled)'
) { |v| cli_options[:github_auth] = v }
opts.on(
'--work-dir DIR',
'Specify a working directory where tarballs, sources, and ' \
'builds will be stored and worked with'
) { |v| cli_options[:work_dir] = v }
opts.on(
'-o DIR',
'--output DIR',
'Output directory for finished builds ' \
'(default: <work-dir>/builds)'
) { |v| cli_options[:output] = v }
opts.on('--build-name NAME', 'Override generated build name') do |v|
cli_options[:build_name] = v
end
opts.on(
'--dist-include x,y,z',
'List of extra files to copy from Emacs source into build ' \
'folder/archive (default: COPYING)'
) { |v| cli_options[:dist_include] = v }
opts.on(
'--[no-]self-sign',
'Enable/disable self-signing of Emacs.app (default: enabled)'
) { |v| cli_options[:self_sign] = v }
opts.on(
'--[no-]archive',
'Enable/disable creating *.tbz archive (default: enabled)'
) { |v| cli_options[:archive] = v }
opts.on(
'--[no-]archive-keep-build-dir',
'Enable/disable keeping source folder for archive ' \
'(default: disabled)'
) { |v| cli_options[:archive_keep] = v }
opts.on(
'--log-level LEVEL',
'Build script log level (default: info)'
) { |v| cli_options[:log_level] = v }
opts.on(
'--plan FILE',
'Follow given plan file, instead of using given git ref/sha'
) { |v| cli_options[:plan] = v }
def self.parse(args)
inst = new
inst.parse!(args)
inst.options
end
begin
parser.parse!
def parse!(args)
parser.parse!(args)
rescue OptionParser::InvalidOption => e
fatal e.message
end
Output.log_level = cli_options[:log_level]
def options
@options ||= defaults.dup.tap do |o|
o.each { |k, v| o[k] = v.dup if v.is_a?(Array) }
end
end
def defaults
{
work_dir: File.expand_path(__dir__),
native_full_aot: false,
relink_eln: true,
native_march: false,
parallel: Etc.nprocessors,
rsvg: true,
dbus: true,
use_nix: !ENV.fetch('IN_NIX_SHELL', '').empty?,
xwidgets: true,
tree_sitter: true,
fd_setsize: 10_000,
github_src_repo: nil,
github_auth: true,
dist_include: ['COPYING', 'configure_output.txt'],
self_sign: true,
archive: true,
archive_keep: false,
patches: [],
log_level: 'info'
}
end
def parser
@parser ||= OptionParser.new do |opts|
opts.banner = <<~DOC
Usage: ./build-emacs-for-macos [options] <branch/tag/sha>
Branch, tag, and SHA are from the emacs-mirror/emacs/emacs Github repo,
available here: https://github.com/emacs-mirror/emacs
Options:
DOC
opts.on(
'--info',
'Print environment info and detected library paths, then exit'
) { |v| options[:info] = v }
opts.on(
'--preview',
'Print preview details about build and exit.'
) { |v| options[:preview] = v }
opts.on(
'-j',
'--parallel COUNT',
'Compile using COUNT parallel processes ' \
"(detected: #{options[:parallel]})"
) { |v| options[:parallel] = v }
opts.on(
'--git-sha SHA',
'Override detected git SHA of specified ' \
'branch allowing builds of old commits'
) { |v| options[:git_sha] = v }
opts.on(
'--[no-]use-nix',
'Use Nix instead of Homebrew to find dependencies ' \
'(default: enabled if IN_NIX_SHELL is set)'
) { |v| options[:use_nix] = v }
opts.on(
'--[no-]tree-sitter',
'Enable/disable tree-sitter if supported ' \
'(default: enabled)'
) { |v| options[:tree_sitter] = v }
opts.on(
'--[no-]native-comp',
'Enable/disable native-comp ' \
'(default: enabled if supported)'
) { |v| options[:native_comp] = v }
opts.on(
'--optimize',
'Shorthand for --native-march --native-mtune --fomit-frame-pointer ' \
'(default: disabled)'
) do
options[:native_march] = true
options[:native_mtune] = true
options[:fomit_frame_pointer] = true
end
opts.on(
'--[no-]native-march',
'Enable/disable -march=native CFLAG ' \
'(default: disabled)'
) { |v| options[:native_march] = v }
opts.on(
'--[no-]native-mtune',
'Enable/disable -mtune=native CFLAG ' \
'(default: disabled)'
) { |v| options[:native_mtune] = v }
opts.on(
'--[no-]fomit-frame-pointer',
'Enable/disable -fomit-frame-pointer CFLAG ' \
'(default: disabled)'
) { |v| options[:fomit_frame_pointer] = v }
opts.on(
'--[no-]native-full-aot',
'Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation ' \
'(default: disabled)'
) { |v| options[:native_full_aot] = v }
opts.on(
'--[no-]relink-eln-files',
'Enable/disable re-linking shared libraries in bundled *.eln ' \
'files (default: enabled)'
) { |v| options[:relink_eln] = v }
opts.on(
'--[no-]rsvg',
'Enable/disable SVG image support via librsvg ' \
'(default: enabled)'
) { |v| options[:rsvg] = v }
opts.on(
'--[no-]dbus',
'Enable/disable dbus support (default: enabled)'
) { |v| options[:dbus] = v }
opts.on(
'--alpha-background',
'Apply experimental alpha-background patch when building Emacs ' \
'30.x - 31.x (default: disabled)'
) { |v| options[:alpha_background] = v }
opts.on(
'--no-frame-refocus',
'Apply no-frame-refocus patch when building Emacs 27.x - 31.x ' \
'(default: disabled)'
) { options[:no_frame_refocus] = true }
opts.on(
'--no-titlebar',
'Apply no-titlebar patch when building Emacs 27.x - 28.x ' \
'(default: disabled)'
) { options[:no_titlebar] = true }
opts.on(
'--[no-]xwidgets',
'Enable/disable XWidgets when building Emacs 27.x ' \
'(default: disabled)'
) { |v| options[:xwidgets] = v }
opts.on('--[no-]poll', 'Apply poll patch (deprecated)') do
warn '==> WARN: poll patch is deprecated and has no effect.'
end
opts.on('--posix-spawn', 'Apply posix-spawn patch (deprecated)') do
warn '==> WARN: posix-spawn patch is deprecated and has no effect.'
end
opts.on(
'-p=URL', '--patch=URL',
'Specify a custom patch file or URL to apply to the Emacs source ' \
'(can be used multiple times)'
) do |v|
if !valid_url?(v) && !File.exist?(v)
fatal "Patch is not a URL or file: #{v}"
end
options[:patches] << v
end
opts.on(
'--[no-]fd-setsize SIZE',
'Set an file descriptor (max open files) limit (default: 10000)'
) { |v| options[:fd_setsize] = v.respond_to?(:to_i) ? v.to_i : 0 }
opts.on(
'--github-src-repo REPO',
'Specify a GitHub repo to download source tarballs from ' \
'(default: emacs-mirror/emacs)'
) { |v| options[:github_src_repo] = v }
opts.on(
'--[no-]github-auth',
'Make authenticated GitHub API requests if GITHUB_TOKEN ' \
'environment variable is set.' \
'(default: enabled)'
) { |v| options[:github_auth] = v }
opts.on(
'--work-dir DIR',
'Specify a working directory where tarballs, sources, and ' \
'builds will be stored and worked with'
) { |v| options[:work_dir] = v }
opts.on(
'-o DIR',
'--output DIR',
'Output directory for finished builds ' \
'(default: <work-dir>/builds)'
) { |v| options[:output] = v }
opts.on('--build-name NAME', 'Override generated build name') do |v|
options[:build_name] = v
end
opts.on(
'--dist-include x,y,z',
'List of extra files to copy from Emacs source into build ' \
'folder/archive (default: COPYING)'
) { |v| options[:dist_include] = v }
opts.on(
'--[no-]self-sign',
'Enable/disable self-signing of Emacs.app (default: enabled)'
) { |v| options[:self_sign] = v }
opts.on(
'--[no-]archive',
'Enable/disable creating *.tbz archive (default: enabled)'
) { |v| options[:archive] = v }
opts.on(
'--[no-]archive-keep-build-dir',
'Enable/disable keeping source folder for archive ' \
'(default: disabled)'
) { |v| options[:archive_keep] = v }
opts.on(
'--log-level LEVEL',
'Build script log level (default: info)'
) { |v| options[:log_level] = v }
opts.on(
'--plan FILE',
'Follow given plan file, instead of using given git ref/sha'
) { |v| options[:plan] = v }
end
end
end
if __FILE__ == $PROGRAM_NAME
begin
cli_options = CLIOptions.parse(ARGV)
Output.log_level = cli_options.delete(:log_level)
work_dir = cli_options.delete(:work_dir)
build = Build.new(work_dir, ARGV.shift, cli_options)

8
flake.lock generated
View File

@@ -20,16 +20,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1731603435,
"narHash": "sha256-CqCX4JG7UiHvkrBTpYC3wcEurvbtTADLbo3Ns2CEoL8=",
"lastModified": 1732981179,
"narHash": "sha256-F7thesZPvAMSwjRu0K8uFshTk3ZZSNAsXTIFvXBT+34=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8b27c1239e5c421a2bbc2c65d52e4a6fbf2ff296",
"rev": "62c435d93bf046a5396f3016472e8f7c8e2aed65",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "24.11-beta",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}

View File

@@ -2,7 +2,7 @@
description = "Development environment flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/24.11-beta";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};

View File

@@ -0,0 +1,487 @@
From 9b436ccb00ea321fe778ea51cf1ad536aff7210f Mon Sep 17 00:00:00 2001
From: Jon Rubens <jonathanrubens@gmail.com>
Date: Wed, 24 Jan 2024 19:45:55 -0800
Subject: [PATCH 1/3] Enable frame parameter alpha_background for MacOS
---
src/macfont.m | 10 ++++++++--
src/nsfns.m | 42 ++++++++++++++++++++++++++++++++++--------
src/nsterm.m | 42 ++++++++++++++++++++++--------------------
3 files changed, 64 insertions(+), 30 deletions(-)
diff --git a/src/macfont.m b/src/macfont.m
index 8aba440d196e..56c1eb57024e 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -2953,9 +2953,14 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face);
else
CG_SET_FILL_COLOR_WITH_FRAME_CURSOR (context, f);
- }
+ CGContextSetAlpha(context, 1);
+ }
else
- CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face);
+ {
+ CGContextSetAlpha(context, f->alpha_background);
+ CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face);
+ }
+ CGContextClearRect(context, background_rect);
CGContextFillRects (context, &background_rect, 1);
}
@@ -2964,6 +2969,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
CGAffineTransform atfm;
CGContextScaleCTM (context, 1, -1);
+ CGContextSetAlpha(context, 1);
if (s->hl == DRAW_CURSOR)
{
if (face && (NS_FACE_BACKGROUND (face)
diff --git a/src/nsfns.m b/src/nsfns.m
index b0281aac2572..3e19cce89de9 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -301,7 +301,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
struct face *face;
NSColor *col;
NSView *view = FRAME_NS_VIEW (f);
- EmacsCGFloat alpha;
+ EmacsCGFloat alpha = f->alpha_background;
block_input ();
if (ns_lisp_to_color (arg, &col))
@@ -316,11 +316,10 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
f->output_data.ns->background_color = col;
FRAME_BACKGROUND_PIXEL (f) = [col unsignedLong];
- alpha = [col alphaComponent];
if (view != nil)
{
- [[view window] setBackgroundColor: col];
+ [[view window] setBackgroundColor: [col colorWithAlphaComponent: alpha]];
if (alpha != (EmacsCGFloat) 1.0)
[[view window] setOpaque: NO];
@@ -330,10 +329,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
face = FRAME_DEFAULT_FACE (f);
if (face)
{
- col = [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)];
- face->background = [[col colorWithAlphaComponent: alpha]
- unsignedLong];
-
+ face->background = [col unsignedLong];
update_face_from_frame_parameter (f, Qbackground_color, arg);
}
@@ -346,6 +342,36 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
unblock_input ();
}
+static void
+ns_set_alpha_background (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+{
+ NSView *view = FRAME_NS_VIEW (f);
+ double alpha = 1.0;
+
+ if (NILP (arg))
+ alpha = 1.0;
+ else if (FLOATP (arg))
+ {
+ alpha = XFLOAT_DATA (arg);
+ if (! (0 <= alpha && alpha <= 1.0))
+ args_out_of_range (make_float (0.0), make_float (1.0));
+ }
+ else if (FIXNUMP (arg))
+ {
+ EMACS_INT ialpha = XFIXNUM (arg);
+ if (! (0 <= ialpha && ialpha <= 100))
+ args_out_of_range (make_fixnum (0), make_fixnum (100));
+ alpha = ialpha / 100.0;
+ }
+ else
+ wrong_type_argument (Qnumberp, arg);
+
+ f->alpha_background = alpha;
+ [[view window] setBackgroundColor: [f->output_data.ns->background_color
+ colorWithAlphaComponent: alpha]];
+ recompute_basic_faces (f);
+ SET_FRAME_GARBAGED (f);
+}
static void
ns_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
@@ -1065,7 +1091,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
ns_set_z_group,
0, /* x_set_override_redirect */
gui_set_no_special_glyphs,
- gui_set_alpha_background,
+ ns_set_alpha_background,
NULL,
#ifdef NS_IMPL_COCOA
ns_set_appearance,
diff --git a/src/nsterm.m b/src/nsterm.m
index 518b38658d17..bda3a12172f5 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2618,8 +2618,9 @@ Hide the window (X11 semantics)
block_input ();
ns_focus (f, &r, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
- (FACE_FROM_ID (f, DEFAULT_FACE_ID))] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
+ (FACE_FROM_ID (f, DEFAULT_FACE_ID))]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (r);
ns_unfocus (f);
@@ -2647,7 +2648,7 @@ Hide the window (X11 semantics)
r = NSIntersectionRect (r, [view frame]);
ns_focus (f, &r, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (r);
@@ -2751,7 +2752,7 @@ Hide the window (X11 semantics)
return;
ns_focus (f, NULL, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (NSMakeRect (0, margin, width, border));
NSRectFill (NSMakeRect (0, 0, border, height));
NSRectFill (NSMakeRect (0, margin, width, border));
@@ -2802,7 +2803,7 @@ Hide the window (X11 semantics)
NSRect r = NSMakeRect (0, y, FRAME_PIXEL_WIDTH (f), height);
ns_focus (f, &r, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (NSMakeRect (0, y, width, height));
NSRectFill (NSMakeRect (FRAME_PIXEL_WIDTH (f) - width,
y, width, height));
@@ -2966,8 +2967,7 @@ Hide the window (X11 semantics)
if (! NSIsEmptyRect (clearRect))
{
NSTRACE_RECT ("clearRect", clearRect);
-
- [[NSColor colorWithUnsignedLong:face->background] set];
+ [[[NSColor colorWithUnsignedLong:face->background] colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (clearRect);
}
@@ -2998,7 +2998,7 @@ Hide the window (X11 semantics)
else
bm_color = f->output_data.ns->cursor_color;
- [bm_color set];
+ [[bm_color colorWithAlphaComponent:f->alpha_background] set];
[bmp fill];
[bmp release];
@@ -3719,7 +3719,7 @@ Function modeled after x_draw_glyph_string_box ().
if (s->face->box == FACE_SIMPLE_BOX && s->face->box_color)
{
ns_draw_box (r, abs (hthickness), abs (vthickness),
- [NSColor colorWithUnsignedLong:face->box_color],
+ [[NSColor colorWithUnsignedLong:face->box_color] colorWithAlphaComponent: s->f->alpha_background],
left_p, right_p);
}
else
@@ -3757,8 +3757,10 @@ Function modeled after x_draw_glyph_string_box ().
{
if (s->hl != DRAW_CURSOR)
[(NS_FACE_BACKGROUND (face) != 0
- ? [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ ? [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: s->f->alpha_background]
: FRAME_BACKGROUND_COLOR (s->f)) set];
+
else if (face && (NS_FACE_BACKGROUND (face)
== [(NSColor *) FRAME_CURSOR_COLOR (s->f)
unsignedLong]))
@@ -3902,7 +3904,7 @@ Function modeled after x_draw_glyph_string_box ().
otherwise, since we composite the image under NS (instead of mucking
with its background color), we must clear just the image area. */
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: s->f->alpha_background] set];
if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin
|| s->img->mask || s->img->pixmap == 0 || s->width != s->background_width)
@@ -3972,7 +3974,7 @@ Function modeled after x_draw_glyph_string_box ().
if (s->hl == DRAW_CURSOR)
{
[FRAME_CURSOR_COLOR (s->f) set];
- tdCol = [NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)];
+ tdCol = [[NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: s->f->alpha_background];
}
else
tdCol = [NSColor colorWithUnsignedLong: NS_FACE_FOREGROUND (face)];
@@ -4066,10 +4068,10 @@ Function modeled after x_draw_glyph_string_box ().
face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
prepare_face_for_display (s->f, face);
- [[NSColor colorWithUnsignedLong: face->background] set];
+ [[[NSColor colorWithUnsignedLong: face->background] colorWithAlphaComponent: s->f->alpha_background] set];
}
else
- [[NSColor colorWithUnsignedLong: s->face->background] set];
+ [[[NSColor colorWithUnsignedLong: s->face->background] colorWithAlphaComponent: s->f->alpha_background] set];
NSRectFill (NSMakeRect (x, y, w, h));
}
}
@@ -4095,7 +4097,7 @@ Function modeled after x_draw_glyph_string_box ().
if (s->hl == DRAW_CURSOR)
[FRAME_CURSOR_COLOR (s->f) set];
else
- [[NSColor colorWithUnsignedLong: s->face->background] set];
+ [[[NSColor colorWithUnsignedLong: s->face->background] colorWithAlphaComponent: s->f->alpha_background] set];
NSRectFill (NSMakeRect (x, s->y, background_width, s->height));
}
@@ -8436,8 +8438,8 @@ - (void)toggleFullScreen: (id)sender
}
[w setContentView:[fw contentView]];
- [w setBackgroundColor: col];
- if ([col alphaComponent] != (EmacsCGFloat) 1.0)
+ [w setBackgroundColor: [col colorWithAlphaComponent: f->alpha_background]];
+ if (f->alpha_background != (EmacsCGFloat) 1.0)
[w setOpaque: NO];
f->border_width = [w borderWidth];
@@ -9172,9 +9174,9 @@ - (instancetype) initWithEmacsFrame: (struct frame *) f
f->border_width = [self borderWidth];
col = [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
- (FACE_FROM_ID (f, DEFAULT_FACE_ID))];
- [self setBackgroundColor:col];
- if ([col alphaComponent] != (EmacsCGFloat) 1.0)
+ (FACE_FROM_ID (f, DEFAULT_FACE_ID))];
+ [self setBackgroundColor:[col colorWithAlphaComponent:f->alpha_background]];
+ if (f->alpha_background != (EmacsCGFloat) 1.0)
[self setOpaque:NO];
/* toolbar support */
From 58cf6e6da20eefca161c1ab1fd0d6ad67d1ba710 Mon Sep 17 00:00:00 2001
From: Jon Rubens <jonathanrubens@gmail.com>
Date: Fri, 26 Jan 2024 09:35:15 -0800
Subject: [PATCH 2/3] Fix code formatting
---
src/macfont.m | 8 ++++----
src/nsterm.m | 30 ++++++++++++++++++++----------
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/src/macfont.m b/src/macfont.m
index 56c1eb57024e..8fb835c7ff01 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -2953,14 +2953,14 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face);
else
CG_SET_FILL_COLOR_WITH_FRAME_CURSOR (context, f);
- CGContextSetAlpha(context, 1);
+ CGContextSetAlpha (context, 1);
}
else
{
- CGContextSetAlpha(context, f->alpha_background);
+ CGContextSetAlpha (context, f->alpha_background);
CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face);
}
- CGContextClearRect(context, background_rect);
+ CGContextClearRect (context, background_rect);
CGContextFillRects (context, &background_rect, 1);
}
@@ -2969,7 +2969,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
CGAffineTransform atfm;
CGContextScaleCTM (context, 1, -1);
- CGContextSetAlpha(context, 1);
+ CGContextSetAlpha (context, 1);
if (s->hl == DRAW_CURSOR)
{
if (face && (NS_FACE_BACKGROUND (face)
diff --git a/src/nsterm.m b/src/nsterm.m
index bda3a12172f5..9ab3ff8f783f 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2803,7 +2803,8 @@ Hide the window (X11 semantics)
NSRect r = NSMakeRect (0, y, FRAME_PIXEL_WIDTH (f), height);
ns_focus (f, &r, 1);
- [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (NSMakeRect (0, y, width, height));
NSRectFill (NSMakeRect (FRAME_PIXEL_WIDTH (f) - width,
y, width, height));
@@ -2967,7 +2968,8 @@ Hide the window (X11 semantics)
if (! NSIsEmptyRect (clearRect))
{
NSTRACE_RECT ("clearRect", clearRect);
- [[[NSColor colorWithUnsignedLong:face->background] colorWithAlphaComponent: f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong:face->background]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (clearRect);
}
@@ -3719,7 +3721,8 @@ Function modeled after x_draw_glyph_string_box ().
if (s->face->box == FACE_SIMPLE_BOX && s->face->box_color)
{
ns_draw_box (r, abs (hthickness), abs (vthickness),
- [[NSColor colorWithUnsignedLong:face->box_color] colorWithAlphaComponent: s->f->alpha_background],
+ [[NSColor colorWithUnsignedLong:face->box_color]
+ colorWithAlphaComponent: s->f->alpha_background],
left_p, right_p);
}
else
@@ -3904,7 +3907,8 @@ Function modeled after x_draw_glyph_string_box ().
otherwise, since we composite the image under NS (instead of mucking
with its background color), we must clear just the image area. */
- [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: s->f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: s->f->alpha_background] set];
if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin
|| s->img->mask || s->img->pixmap == 0 || s->width != s->background_width)
@@ -3974,7 +3978,8 @@ Function modeled after x_draw_glyph_string_box ().
if (s->hl == DRAW_CURSOR)
{
[FRAME_CURSOR_COLOR (s->f) set];
- tdCol = [[NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: s->f->alpha_background];
+ tdCol = [[NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: s->f->alpha_background];
}
else
tdCol = [NSColor colorWithUnsignedLong: NS_FACE_FOREGROUND (face)];
@@ -4068,10 +4073,12 @@ Function modeled after x_draw_glyph_string_box ().
face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
prepare_face_for_display (s->f, face);
- [[[NSColor colorWithUnsignedLong: face->background] colorWithAlphaComponent: s->f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong: face->background]
+ colorWithAlphaComponent: s->f->alpha_background] set];
}
else
- [[[NSColor colorWithUnsignedLong: s->face->background] colorWithAlphaComponent: s->f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong: s->face->background]
+ colorWithAlphaComponent: s->f->alpha_background] set];
NSRectFill (NSMakeRect (x, y, w, h));
}
}
@@ -4097,7 +4104,8 @@ Function modeled after x_draw_glyph_string_box ().
if (s->hl == DRAW_CURSOR)
[FRAME_CURSOR_COLOR (s->f) set];
else
- [[[NSColor colorWithUnsignedLong: s->face->background] colorWithAlphaComponent: s->f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong: s->face->background]
+ colorWithAlphaComponent: s->f->alpha_background] set];
NSRectFill (NSMakeRect (x, s->y, background_width, s->height));
}
@@ -8438,7 +8446,8 @@ - (void)toggleFullScreen: (id)sender
}
[w setContentView:[fw contentView]];
- [w setBackgroundColor: [col colorWithAlphaComponent: f->alpha_background]];
+ [w setBackgroundColor: [col colorWithAlphaComponent:
+ f->alpha_background]];
if (f->alpha_background != (EmacsCGFloat) 1.0)
[w setOpaque: NO];
@@ -9175,7 +9184,8 @@ - (instancetype) initWithEmacsFrame: (struct frame *) f
col = [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
(FACE_FROM_ID (f, DEFAULT_FACE_ID))];
- [self setBackgroundColor:[col colorWithAlphaComponent:f->alpha_background]];
+ [self setBackgroundColor:
+ [col colorWithAlphaComponent:f->alpha_background]];
if (f->alpha_background != (EmacsCGFloat) 1.0)
[self setOpaque:NO];
From 896596aac2932ab98dbeb68f48a963275fdb76c5 Mon Sep 17 00:00:00 2001
From: Jon Rubens <jonathanrubens@gmail.com>
Date: Wed, 31 Jan 2024 13:30:13 -0800
Subject: [PATCH 3/3] More code formatting
---
src/nsfns.m | 11 ++++++-----
src/nsterm.m | 8 +++++---
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/src/nsfns.m b/src/nsfns.m
index 3e19cce89de9..67d8449c70dd 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -321,11 +321,6 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
{
[[view window] setBackgroundColor: [col colorWithAlphaComponent: alpha]];
- if (alpha != (EmacsCGFloat) 1.0)
- [[view window] setOpaque: NO];
- else
- [[view window] setOpaque: YES];
-
face = FRAME_DEFAULT_FACE (f);
if (face)
{
@@ -369,6 +364,12 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
f->alpha_background = alpha;
[[view window] setBackgroundColor: [f->output_data.ns->background_color
colorWithAlphaComponent: alpha]];
+
+ if (alpha != (EmacsCGFloat) 1.0)
+ [[view window] setOpaque: NO];
+ else
+ [[view window] setOpaque: YES];
+
recompute_basic_faces (f);
SET_FRAME_GARBAGED (f);
}
diff --git a/src/nsterm.m b/src/nsterm.m
index 9ab3ff8f783f..6feef6236449 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2648,9 +2648,11 @@ Hide the window (X11 semantics)
r = NSIntersectionRect (r, [view frame]);
ns_focus (f, &r, 1);
- [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (r);
+ [[view window] invalidateShadow];
ns_unfocus (f);
return;
@@ -2752,7 +2754,8 @@ Hide the window (X11 semantics)
return;
ns_focus (f, NULL, 1);
- [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (NSMakeRect (0, margin, width, border));
NSRectFill (NSMakeRect (0, 0, border, height));
NSRectFill (NSMakeRect (0, margin, width, border));
@@ -4106,7 +4109,6 @@ Function modeled after x_draw_glyph_string_box ().
else
[[[NSColor colorWithUnsignedLong: s->face->background]
colorWithAlphaComponent: s->f->alpha_background] set];
-
NSRectFill (NSMakeRect (x, s->y, background_width, s->height));
}
}