Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to change company-box child-frame background color when circadian switch theme #28

Open
stardiviner opened this issue May 9, 2018 · 2 comments

Comments

@stardiviner
Copy link
Contributor

I use package circadian to auto
switch theme. I want company-box child-frame background color can be changed in
circadian switch hook too.
Here is my try:

(setq-default company-box-frame-parameters company-box-frame-parameters) ; used  by (default-value 'company-box-frame-parameters).

(defun my:company-box-faces-setup (theme)
    "Reload company-box faces on `circadian' `THEME' toggling."
    (set-face-attribute 'company-box-candidate nil
                        :inherit nil
                        :family (face-attribute 'default :family)
                        :foreground (face-foreground 'default))
    (set-face-attribute 'company-box-selection nil
                        :inherit 'company-tooltip-selection)
    (set-face-attribute 'company-box-background nil
                        :background (cl-case (alist-get 'background-mode (frame-parameters))
                                      ('light "#EAF9FF")
                                      ('dark "#454545")))
    (setq company-box-frame-parameters (default-value 'company-box-frame-parameters))
    (add-to-list 'company-box-frame-parameters
                 `(background-color . ,(cl-case (alist-get 'background-mode (frame-parameters))
                                         ('light "#EAF9FF")
                                         ('dark "#454545"))) t)
    ;; (add-to-list 'company-box-frame-parameters
    ;;              `(foreground-color . ,(face-foreground 'default)) t)
    )
  (add-hook 'circadian-after-load-theme-hook #'my:company-box-faces-setup)

But this does not work.
When I run (circadian-setup) it is white background on 'light theme, or black
background color on 'dark theme.

Maybe my set background color way (use add-to-list) is wrong?

@stardiviner
Copy link
Contributor Author

I was always wandering why I change company-box-frame-parameter is not working.
After checking out source code, I found this is because:

(defun company-box--display (string)
  "Display the completions."
  (company-box--render-buffer string)
  (unless (company-box--get-frame) ; the already created child-frame exist, so will not apply following new child-frame parameters.
    (company-box--set-frame (company-box--make-frame)))
  (company-box--set-frame-position (company-box--get-frame))
  (unless (frame-visible-p (company-box--get-frame))
    (make-frame-visible (company-box--get-frame)))
  (company-box--update-scrollbar (company-box--get-frame) t))

So I hope company-box can add a function to reset child-frame like this:

;; delete old child-frame, then `company-box' create new child-frame.
    (delete-frame (company-box--get-frame))
    (unless (company-box--get-frame)
      (company-box--set-frame (company-box--make-frame)))
    (delete-frame (frame-parameter nil 'company-box-doc-frame))
    (unless (frame-live-p (frame-parameter nil 'company-box-doc-frame))
      (set-frame-parameter nil 'company-box-doc-frame nil))

Here is my current config (as reference for you to considering circadian theme switching case):

(setq-default company-box-frame-parameters company-box-frame-parameters)
  (defun my:company-box-faces-setup (theme)
    "Reload company-box faces on `circadian' `THEME' toggling."
    ;; delete old child-frame, then `company-box' create new child-frame.
    (delete-frame (company-box--get-frame))
    (unless (company-box--get-frame)
      (company-box--set-frame (company-box--make-frame)))
    (delete-frame (frame-parameter nil 'company-box-doc-frame))
    (unless (frame-live-p (frame-parameter nil 'company-box-doc-frame))
      (set-frame-parameter nil 'company-box-doc-frame nil))
    
    (set-face-attribute 'company-box-candidate nil
                        :inherit nil
                        :family (face-attribute 'default :family)
                        :foreground (face-foreground 'default))
    (set-face-attribute 'company-box-selection nil
                        :inherit 'company-tooltip-selection)
    (set-face-attribute 'company-box-background nil
                        :background (cl-case (alist-get 'background-mode (frame-parameters))
                                      ('light "#EBF4FE")
                                      ('dark (color-lighten-name (face-background 'default) 4))))
    (add-to-list 'company-box-frame-parameters
                 `(background-color . ,(cl-case (alist-get 'background-mode (frame-parameters))
                                         ('light "#EBF4FE")
                                         ('dark (color-lighten-name (face-background 'default) 4)))))
    (add-to-list 'company-box-frame-parameters
                 `(foreground-color . ,(face-foreground 'default)))
    )
  (add-hook 'circadian-after-load-theme-hook #'my:company-box-faces-setup)

@stardiviner
Copy link
Contributor Author

Hi, @sebastiencs any idea on this? can you add some similar workaround for this case which the company-box child-frames is dead, or invalid problems?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant