<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ryohei Ikegami</title>
    <description>The latest articles on Forem by Ryohei Ikegami (@seanchas_t).</description>
    <link>https://forem.com/seanchas_t</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F45342%2Fbbb428d7-2c14-4eb4-ba5e-c4accd6fee9e.png</url>
      <title>Forem: Ryohei Ikegami</title>
      <link>https://forem.com/seanchas_t</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/seanchas_t"/>
    <language>en</language>
    <item>
      <title>transparent-titlebar: transparent title bar with native title label in Electron for Mac</title>
      <dc:creator>Ryohei Ikegami</dc:creator>
      <pubDate>Tue, 02 Jan 2018 08:38:56 +0000</pubDate>
      <link>https://forem.com/seanchas_t/transparent-titlebar-transparent-title-bar-with-native-title-label-in-electron-for-mac-1ej0</link>
      <guid>https://forem.com/seanchas_t/transparent-titlebar-transparent-title-bar-with-native-title-label-in-electron-for-mac-1ej0</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fi6j7s8zedltdvfnmhnht.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fi6j7s8zedltdvfnmhnht.gif" title="Example" alt="Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/seanchas116/transparent-titlebar" rel="noopener noreferrer"&gt;https://github.com/seanchas116/transparent-titlebar&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Customizing title bar of Electron apps in Mac
&lt;/h2&gt;

&lt;p&gt;Many cool Mac apps customizes title bar and often hides original title bar background. Electron provides &lt;a href="https://electronjs.org/docs/api/frameless-window#hidden" rel="noopener noreferrer"&gt;titleBarStyle option&lt;/a&gt; to hide original titlebar, but it also hides the title label.&lt;br&gt;
If you want to make the title bar transparent while leaving the native title label visible, you'll need another way.&lt;/p&gt;
&lt;h3&gt;
  
  
  why needs native title label?
&lt;/h3&gt;

&lt;p&gt;The best benefit of the native title level is &lt;a href="https://electronjs.org/docs/tutorial/desktop-environment-integration#represented-file-of-window-macos" rel="noopener noreferrer"&gt;Represented File&lt;/a&gt;.&lt;br&gt;
It's difficult to reimplement this in DOM perfectly.&lt;/p&gt;
&lt;h2&gt;
  
  
  transparent-titlebar
&lt;/h2&gt;

&lt;p&gt;I developed &lt;a href="https://www.npmjs.com/package/transparent-titlebar" rel="noopener noreferrer"&gt;transparent-titlebar&lt;/a&gt; library, which uses Cocoa APIs to set title bars transparent while leaving title labels visible.&lt;br&gt;
It customizes &lt;code&gt;NSWindow&lt;/code&gt;'s &lt;code&gt;titlebarAppearsTransparent&lt;/code&gt; and &lt;code&gt;styleMask&lt;/code&gt; to show content with entire space of window.&lt;/p&gt;

&lt;p&gt;This is how to use this library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;win&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;BrowserWindow&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;transparentTitlebar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;transparent-titlebar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Setup window to use transparent titlebar&lt;/span&gt;
&lt;span class="nx"&gt;transparentTitlebar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;win&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getNativeWindowHandle&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;// Set title color to red (must be called whenever the title has changed)&lt;/span&gt;
&lt;span class="nx"&gt;transparentTitlebar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;win&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getNativeWindowHandle&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may need to run &lt;a href="https://github.com/electron/electron-rebuild" rel="noopener noreferrer"&gt;electron-rebuild&lt;/a&gt; after install.&lt;/p&gt;

&lt;h2&gt;
  
  
  change color (in hacky way)
&lt;/h2&gt;

&lt;p&gt;It's hard to change the text color of the title because Cocoa does not provide any API to change it directly.&lt;br&gt;
Fortunately I found a way to find NSTextField from title bar subviews and change its color: &lt;a href="http://stackoverflow.com/a/29336473" rel="noopener noreferrer"&gt;http://stackoverflow.com/a/29336473&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setTitleBarColor&lt;/code&gt; function uses this solution. It must be called whenever after the title has changed.&lt;br&gt;
It is a hack and probably you have to use it with caution.&lt;br&gt;
(this is because I published this in a separate package instead of a pull request to Electron)&lt;/p&gt;

</description>
      <category>electron</category>
      <category>macos</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
